Skip to content

Commit fb1a512

Browse files
author
arch
committed
add multiaxis assignment to lua next
1 parent e07e082 commit fb1a512

File tree

1 file changed

+86
-20
lines changed

1 file changed

+86
-20
lines changed

contrib/Installer/assets/main.lua.next

Lines changed: 86 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ updateCounter = 0
99
scriptIdx = 0
1010
mtfgVersion = "0.0.0"
1111
status = "MTFG not running"
12+
multiaxis = false
13+
tmpFileName = "funscript_actions.json"
14+
scriptNames = {}
15+
scriptAssignment = {x={idx=1}, y={idx=1}, roll={idx=1}}
1216

1317
function exists(file)
1418
return os.rename(file, file)
@@ -39,7 +43,7 @@ function start_funscript_generator()
3943
end
4044

4145
scriptIdx = ofs.ActiveIdx()
42-
local tmpFile = ofs.ExtensionDir() .. "/funscript_actions.json"
46+
local tmpFile = ofs.ExtensionDir() .. "/" .. tmpFileName
4347
local video = player.CurrentVideo()
4448
local script = ofs.Script(scriptIdx)
4549
local currentTimeMs = player.CurrentTime() * 1000
@@ -72,6 +76,11 @@ function start_funscript_generator()
7276
end
7377

7478
table.insert(args, "--generator")
79+
80+
if multiaxis then;
81+
table.insert(args, "--multiaxis")
82+
end
83+
7584
table.insert(args, "-s")
7685
table.insert(args, tostring(currentTimeMs))
7786
table.insert(args, "-i")
@@ -95,7 +104,7 @@ end
95104

96105
function import_funscript_generator_csv_result()
97106
status = "MTFG not running"
98-
local tmpFile = ofs.ExtensionDir() .. "/funscript_actions.csv"
107+
local tmpFile = ofs.ExtensionDir() .. "/" .. tmpFileName
99108
local f = io.open(tmpFile)
100109
if not f then
101110
print('Funscript Generator csv output file not found')
@@ -124,7 +133,7 @@ end
124133

125134
function import_funscript_generator_json_result()
126135
status = "MTFG not running"
127-
local tmpFile = ofs.ExtensionDir() .. "/funscript_actions.json"
136+
local tmpFile = ofs.ExtensionDir() .. "/" .. tmpFileName
128137
local f = io.open(tmpFile)
129138
if not f then
130139
print('Funscript Generator json output file not found')
@@ -136,17 +145,36 @@ function import_funscript_generator_json_result()
136145
json_body = json.decode(content)
137146
actions = json_body["actions"]
138147

139-
script = ofs.Script(scriptIdx)
148+
if multiaxis then
149+
local i = 1
150+
while ofs.Script(i) do
151+
name = ofs.ScriptTitle(i)
152+
for k,v in pairs(scriptAssignment) do
153+
if name and name == scriptNames[v.idx] then
154+
if actions[k] then
155+
script = ofs.Script(i)
156+
for _, action in pairs(actions[k]) do
157+
ofs.AddAction(script, action["at"], action["pos"], true)
158+
end
159+
ofs.Commit(script)
160+
end
161+
end
162+
end
163+
i = i + 1
164+
end
165+
else
166+
script = ofs.Script(scriptIdx)
140167

141-
for metric, actions_metric in pairs(actions) do
142-
print('metric', metric)
143-
for _, action in pairs(actions_metric) do
144-
ofs.AddAction(script, action["at"], action["pos"], true)
168+
for metric, actions_metric in pairs(actions) do
169+
print('add ', metric, ' to ', ofs.ScriptTitle(scriptIdx))
170+
for _, action in pairs(actions_metric) do
171+
ofs.AddAction(script, action["at"], action["pos"], true)
172+
end
145173
end
146-
end
147174

148-
-- save changes
149-
ofs.Commit(script)
175+
-- save changes
176+
ofs.Commit(script)
177+
end
150178

151179
-- delete json file
152180
os.remove(tmpFile)
@@ -276,15 +304,7 @@ function init()
276304
end
277305
end
278306

279-
280-
function update(delta)
281-
updateCounter = updateCounter + 1
282-
if processHandleMTFG and not ofs.IsProcessAlive(processHandleMTFG) then
283-
print('funscript generator completed import result')
284-
processHandleMTFG = nil
285-
import_funscript_generator_json_result()
286-
end
287-
if math.fmod(updateCounter, 1000) == 1 then
307+
function update_logfile_exists()
288308
local logfile = ""
289309
if platform == "Windows" then
290310
logfile = "C:/Temp/funscript_editor.log"
@@ -298,6 +318,37 @@ function update(delta)
298318
else
299319
logfileExist = false
300320
end
321+
end
322+
323+
324+
function is_empty(s)
325+
return s == nil or s == ''
326+
end
327+
328+
329+
function update_script_names()
330+
local i = 1
331+
scriptNames = {'ignore'}
332+
while ofs.Script(i) do
333+
name = ofs.ScriptTitle(i)
334+
if not is_empty(name) then
335+
table.insert(scriptNames, name)
336+
end
337+
i = i + 1
338+
end
339+
end
340+
341+
342+
function update(delta)
343+
updateCounter = updateCounter + 1
344+
if processHandleMTFG and not ofs.IsProcessAlive(processHandleMTFG) then
345+
print('funscript generator completed import result')
346+
processHandleMTFG = nil
347+
import_funscript_generator_json_result()
348+
end
349+
if math.fmod(updateCounter, 100) == 1 then
350+
update_logfile_exists()
351+
update_script_names()
301352
end
302353
end
303354

@@ -350,6 +401,21 @@ function gui()
350401
end
351402

352403
ofs.Separator()
404+
405+
multiaxis, valueChanged = ofs.Checkbox("multiaxis", multiaxis)
406+
407+
if multiaxis then
408+
local comboNum = 1
409+
for k,v in pairs(scriptAssignment) do
410+
ofs.Text(k.." => ")
411+
ofs.SameLine()
412+
v.idx, _ = ofs.Combo("#"..tostring(comboNum), v.idx, scriptNames)
413+
comboNum = comboNum + 1
414+
end
415+
end
416+
417+
ofs.Separator()
418+
353419
ofs.Text("Post-Processing:")
354420
ofs.SameLine()
355421
if ofs.Button("Invert") then

0 commit comments

Comments
 (0)