Initial re-upload of spice2x-24-08-24
This commit is contained in:
15
api/resources/lua/README.md
Normal file
15
api/resources/lua/README.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# Lua Scripting
|
||||
Supported version: Lua 5.4.3
|
||||
No proper documentation yet. Check the example scripts if you need this!
|
||||
For undocumented functions you can find the definitions in the source code (script/api/*.cpp).
|
||||
They are very similar to what the network API provides.
|
||||
|
||||
# Automatic Execution
|
||||
Create a "script" folder next to spice and put your scripts in there (subfolders allowed).
|
||||
The prefix specifies when the script will be called:
|
||||
|
||||
- `boot_*`: executed on game boot
|
||||
- `shutdown_*`: executed on game end
|
||||
- `config_*`: executed when you start spicecfg (mostly for debugging/tests)
|
||||
|
||||
Example: "script/boot_patch.py" would be called on game boot.
|
||||
113
api/resources/lua/boot_iidx_tt_lights.lua
Normal file
113
api/resources/lua/boot_iidx_tt_lights.lua
Normal file
@@ -0,0 +1,113 @@
|
||||
-- example script for light effects on IIDX TT stab movement
|
||||
-- create a folder called "script" next to spice and put me in there
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
-- settings
|
||||
tt_duration = 0.25
|
||||
zero_duration = 0.3141592
|
||||
loop_delta = 1 / 240
|
||||
curve_pow = 1 / 4
|
||||
col_r = 1.0
|
||||
col_g = 0.0
|
||||
col_b = 0.0
|
||||
light_p1_r = "Side Panel Left Avg R"
|
||||
light_p1_g = "Side Panel Left Avg G"
|
||||
light_p1_b = "Side Panel Left Avg B"
|
||||
light_p2_r = "Side Panel Right Avg R"
|
||||
light_p2_g = "Side Panel Right Avg G"
|
||||
light_p2_b = "Side Panel Right Avg B"
|
||||
|
||||
-- wait for game
|
||||
while not analogs.read()["Turntable P1"] do yield() end
|
||||
|
||||
-- initial state
|
||||
tt1_last = tonumber(analogs.read()["Turntable P1"].state)
|
||||
tt2_last = tonumber(analogs.read()["Turntable P2"].state)
|
||||
tt1_diff_last = 0
|
||||
tt2_diff_last = 0
|
||||
tt1_trigger = 0
|
||||
tt2_trigger = 0
|
||||
tt1_zero_elapsed = 0
|
||||
tt2_zero_elapsed = 0
|
||||
|
||||
-- main loop
|
||||
while true do
|
||||
|
||||
-- read state
|
||||
tt1 = tonumber(analogs.read()["Turntable P1"].state)
|
||||
tt2 = tonumber(analogs.read()["Turntable P2"].state)
|
||||
time_cur = time()
|
||||
|
||||
-- calculate difference
|
||||
tt1_diff = tt1 - tt1_last
|
||||
tt2_diff = tt2 - tt2_last
|
||||
|
||||
-- fix wrap around
|
||||
if math.abs(tt1_diff) > 0.5 then tt1_diff = 0 end
|
||||
if math.abs(tt2_diff) > 0.5 then tt2_diff = 0 end
|
||||
|
||||
-- trigger on movement start and direction changes
|
||||
if (tt1_diff_last == 0 and tt1_diff ~= 0)
|
||||
or (tt1_diff_last > 0 and tt1_diff < 0)
|
||||
or (tt1_diff_last < 0 and tt1_diff > 0) then
|
||||
tt1_trigger = time_cur
|
||||
end
|
||||
if (tt2_diff_last == 0 and tt2_diff ~= 0)
|
||||
or (tt2_diff_last > 0 and tt2_diff < 0)
|
||||
or (tt2_diff_last < 0 and tt2_diff > 0) then
|
||||
tt2_trigger = time_cur
|
||||
end
|
||||
|
||||
-- light effects when last trigger is still active
|
||||
if time_cur - tt1_trigger < tt_duration then
|
||||
brightness = 1 - ((time_cur - tt1_trigger) / tt_duration) ^ curve_pow
|
||||
lights.write({[light_p1_r]={state=brightness*col_r}})
|
||||
lights.write({[light_p1_g]={state=brightness*col_g}})
|
||||
lights.write({[light_p1_b]={state=brightness*col_b}})
|
||||
else
|
||||
lights.write_reset(light_p1_r)
|
||||
lights.write_reset(light_p1_g)
|
||||
lights.write_reset(light_p1_b)
|
||||
end
|
||||
if time_cur - tt2_trigger < tt_duration then
|
||||
brightness = 1 - ((time_cur - tt2_trigger) / tt_duration) ^ curve_pow
|
||||
lights.write({[light_p2_r]={state=brightness*col_r}})
|
||||
lights.write({[light_p2_g]={state=brightness*col_g}})
|
||||
lights.write({[light_p2_b]={state=brightness*col_b}})
|
||||
else
|
||||
lights.write_reset(light_p2_r)
|
||||
lights.write_reset(light_p2_g)
|
||||
lights.write_reset(light_p2_b)
|
||||
end
|
||||
|
||||
-- flush HID light output
|
||||
lights.update()
|
||||
|
||||
-- turntable movement detection
|
||||
-- doesn't set the diff back to zero unless enough time has passed
|
||||
if tt1_diff == 0 then
|
||||
tt1_zero_elapsed = tt1_zero_elapsed + loop_delta
|
||||
if tt1_zero_elapsed >= zero_duration then
|
||||
tt1_diff_last = tt1_diff
|
||||
end
|
||||
else
|
||||
tt1_zero_elapsed = 0
|
||||
tt1_diff_last = tt1_diff
|
||||
end
|
||||
if tt2_diff == 0 then
|
||||
tt2_zero_elapsed = tt2_zero_elapsed + loop_delta
|
||||
if tt2_zero_elapsed >= zero_duration then
|
||||
tt2_diff_last = tt2_diff
|
||||
end
|
||||
else
|
||||
tt2_zero_elapsed = 0
|
||||
tt2_diff_last = tt2_diff
|
||||
end
|
||||
|
||||
-- remember state
|
||||
tt1_last = tt1
|
||||
tt2_last = tt2
|
||||
|
||||
-- loop end
|
||||
sleep(loop_delta)
|
||||
end
|
||||
57
api/resources/lua/config_example.lua
Normal file
57
api/resources/lua/config_example.lua
Normal file
@@ -0,0 +1,57 @@
|
||||
-- script examples
|
||||
-- no proper documentation yet
|
||||
-- create a folder called "script" next to spice and put me in there
|
||||
-- then open the config and if needed select IIDX for the demo
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
-- sleep for 0.2 seconds
|
||||
sleep(0.2)
|
||||
|
||||
-- log functions
|
||||
log_misc("example misc")
|
||||
log_info("example info")
|
||||
log_warning("example warning")
|
||||
--log_fatal("this would terminate")
|
||||
|
||||
-- print time
|
||||
log_info(time())
|
||||
|
||||
-- show message box
|
||||
msgbox("You are running the example script! Select IIDX if not already done.")
|
||||
|
||||
-- wait until analog is available
|
||||
while not analogs.read()["Turntable P1"] do yield() end
|
||||
|
||||
-- write button state
|
||||
buttons.write({["P1 Start"]={state=1}})
|
||||
|
||||
-- write analog state
|
||||
analogs.write({["Turntable P1"]={state=0.33}})
|
||||
|
||||
-- write light state
|
||||
lights.write({["P2 Start"]={state=0.8}})
|
||||
|
||||
-- import other libraries in "script" folder
|
||||
--local example = require('script.example')
|
||||
|
||||
-- demo
|
||||
while true do
|
||||
|
||||
-- analog animation
|
||||
analogs.write({["Turntable P2"]={state=math.abs(math.sin(time()))}})
|
||||
|
||||
-- button blink
|
||||
if math.cos(time() * 10) > 0 then
|
||||
buttons.write({["P1 1"]={state=1}})
|
||||
else
|
||||
buttons.write({["P1 1"]={state=0}})
|
||||
end
|
||||
|
||||
-- flush HID light output
|
||||
lights.update()
|
||||
|
||||
-- check for keyboard press
|
||||
if GetAsyncKeyState(0x20) > 0 then
|
||||
msgbox("You pressed space!")
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user