4545platform = get_platform ()
4646
4747function binding .start_funscript_generator ()
48+ exec_mtfg (false )
49+ end
50+
51+ function exec_mtfg (no_tracking )
4852 if processHandleMTFG then
4953 print (' MTFG already running' )
5054 return
@@ -112,6 +116,10 @@ function binding.start_funscript_generator()
112116 table.insert (args , tostring (math.floor (next_action .at * 1000.0 )))
113117 end
114118
119+ if no_tracking then
120+ table.insert (args , " --no-tracking" )
121+ end
122+
115123 print (" cmd: " , cmd )
116124 print (" args: " , table.unpack (args ))
117125
@@ -121,6 +129,26 @@ function binding.start_funscript_generator()
121129end
122130
123131
132+ function delete_range (script , start_of_range , end_of_range )
133+ local fps = player .FPS ()
134+ local frame_time = 1.0 / fps
135+ for idx , action in ipairs (script .actions ) do
136+ if action .at >= (start_of_range - frame_time ) and action .at <= (end_of_range + frame_time ) then
137+ script :markForRemoval (idx )
138+ end
139+ end
140+ print (" delete range" , start_of_range , end_of_range )
141+ script :removeMarked ()
142+ end
143+
144+
145+ function tableLength (T )
146+ local count = 0
147+ for _ in pairs (T ) do count = count + 1 end
148+ return count
149+ end
150+
151+
124152function import_funscript_generator_json_result ()
125153 status = " MTFG not running"
126154 local tmpFile = ofs .ExtensionDir () .. " /" .. tmpFileName
@@ -147,6 +175,7 @@ function import_funscript_generator_json_result()
147175 if name and name == scriptNames [v .idx ] then
148176 if actions [k ] then
149177 script = ofs .Script (i )
178+ delete_range (script , actions [k ][1 ][" at" ] / 1000.0 , actions [k ][# (actions [k ])][" at" ] / 1000.0 )
150179 for _ , action in pairs (actions [k ]) do
151180 local closest_action , _ = script :closestAction (action [" at" ])
152181 local new_action = Action .new (action [" at" ]/ 1000.0 , action [" pos" ], true )
@@ -164,9 +193,10 @@ function import_funscript_generator_json_result()
164193 end
165194 else
166195 script = ofs .Script (scriptIdx )
167-
168196 for metric , actions_metric in pairs (actions ) do
169197 print (' add ' , metric , ' to ' , ofs .ScriptName (scriptIdx ))
198+ print (type (actions_metric ))
199+ delete_range (script , actions_metric [1 ][" at" ] / 1000.0 , actions_metric [# actions_metric ][" at" ] / 1000.0 )
170200 for _ , action in pairs (actions_metric ) do
171201 local closest_action , _ = script :closestAction (action [" at" ]/ 1000.0 )
172202 local new_action = Action .new (action [" at" ]/ 1000.0 , action [" pos" ], true )
@@ -388,9 +418,12 @@ function gui()
388418
389419 ofs .SameLine ()
390420 if not processHandleMTFG then
391-
392421 if ofs .Button (" Start MTFG" ) then
393- binding .start_funscript_generator ()
422+ exec_mtfg (false )
423+ end
424+ ofs .SameLine ()
425+ if ofs .Button (" Reprocess Data" ) then
426+ exec_mtfg (true )
394427 end
395428 else
396429 if ofs .Button (" Kill MTFG" ) then
0 commit comments