Skip to content

Commit 234742d

Browse files
committed
editor: tex command editor
1 parent 252040d commit 234742d

File tree

6 files changed

+896
-6
lines changed

6 files changed

+896
-6
lines changed

config/tool.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ exec "config/tool/toolenv.cfg"
88
exec "config/tool/toolmat.cfg"
99
exec "config/tool/toolai.cfg"
1010
exec "config/tool/toolphysics.cfg"
11+
exec "config/tool/toolimgedit.cfg"

config/tool/toolcommon.cfg

+66
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,72 @@ tool_path_striptexcmds = [
326326
]
327327
]
328328

329+
// Returns a list of texture commands from a texture path
330+
// E.g. "<invert><mad:0/0.5/0.2>folder/image.jpg" -> [[invert] [mad [0 0.5 0.2]]]
331+
// 1:<path>
332+
tool_path_gettexcmds = [
333+
local _path _open_bracket _close_bracket _cmd _parsed_cmd _cmds
334+
_path = $arg1
335+
_open_bracket = (strstr $_path "<")
336+
_cmds = []
337+
338+
while [>= $_open_bracket 0] [
339+
_close_bracket = (strstr $_path ">")
340+
_cmd = (substr $_path (+ $_open_bracket 1) (- $_close_bracket $_open_bracket 1))
341+
342+
// Remove ":" and "," separators
343+
_cmd = (strreplace (strreplace $_cmd ":" " ") "," " ")
344+
345+
// Format the command arguments into sublists
346+
loop i (listlen $_cmd) [
347+
if (= $i 0) [
348+
_parsed_cmd = (at $_cmd 0)
349+
] [
350+
append _parsed_cmd [[@@(strreplace (at $_cmd $i) "/" " ")]]
351+
]
352+
]
353+
354+
// Add the command to the list
355+
append _cmds [[@@_parsed_cmd]]
356+
357+
// Remove the command from the path
358+
_path = (substr $_path (+ $_close_bracket 1))
359+
360+
// Find the next command
361+
_open_bracket = (strstr $_path "<")
362+
]
363+
364+
result $_cmds
365+
]
366+
367+
// Returns a formatted texture command
368+
// E.g. "mad [0 0.5 0.2]" -> "<mad:0/0.5/0.2>"
369+
// 1:<command>
370+
tool_path_maketexcmd = [
371+
local _cmd _cmd_len _cmd_str _cmdlet
372+
_cmd = $arg1
373+
_cmd_len = (listlen $_cmd)
374+
375+
if (> $_cmd_len 1) [
376+
_cmd_str = (concatword "<" (at $_cmd 0) ":")
377+
378+
// Add the command arguments
379+
loop i (- $_cmd_len 1) [
380+
_cmdlet = (strreplace (at $_cmd (+ $i 1)) " " "/")
381+
382+
if (= $i (- $_cmd_len 2)) [
383+
_cmd_str = (concatword $_cmd_str $_cmdlet)
384+
] [
385+
_cmd_str = (concatword $_cmd_str $_cmdlet ",")
386+
]
387+
]
388+
389+
concatword $_cmd_str ">"
390+
] [
391+
concatword "<" $_cmd ">"
392+
]
393+
]
394+
329395
TOOL_VERSION = 3
330396

331397
tool_on_mapload_handlers = []

config/tool/toolimgedit.cfg

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
TOOL_IMGEDIT_CMDS = [
2+
"mad"
3+
"colourify"
4+
"colourmask"
5+
"invert"
6+
"invertchan"
7+
"normal"
8+
"dup"
9+
"offset"
10+
"rotate"
11+
"crop"
12+
"blur"
13+
"premul"
14+
"agrad"
15+
// "blend"
16+
"dds"
17+
"nocompress"
18+
"anim"
19+
]
20+
21+
TOOL_IMGEDIT_CMD_NAMES = [
22+
"Multiply & Add"
23+
"Colourify" // Luminance-based colouring
24+
"Colour mask" // Lerp between two colours based on alpha
25+
"Invert" // Inverts all channels
26+
"Invert channel" // Invert a single channel
27+
"Generate normalmap" // Generates a normalmap from diffuse
28+
"Copy channel" // Copies a channel to another
29+
"Offset" // Offsets the image in pixels
30+
"Rotate" // Rotates and/or flips the image
31+
"Crop"
32+
"Blur"
33+
"Premultiplied alpha"
34+
"Alpha gradient"
35+
// "Blend with"
36+
"Use DDS"
37+
"Force no compression"
38+
"Animation"
39+
]
40+
41+
TOOL_IMGEDIT_CMD_DEFAULTS = [
42+
[[1 1 1] [0 0 0]] // mad
43+
[[0 0 0]] // colourify
44+
[[0 0 0] [0 0 0]] // colourmask
45+
[] // invert
46+
[0] // invertchan
47+
[3] // normal
48+
[0 0] // dup
49+
[0 0] // offset
50+
[0] // rotate
51+
[0 0 -1 -1] // crop
52+
[1 1] // blur
53+
[] // premul
54+
[1 1 0 0] // agrad
55+
// blend
56+
[] // dds
57+
[] // nocompress
58+
[50 1 2 0 0 0] // anim
59+
]
60+
61+
tool_imgedit_var = []
62+
tool_imgedit_imgpath = ""
63+
tool_imgedit_cmds = []
64+
tool_imgedit_cmd_idxs = []
65+
tool_imgedit_numcmds = 0
66+
67+
tool_imgedit_getcmds = [
68+
local _cmd
69+
70+
tool_imgedit_imgpath = (tool_path_striptexcmds $$tool_imgedit_var)
71+
tool_imgedit_cmds = (tool_path_gettexcmds $$tool_imgedit_var)
72+
tool_imgedit_numcmds = (listlen $tool_imgedit_cmds)
73+
tool_imgedit_cmd_idxs = []
74+
75+
loop i $tool_imgedit_numcmds [
76+
_cmd = (at $tool_imgedit_cmds $i)
77+
78+
[tool_imgedit_cmd_tmp_@i] = $_cmd
79+
80+
append tool_imgedit_cmd_idxs (listfind=s $TOOL_IMGEDIT_CMDS (at $_cmd 0))
81+
]
82+
]
83+
84+
tool_imgedit_apply = [
85+
local _cmd _cmds
86+
87+
tool_imgedit_cmds = []
88+
_cmds = []
89+
90+
loop i $tool_imgedit_numcmds [
91+
_cmd = $[tool_imgedit_cmd_tmp_@i]
92+
append tool_imgedit_cmds [[@@_cmd]]
93+
appendword _cmds (tool_path_maketexcmd $_cmd)
94+
]
95+
96+
set $tool_imgedit_var (concatword $_cmds $tool_imgedit_imgpath)
97+
]
98+
99+
// 1:<index> 2:<direction (-1 left/1 right)>
100+
tool_imgedit_cmd_shift = [
101+
local _min_idx _max_idx _new_idx
102+
_min_idx = (? (= $arg2 -1) 1 0)
103+
_max_idx = (- $tool_imgedit_numcmds (? (= $arg2 1) 1 0))
104+
_new_idx = (+ $arg1 $arg2)
105+
106+
if (&& [>= $arg1 $_min_idx] [< $arg1 $_max_idx]) [
107+
local _tmp
108+
_tmp = $[tool_imgedit_cmd_tmp_@arg1]
109+
110+
[tool_imgedit_cmd_tmp_@arg1] = $[tool_imgedit_cmd_tmp_@_new_idx]
111+
[tool_imgedit_cmd_tmp_@_new_idx] = $_tmp
112+
113+
_tmp = (at $tool_imgedit_cmd_idxs $arg1)
114+
tool_imgedit_cmd_idxs = (listsplice $tool_imgedit_cmd_idxs (at $tool_imgedit_cmd_idxs $_new_idx) $arg1 1)
115+
tool_imgedit_cmd_idxs = (listsplice $tool_imgedit_cmd_idxs $_tmp $_new_idx 1)
116+
]
117+
]
118+
119+
// 1:<index> 2:<type idx>
120+
tool_imgedit_cmd_add = [
121+
local _new_cmd _new_args
122+
_new_cmd = (at $TOOL_IMGEDIT_CMDS $arg2)
123+
_new_args = (at $TOOL_IMGEDIT_CMD_DEFAULTS $arg2)
124+
125+
if (!=s $_new_args []) [
126+
append _new_cmd $_new_args
127+
]
128+
129+
looprev i $tool_imgedit_numcmds [
130+
if (>= $i $arg1) [
131+
[tool_imgedit_cmd_tmp_@(+ $i 1)] = $[tool_imgedit_cmd_tmp_@i]
132+
]
133+
]
134+
135+
[tool_imgedit_cmd_tmp_@arg1] = [@_new_cmd]
136+
tool_imgedit_cmd_idxs = (listsplice $tool_imgedit_cmd_idxs (concat $arg2 (at $tool_imgedit_cmd_idxs $arg1)) $arg1 1)
137+
138+
tool_imgedit_numcmds = (+ $tool_imgedit_numcmds 1)
139+
]
140+
141+
// 1:<index>
142+
tool_imgedit_cmd_remove = [
143+
loop i (- $tool_imgedit_numcmds 1) [
144+
if (>= $i $arg1) [
145+
[tool_imgedit_cmd_tmp_@i] = $[tool_imgedit_cmd_tmp_@(+ $i 1)]
146+
]
147+
]
148+
149+
tool_imgedit_cmd_idxs = (listsplice $tool_imgedit_cmd_idxs "" $arg1 1)
150+
tool_imgedit_numcmds = (- $tool_imgedit_numcmds 1)
151+
]
152+
153+
// 1:<var>
154+
tool_imgedit_open = [
155+
tool_imgedit_var = $arg1
156+
tool_imgedit_getcmds
157+
158+
toolpanel_open tool_imgedit center [
159+
p_title = "Image editor"
160+
]
161+
]

config/ui/tool.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ exec "config/ui/tool/toolenv.cfg"
1010
exec "config/ui/tool/toolmat.cfg"
1111
exec "config/ui/tool/toolai.cfg"
1212
exec "config/ui/tool/toolphysics.cfg"
13+
exec "config/ui/tool/toolimgedit.cfg"
1314

1415
toolview_init

0 commit comments

Comments
 (0)