-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemoeditor.cfg
436 lines (419 loc) · 15.8 KB
/
demoeditor.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
// V: 25/07/2021
_de_readabletime = (strreplace (timeremaining 1) ":" " ")
_de_actions_buff = ""
_de_savedmillis = 0
_de_savedtextshow = ""
_de_popupvisible = 0
_de_curmillis = 0
if (! (getalias _de_actions_time)) [
_de_actions = ""
_de_actions_time = []
_de_actions_timereadable = []
_de_actions_command = []
_de_timeremainingbuff = -1
_de_runningaction = 0
_de_input_minutes = 5
_de_input_seconds = 0
if (! (getalias _de_input_demoname)) [
_de_input_demoname = ""
_de_validdemoname = 0
_de_actions_hascfgfile = 0
]
]
_de_actions_run = [
local timeindex
if (!= $timeremaining $_de_timeremainingbuff) [
timeindex = (indexof $_de_actions_time $timeremaining)
if (&& (!= $timeindex -1) $_de_runningaction) [
do (_de_command_unescape (at $_de_actions_command $timeindex))
]
_de_timeremainingbuff = $timeremaining
]
sleep 0 [_de_actions_run]
]
// replaces new lines (*~n), tabs (*~t), brackets (*~bl *~br) and quotation marks (*~q) to preserve them in lists
_de_command_escape = [
local r; r = [strreplace $arg1 $arg2 $arg3]
r (r (r (r (r $arg1 "^n" "*~n") "^t" "*~t") "[" "*~bl") "]" "*~br") "^"" "*~q"
]
_de_command_unescape = [
local r; r = [strreplace $arg1 $arg2 $arg3]
r (r (r (r (r $arg1 "*~n" "^n") "*~t" "^t") "*~bl" "[") "*~br" "]") "*~q" "^""
]
_de_loopchar = [loop $arg1 (strlen $arg2) [$arg1 = (substr $arg2 $$arg1 1); arg3]]
_de_strstr+ = [arg1 = (strstr (substr $arg1 $arg3) $arg2); if (>= $arg1 0) [+ $arg1 $arg3] [result -1]]
_de_strstrlist = [local i l idc; i = 0 ; l = (strlen $arg2); while [> $i -1] [i = (_de_strstr+ $arg1 $arg2 $i); if (>= $i 0) [append idc $i; i = (+ $i $l)]]; result $idc]
_de_stroccount = [local _stroc _strocpos; _stroc = 0; loop i (strlen $arg1) [if (=s (substr $arg1 $i 1) $arg2)[_stroc = (+ $_stroc 1); append _strocpos $i]]; if (arg3) [result $_strocpos] [result $_stroc]]
_de_strshortify = [if (>= (strlen $arg1) $arg2) [arg1 = (concatword (substr $arg1 0 $arg3) "..." (substr $arg1 (- (strlen $arg1) $arg3) $arg3))]; result $arg1]
_de_clearstr = [local number; _de_loopchar char $arg1 [if (!= (strstr [0123456789] $char) -1) [number = (concatword $number $char)]]; result (? (=s $number "") 0 $number)]
_de_listreplace = [listsplice $arg1 $arg3 $arg2 1]
_de_listdiff = [listfilter _l $arg2 [$arg3 (indexof $arg1 $_l) -1]]
_de_echo = [_de_popupvisible = 0; _de_message = $arg1; _de_savedmillis = (+ (getmillis) 8000); _de_curmillis = (getmillis)]
_de_icon = [guiimage (format "%2packages/icons/%1" $arg1 (? (!=s $arg4 "") (concatword "<mad:" $arg4 ">") "")) $arg2 $arg3 0]
_de_editguieditor = [textfocus $arg2; textselectall; textcopy; textclear; textfocus $arg1; textclear; textpaste]
_de_sleep_current = 0
_de_sleep_target = 0
_de_sleep_action = ""
_de_sleep_run = [
_de_sleep_action = $arg1
_de_sleep_target = 1
_de_sleep_current = 0
]
_de_action_jumpto = [
local timeindex readabletime
timeindex = (indexof $_de_actions_time $arg1)
readabletime = (at $_de_actions_timereadable $timeindex)
_de_input_minutes = (at $readabletime 0)
_de_input_seconds = (at $readabletime 1)
_de_actions_buff = (_de_command_unescape (at $_de_actions_command $timeindex))
_de_sleep_run [_de_editguieditor "_de_actions" "_de_actions_buff"]
]
_de_confirm = [
_de_popupvisible = 1
_de_message = $arg1
_de_confirmaction = $arg2
_de_confirmgui = $arg3
]
_de_refreshdemovalidity = [
local root ext demopath actionscfg
ext = (? (= (strstr $_de_input_demoname ".dmo") -1) ".dmo" "")
root = (? (= (strstr $_de_input_demoname "/") -1) (concatword $demodir "/") "")
demopath = (concatword $root $_de_input_demoname $ext)
_de_validdemoname = (? (findfile $demopath) $demopath 0)
actionscfg = (concatword (strreplace $_de_input_demoname ".dmo" "") ".cfg")
_de_actions_hascfgfile = (? (findfile (concatword $root $actionscfg)) (concatword $root $actionscfg) (? (findfile $actionscfg) $actionscfg 0))
]
_de_loadcfgfile = [exec $_de_actions_hascfgfile; _de_action_jumpto (at $_de_actions_time 0)]
demoeditor = [showgui pseudodemoeditor]
demo = [
stopdemo
if $paused [pausegame 0]
if (mode -1) [if (> $numargs 0) [map $arg1] [map]]
_de_input_demoname = $arg1
_de_input_demonamebuff = $arg1
_de_refreshdemovalidity
_de_lastvaliddemo = $arg1
if $_de_actions_hascfgfile [_de_loadcfgfile]
if (|| (=s $arg2 "edit") (= $arg2 1)) [demoeditor; sleep 0 [pausegame 1]]
]
newgui pseudodemoeditor [
local inputtime timelinestrut timedirection actiontime
inputtime = (+ (* 60 $_de_input_minutes) $_de_input_seconds)
timelinestrut = [*f 0.22 (*f (divf (-f 600 (? (=s $arg1 "") $timeremaining $arg1)) 60) 6)]
timedirection = (> $inputtime (timeremaining 0))
actiontime = (indexof $_de_actions_time $inputtime)
guinoautotab [
//nodebug [
//guitab (concatword (? $paused "^f4" "^f0") (timeremaining 1))
guialign 0 [guiimage "packages/skyboxes/white_bk.jpg" [] 8.2]
guistrut -16.2
guialign 0 [guiimage "packages/skyboxes/black_bk.jpg" [] 8]
guistrut -14
guititle "^f8Demo Playback"
guistayopen [
guialign 0 [
guibutton "^f5edit project name" [
_de_confirm "Rename project?" [
_de_input_demoname = $_de_input_demonamebuff
_de_refreshdemovalidity
] [
guifield _de_input_demonamebuff -25 [if (=s $_de_input_demonamebuff "") [_de_input_demonamebuff = $_de_lastvaliddemo]]
guistrut -1
]
] 0
]
]
//guialign 0 [guitext "^f5demo name" 0]
//guialign 0 [guifield _de_input_demoname -20 [_de_refreshdemovalidity]]
//guialign 0 [guistrut -22; guilist [guistrut -0.9; guitext "^f5*" 0]]
guistayopen [
guistrut 0.2
guilist [
guistrut (+f 8 (timelinestrut))
guititle (concatword (? (= (indexof $_de_actions_time $timeremaining) -1) "^f6" (? $_de_runningaction "^f8" "^f3")) (timeremaining 1))
]
guistrut 0.2
guialign 0 [
guistrut 14.2
guilist [
guilist [
loop n 60 [
local id
id = (- 60 $n) // the horizontal line is drawn from right to left
if (= $n (div $inputtime 10)) [
guistrut -0.8
guilist [
guistrut -0.3
_de_icon "de_timeline_item.png" [] 0.2
]
]
looplist savedactiontime $_de_actions_time [
if (= $n (div $savedactiontime 10)) [
guistrut -0.8
guilist [
guistrut -0.3
_de_icon "de_timeline_item.png" [
_de_action_jumpto @savedactiontime
] 0.2 (? (= $timeremaining $savedactiontime) (? $_de_runningaction "0.2/1/1" "1/0.2/0.2") (? (!= $inputtime $savedactiontime) "0.4/0.4/0.4" "0/1/0"))
]
]
]
guistrut -1
_de_icon "de_timeline.png" [
local selectedtime
selectedtime = (divf (* @n 10) 60)
_de_input_minutes = (substr $selectedtime 0 1)
_de_input_seconds = (concatword "0" (substr $selectedtime 2 1))
] 0.2 (? (> (* $n 10) $timeremaining) "0/1/1" "0.2/0.2/0.2") // fill visited line
]
]
]
]
guistrut -0.97
guialign -1 [
// time line
guistrut (+f 9.5 (timelinestrut))
guititle "^f6."
]
guistrut -0.75
guialign 0 [
guistrut 0.1
_de_icon "de_plus.png" [
_de_input_minutes = (? (!= $_de_input_minutes 9) (+ $_de_input_minutes 1) 0)
] 0.5
guistrut 13.1
_de_icon "de_minus.png" [
_de_input_minutes = (? (!= $_de_input_minutes 0) (- $_de_input_minutes 1) 9)
] 0.5
]
guistrut -0.5
guialign 0 [
_de_icon "de_timeinput.png" [] 1.55 (? (= $timeremaining $inputtime) "0.55/0.15/0.1" "0.1/0.1/0.1")
]
guistrut -2.1
guialign 0 [
guifield _de_input_minutes 2 [
_de_input_minutes = (? (=s $_de_input_minutes "") (substr (timeremaining 1) 0 1) (max (min (_de_clearstr $_de_input_minutes) 9) 0))
]
guifield _de_input_seconds 2 [
_de_input_seconds = (? (=s $_de_input_seconds "") (substr (timeremaining 1) 2) (max (min (_de_clearstr $_de_input_seconds) 59) 0))
]
]
guialign 0 [
local skip
skip = [
if @timedirection [
if (!=s $_de_input_demoname "") [
if $_de_validdemoname [
demo $_de_input_demoname
] [
local demonamebuff
demonamebuff = $_de_input_demoname
_de_echo (concat "^f7Project^f8" $demonamebuff "^f7does not have a demo file with the same name.")
demo $_de_lastvaliddemo
_de_input_demonamebuff = $demonamebuff
_de_input_demoname = $demonamebuff
_de_refreshdemovalidity
]
] [
_de_echo "^f7You can't rewind without setting the ^f5project name^f~."
]
]
seekdemo (concatword "-" $_de_input_minutes ":" $_de_input_seconds)
pausegame 1
]
guistrut 0.1
// rewind button
if (!= $inputtime (timeremaining 0)) [
_de_icon "de_skip_left.png" [
if @timedirection [
@@skip
] [
_de_echo (concatword "You can't rewind to " $_de_input_minutes ":" $_de_input_seconds ", it's ahead of the current time (^f6" (timeremaining 1) "^f~).")
]
] 0.505 (? $timedirection "0.88/0.35/0.1" "0.2/0.2/0.2")
]
guistrut -0.4
// pause/play button
guibutton "" [pausegame (! $paused)] (? $paused "de_arrow_right.png" "de_pause.png")
guistrut -0.6
// fast-forward button
if (!= $inputtime (timeremaining 0)) [
_de_icon "de_skip_right.png" [
if (! @timedirection) [
@@skip
] [
_de_echo (concatword "You can't fast-forward to " $_de_input_minutes ":" $_de_input_seconds ", it's behind the current time (^f6" (timeremaining 1) "^f~).")
]
] 0.505 (? (! $timedirection) "0.88/0.35/0.1" "0.2/0.2/0.2")
]
]
//if (> (strlen $textcurrentline) 20) [textselectall; textcopy; textpaste]
guialign 0 [
guistrut -0.8
guieditor _de_actions -20 5
guistrut -1.5
guilist [
// info button
guibutton "^f4?" [_de_echo "Commands run automatically at the specified time."] 0
// action options button
if (!=s $_de_actions_time "") [
guilist [
guistrut -0.6
_de_icon "de_gear.png" [
_de_confirm (concat (? $_de_runningaction "^f3Stop" "^f1Start") "^f7auto execution of actions?") [
_de_runningaction = (! $_de_runningaction)
if (! $_de_runningaction) [clearsleep] [_de_actions_run]
] [
if (!= (listlen $_de_actions_time) 0) [
guialign 0 [
guitext "or " 0
guibutton "^f3clear all actions" [
_de_confirm (concatword "^f3Remove ^f7all actions? (^f0" (listlen $_de_actions_time) "^f7)") [
_de_actions_time = []
_de_actions_command = []
_de_actions_timereadable = []
]
] "de_trash.png"
]
guistrut -1
]
]
] 0.55 (? (! $paused) (? $_de_runningaction "0.2/1/0.2" "1/0.2/0.2") (? $_de_runningaction "1/1/0.2" "0.2/0.2/0.2"))
guistrut -5
]
]
// save/load action button
if (!=s $_de_input_demoname "") [
local newcfgfile
newcfgfile = (concatword (strreplace (? $_de_validdemoname $_de_validdemoname $_de_input_demoname) ".dmo" "") ".cfg")
guilist [
guistrut -0.6
_de_icon "de_folder.png" [
_de_refreshdemovalidity
_de_confirm (concatword "^f0Save " (? $_de_actions_hascfgfile "^f2" (? $_de_validdemoname "^f7" "^f3")) (_de_strshortify @newcfgfile 25 10) "^f7?") [
_de_actions_buff = (concatword "_de_echo [*~f0Loaded *~f1" (listlen $_de_actions_time) " *~f0" (? (!= (listlen $_de_actions_time) 1) "actions" "action") " by *~f1" (getname) "]^n_de_actions_time = [" $_de_actions_time "]^n_de_actions_timereadable = [" $_de_actions_timereadable "]^n_de_actions_command = [" (_de_command_unescape $_de_actions_command) "]^n^n// generated with Pseudo Demo Editor, by Salatiel#5274^n// https://github.com/SalatielSauer/Sauer-Demo-Editor")
textfocus "_de_actions_buff"
textcopy
_de_echo "saving..."
_de_sleep_run [
textsave @@@newcfgfile
_de_echo (? (findfile @@@newcfgfile) "^f0Actions saved successfully." "^f3Could not save actions to file, try again.")
]
_de_refreshdemovalidity
] [
if $_de_actions_hascfgfile [
guialign 0 [
guitext "or " 0
guibutton "^f0Load available .cfg" [
_de_confirm (concatword "^f1Load ^f7" (_de_strshortify $_de_actions_hascfgfile 25 10) "?") [_de_loadcfgfile]
] "de_folder.png"
]
guistrut -1
]
]
] 0.55 "1/1/1"
guistrut -5
]
]
]
]
guilist [
// it is not possible to edit the value of a guieditor var directly
// so we use an offscreen guifield and copy/paste its content there
guistrut -5000
guifield _de_actions_buff 1
]
// equivalent to sleep 0, but functional during paused game
if (= $_de_sleep_current $_de_sleep_target) [do $_de_sleep_action]
_de_sleep_current = (? (= $_de_sleep_current 0) 1 2)
guistrut -2
// add/remove action button
guialign 0 [
local availableactions
availableactions = (> (listlen $_de_actions_time) 1)
guistrut 0.1
_de_icon "de_arrow_left.png" [
if @availableactions [
_de_action_jumpto (at $_de_actions_time (? (= @@actiontime 0) (- (listlen $_de_actions_time) 1) (- @@actiontime 1)))
]
] 0.55 (? $availableactions "1/1/1" "0.2/0.2/0.2")
guistrut -0.9
if (!= $actiontime -1) [
_de_icon "de_minus.png" [
_de_confirm (concatword "Remove action ^f0#" @actiontime "^f~?") [
_de_actions_time = (_de_listreplace $_de_actions_time @@actiontime "")
_de_actions_timereadable = (_de_listreplace $_de_actions_timereadable @@actiontime "")
_de_actions_command = (_de_listreplace $_de_actions_command @@actiontime "")
] [
guialign 0 [
guitext "^f7or " 0
guibutton "^f1update value" [
_de_actions_command = (_de_listreplace $_de_actions_command @@@@actiontime (concatword "[" (_de_command_escape $textshow) "]"))
_de_echo (concatword "Value of action ^f0#" @actiontime " ^f~updated successfully.")
] 0
]
guistrut -1
]
] 0.55 "1/0.2/0.2"
] [
_de_icon "de_plus.png" [
if (=s $textshow "") [
_de_echo "There is no command to be added to the current time."
] [
append _de_actions_time (concatword "[" @@inputtime "]")
append _de_actions_timereadable (concatword "[" @@_de_input_minutes " " @@_de_input_seconds "]")
append _de_actions_command (concatword "[" (_de_command_escape $textshow) "]")
]
] 0.55 (? (=s $textshow "") "0.2/0.2/0.2" "0/1/0")
]
guistrut -0.8
_de_icon "de_arrow_right.png" [
if @availableactions [
_de_action_jumpto (at $_de_actions_time (+ @@actiontime 1))
]
] 0.55 (? $availableactions "1/1/1" "0.2/0.2/0.2")
]
guistrut -2
guialign 0 [
guistrut -0.1
guititle (? (!= @actiontime -1) (concatword "^f0" (strreplace (at $_de_actions_timereadable $actiontime) " " ":") "^f6(" @actiontime ")") "^f4no action")
]
]
// popup for warnings and action confirmations
local popupactive
popupactive = (|| $_de_popupvisible (> $_de_savedmillis $_de_curmillis))
if $popupactive [
guistrut -8
_de_icon "de_popup.png" [] 8.2 "0/0/0"
guistrut -6
] [guistrut 1.5]
guialign 0 [
guilist [
if $popupactive [
guistrut -4
guialign 0 [guiimage "packages/icons/de_warning.png" [] 0.8]
if (! $_de_popupvisible) [
guitextbox (strreplace $_de_message "*~f" "^f") 30
_de_curmillis = (+ $_de_curmillis 50)
] [
guititle (concatword "^f7" $_de_message)
guialign 0 [
guistayopen [
_de_icon "de_confirm.png" [_de_popupvisible = 0; _de_curmillis = $_de_savedmillis; _de_confirmaction] 0.5 "0/1/0"
guistrut 1
_de_icon "de_cancel.png" [_de_popupvisible = 0; _de_curmillis = $_de_savedmillis] 0.5 "0.9/0.2/0.2"
]
]
guistayopen [if $_de_confirmgui [_de_confirmgui]]
]
] [
_de_message = ""
guistrut 2
]
]
]
if $popupactive [guistrut 1.1]
//]
]
] 0