add vcm old models converter button to the editor temporary

This commit is contained in:
MihailRis 2026-08-17 22:23:20 +03:00
parent d54bb5bf54
commit c713015134
2 changed files with 78 additions and 0 deletions

View file

@ -31,6 +31,12 @@
hover-color="#1080FF"
onclick="run_current_file()"
color="#FFFFFF80" size="16"></image>
<!-- TODO: remove after 0.32-->
<image src="gui/item" size="16"
enabled="true" interactive="true"
hover-color="#1080FF"
tooltip="Fix old VCM regions (0.31 bug)"
onclick="fix_vcm_regions()"></image>
</panel>
<label id="title" pos="26,8"></label>
</container>

View file

@ -113,6 +113,78 @@ local function reload_model(filename, name)
assets.parse_model(file.ext(filename), document.editor.text, name)
end
-- === TODO: remove after 0.32 ===
local pattern =
"region %(%s*"
.. "([+-]?%d+%.?%d*[eE]?[+-]?%d*)%s*,%s*"
.. "([+-]?%d+%.?%d*[eE]?[+-]?%d*)%s*,%s*"
.. "([+-]?%d+%.?%d*[eE]?[+-]?%d*)%s*,%s*"
.. "([+-]?%d+%.?%d*[eE]?[+-]?%d*)"
.. "%s*%)"
local function replace1(x1, y1, x2, y2)
return string.format("region (%s, %s, %s, %s)", x2, y2, x1, y1)
end
local function replace2(x1, y1, x2, y2)
return string.format("region (%s, %s, %s, %s)", x2, y1, x1, y2)
end
function convert_vcm(text)
local lines = {}
local zpairs = {
{"%(north%)", "%(south%)", "(TMPS)", "(TMPN)"},
{"%,north", "%,south", ",TMPS", ",TMPN"},
{"north%,", "south%,", "TMPS,", "TMPN,"},
}
local xpairs = {
{"%(west%)", "%(east%)", "(TMPE)", "(TMPW)"},
{"%,west", "%,east", ",TMPE", ",TMPW"},
{"west%,", "east%,", "TMPE,", "TMPW,"},
}
for i, pair in ipairs(zpairs) do
text = text:gsub(pair[1], pair[3])
text = text:gsub(pair[2], pair[4])
end
text = text:gsub("TMPS", "south")
text = text:gsub("TMPN", "north")
for i, pair in ipairs(xpairs) do
text = text:gsub(pair[1], pair[3])
text = text:gsub(pair[2], pair[4])
end
text = text:gsub("TMPW", "west")
text = text:gsub("TMPE", "east")
for line in text:gmatch("[^\n]*\n?") do
if line == "" then
break
end
if line:find("(top)", 1, true) then
line = line:gsub(pattern, replace1)
end
if line:find("(bottom)", 1, true)
or line:find("(east)", 1, true) then
line = line:gsub(pattern, replace2)
end
table.insert(lines, line)
end
return table.concat(lines)
end
function fix_vcm_regions()
if not current_file.filename then
return
end
document.editor.text = convert_vcm(document.editor.text)
end
-- ===============================
function run_current_file()
if not current_file.filename then
return