Merge pull request #937 from MihailRis/fix

fixes
This commit is contained in:
MihailRis 2026-08-18 00:11:23 +03:00 • committed by GitHub
commit 4111da1230
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 118 additions and 30 deletions

View file

@ -17,7 +17,7 @@
color="#FFFFFF80" size="16" pos="4,6"
hover-color="#1080FF"></image>
<panel orientation="horizontal" gravity="top-right"
size="76,24" padding="8" interval="8" color="0">
size="76,24" padding="8,6,8,2" interval="8" color="0">
<image id="saveIcon" src="gui/save" tooltip="@Save"
enabled="false" interactive="true"
hover-color="#1080FF"
@ -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

View file

@ -1,4 +1,4 @@
@box from (0,0,0) to (1,0.5,1) delete (top,south)
@box from (0,0.5,0) to (1,1,0.5) delete (bottom,south)
@box from (0,0,0) to (1,0.5,1) delete (top,north)
@box from (0,0.5,0) to (1,1,0.5) delete (bottom,north)
@rect from (0,0.5,0.5) right (1,0,0) up (0,0,0.5) texture "$2"
@rect from (0,0,0) right (1,0,0) up (0,1,0) texture "$1"