Skip to content

Commit 335447e

Browse files
author
arch
committed
adjust linux install
1 parent 0820331 commit 335447e

File tree

4 files changed

+95
-557
lines changed

4 files changed

+95
-557
lines changed

contrib/Installer/assets/main.lua

Lines changed: 64 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
json = require "json"
1+
json = require "json.lua"
2+
-- MTFG LUA Wrappper Version 2.0.0
23

34
-- global var
45
processHandleMTFG = nil
@@ -39,7 +40,7 @@ end
3940

4041
platform = get_platform()
4142

42-
function start_funscript_generator()
43+
function binding.start_funscript_generator()
4344
if processHandleMTFG then
4445
print('MTFG already running')
4546
return
@@ -56,12 +57,12 @@ function start_funscript_generator()
5657
print("currentScriptIdx: ", scriptIdx)
5758
print("currentTimeMs: ", currentTimeMs)
5859

59-
local next_action = ofs.ClosestActionAfter(script, currentTimeMs / 1000)
60-
if next_action and script.actions[next_action].at < (currentTimeMs + 500) then
61-
next_action = ofs.ClosestActionAfter(script, script.actions[next_action].at / 1000)
60+
local next_action, _ = script:closestActionAfter(currentTimeMs / 1000.0)
61+
if next_action and (next_action.at*1000) < (currentTimeMs + 500) then
62+
next_action, _ = script:closestActionAfter(next_action.at)
6263
end
6364

64-
print("nextAction: ", next_action and tostring(script.actions[next_action].at) or "nil")
65+
print("nextAction: ", next_action and tostring(next_action.at) or "nil")
6566

6667
local cmd = ""
6768
local args = {}
@@ -97,47 +98,18 @@ function start_funscript_generator()
9798

9899
if next_action then
99100
table.insert(args, "-e")
100-
table.insert(args, tostring(script.actions[next_action].at))
101+
table.insert(args, tostring(next_action.at*1000.0))
101102
end
102103

103104
print("cmd: ", cmd)
104105
print("args: ", table.unpack(args))
105106

106-
processHandleMTFG = ofs.CreateProcess(cmd, table.unpack(args))
107+
processHandleMTFG = Process.new(cmd, table.unpack(args))
107108

108109
status = "MTFG running"
109110
end
110111

111112

112-
function import_funscript_generator_csv_result()
113-
status = "MTFG not running"
114-
local tmpFile = ofs.ExtensionDir() .. "/" .. tmpFileName
115-
local f = io.open(tmpFile)
116-
if not f then
117-
print('Funscript Generator csv output file not found')
118-
return
119-
end
120-
121-
script = ofs.Script(scriptIdx)
122-
local k = 1
123-
for line in f:lines() do
124-
-- first line is header
125-
if k > 1 then
126-
for at, pos in string.gmatch(line, "(%w+);(%w+)") do
127-
ofs.AddAction(script, at, pos, true)
128-
end
129-
end
130-
k = k + 1
131-
end
132-
f:close()
133-
134-
-- save changes
135-
ofs.Commit(script)
136-
137-
-- delete csv file
138-
os.remove(tmpFile)
139-
end
140-
141113
function import_funscript_generator_json_result()
142114
status = "MTFG not running"
143115
local tmpFile = ofs.ExtensionDir() .. "/" .. tmpFileName
@@ -154,16 +126,23 @@ function import_funscript_generator_json_result()
154126

155127
if multiaxis then
156128
local i = 1
157-
while ofs.Script(i) do
158-
name = ofs.ScriptTitle(i)
129+
while i <= ofs.ScriptCount() do
130+
name = ofs.ScriptName(i)
159131
for k,v in pairs(scriptAssignment) do
160132
if name and name == scriptNames[v.idx] then
161133
if actions[k] then
162134
script = ofs.Script(i)
163135
for _, action in pairs(actions[k]) do
164-
ofs.AddAction(script, action["at"], action["pos"], true)
136+
local closest_action, _ = script:closestAction(action["at"])
137+
local filtered = false
138+
if closest_action and math.abs(closest_action.at - (action["at"]/1000.0)) < 0.01 then
139+
filtered = true
140+
else
141+
local a = Action.new(action["at"]/1000.0, action["pos"], true)
142+
table.insert(script.actions, a)
143+
end
165144
end
166-
ofs.Commit(script)
145+
script:commit()
167146
end
168147
end
169148
end
@@ -173,14 +152,20 @@ function import_funscript_generator_json_result()
173152
script = ofs.Script(scriptIdx)
174153

175154
for metric, actions_metric in pairs(actions) do
176-
print('add ', metric, ' to ', ofs.ScriptTitle(scriptIdx))
155+
print('add ', metric, ' to ', ofs.ScriptName(scriptIdx))
177156
for _, action in pairs(actions_metric) do
178-
ofs.AddAction(script, action["at"], action["pos"], true)
157+
local closest_action, _ = script:closestAction(action["at"]/1000.0)
158+
local filtered = false
159+
if closest_action and math.abs(closest_action.at - (action["at"]/1000.0)) < 0.01 then
160+
filtered = true
161+
else
162+
local a = Action.new(action["at"]/1000.0, action["pos"], true)
163+
table.insert(script.actions, a)
164+
end
179165
end
180166
end
181167

182-
-- save changes
183-
ofs.Commit(script)
168+
script:commit()
184169
end
185170

186171
-- delete json file
@@ -195,7 +180,7 @@ function invert_selected()
195180
action.pos = clamp(100 - action.pos, 0, 100)
196181
end
197182
end
198-
ofs.Commit(script)
183+
script:commit()
199184
end
200185

201186

@@ -219,16 +204,16 @@ function align_bottom_points(align_value)
219204
if action.selected then
220205
local bottom_point = true
221206

222-
local next_action = ofs.ClosestActionAfter(script, action.at / 1000)
207+
local next_action, _ = script:closestActionAfter(action.at / 1000)
223208
if next_action then
224-
if script.actions[next_action].pos <= action.pos then
209+
if next_action.pos <= action.pos then
225210
bottom_point = false
226211
end
227212
end
228213

229-
local prev_action = ofs.ClosestActionBefore(script, action.at / 1000)
214+
local prev_action, _ = script:closestActionBefore(action.at / 1000)
230215
if prev_action then
231-
if script.actions[prev_action].pos <= action.pos then
216+
if prev_action.pos <= action.pos then
232217
bottom_point = false
233218
end
234219
end
@@ -239,7 +224,7 @@ function align_bottom_points(align_value)
239224
end
240225
end
241226

242-
ofs.Commit(script)
227+
script:commit()
243228
end
244229

245230

@@ -263,16 +248,16 @@ function align_top_points(align_value)
263248
if action.selected then
264249
local top_point = true
265250

266-
local next_action = ofs.ClosestActionAfter(script, action.at / 1000)
251+
local next_action, _ = script:closestActionAfter(action.at / 1000)
267252
if next_action then
268-
if script.actions[next_action].pos >= action.pos then
253+
if next_action.pos >= action.pos then
269254
top_point = false
270255
end
271256
end
272257

273-
local prev_action = ofs.ClosestActionBefore(script, action.at / 1000)
258+
local prev_action, _ = script:closestActionBefore(action.at / 1000)
274259
if prev_action then
275-
if script.actions[prev_action].pos >= action.pos then
260+
if prev_action.pos >= action.pos then
276261
top_point = false
277262
end
278263
end
@@ -283,13 +268,12 @@ function align_top_points(align_value)
283268
end
284269
end
285270

286-
ofs.Commit(script)
271+
script:commit()
287272
end
288273

289274

290275
function init()
291276
print("Detected OS: ", platform)
292-
ofs.Bind("start_funscript_generator", "execute the funcript generator")
293277
local version_file_path = ""
294278
if platform == "Windows" then
295279
version_file_path = ofs.ExtensionDir().."\\funscript-editor\\funscript_editor\\VERSION.txt"
@@ -338,8 +322,9 @@ function update_script_names()
338322
scriptNamesCount = 0
339323
scriptNames = {'ignore'}
340324
scriptNamesCount = scriptNamesCount + 1
341-
while ofs.Script(i) do
342-
name = ofs.ScriptTitle(i)
325+
local i = 1
326+
while i <= ofs.ScriptCount() do
327+
name = ofs.ScriptName(i)
343328
if not is_empty(name) then
344329
table.insert(scriptNames, name)
345330
scriptNamesCount = scriptNamesCount + 1
@@ -362,7 +347,7 @@ end
362347

363348
function update(delta)
364349
updateCounter = updateCounter + 1
365-
if processHandleMTFG and not ofs.IsProcessAlive(processHandleMTFG) then
350+
if processHandleMTFG and not processHandleMTFG:alive() then
366351
print('funscript generator completed import result')
367352
processHandleMTFG = nil
368353
import_funscript_generator_json_result()
@@ -384,7 +369,7 @@ function gui()
384369
if not processHandleMTFG then
385370

386371
if ofs.Button("Start MTFG") then
387-
start_funscript_generator()
372+
binding.start_funscript_generator()
388373
end
389374
else
390375
if ofs.Button("Kill MTFG") then
@@ -399,7 +384,7 @@ function gui()
399384
ofs.SameLine()
400385
if ofs.Button("Open Config") then
401386
if platform == "Windows" then
402-
processHandleConfigDir = ofs.CreateProcess("explorer.exe", ofs.ExtensionDir().."\\funscript-editor\\funscript_editor\\config")
387+
processHandleConfigDir = Process.new("explorer.exe", ofs.ExtensionDir().."\\funscript-editor\\funscript_editor\\config")
403388
else
404389
local cmd = '/usr/bin/dbus-send --session --print-reply --dest=org.freedesktop.FileManager1 --type=method_call /org/freedesktop/FileManager1 org.freedesktop.FileManager1.ShowItems array:string:"file://'
405390
..ofs.ExtensionDir()..'/Python-Funscript-Editor/funscript_editor/config/" string:""'
@@ -412,12 +397,12 @@ function gui()
412397
if platform == "Windows" then
413398
ofs.SameLine()
414399
if ofs.Button("Open Log") then
415-
processHandleLogFile = ofs.CreateProcess("notepad.exe", "C:/Temp/funscript_editor.log")
400+
processHandleLogFile = Process.new("notepad.exe", "C:/Temp/funscript_editor.log")
416401
end
417402
else
418403
ofs.SameLine()
419404
if ofs.Button("Open Log") then
420-
processHandleLogFile = ofs.CreateProcess("/usr/bin/xdg-open", "/tmp/funscript_editor.log")
405+
processHandleLogFile = Process.new("/usr/bin/xdg-open", "/tmp/funscript_editor.log")
421406
end
422407
end
423408
end
@@ -450,20 +435,23 @@ function gui()
450435

451436
ofs.Separator()
452437

453-
ofs.Text("Post-Processing:")
454-
ofs.SameLine()
455-
if ofs.Button("Invert") then
456-
invert_selected()
457-
end
438+
local enable_post_processing = false -- broken
439+
if enable_post_processing then
440+
ofs.Text("Post-Processing:")
441+
ofs.SameLine()
442+
if ofs.Button("Invert") then
443+
invert_selected()
444+
end
458445

459-
ofs.SameLine()
460-
if ofs.Button("Align Bottom Points") then
461-
align_bottom_points(-1)
462-
end
446+
ofs.SameLine()
447+
if ofs.Button("Align Bottom Points") then
448+
align_bottom_points(-1)
449+
end
463450

464-
ofs.SameLine()
465-
if ofs.Button("Align Top Points") then
466-
align_top_points(-1)
451+
ofs.SameLine()
452+
if ofs.Button("Align Top Points") then
453+
align_top_points(-1)
454+
end
467455
end
468456

469457
end

0 commit comments

Comments
 (0)