mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-14 07:21:51 +00:00
add vcm old models converter button to the editor temporary
This commit is contained in:
parent
d54bb5bf54
commit
c713015134
2 changed files with 78 additions and 0 deletions
|
|
@ -31,6 +31,12 @@
|
||||||
hover-color="#1080FF"
|
hover-color="#1080FF"
|
||||||
onclick="run_current_file()"
|
onclick="run_current_file()"
|
||||||
color="#FFFFFF80" size="16"></image>
|
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>
|
</panel>
|
||||||
<label id="title" pos="26,8"></label>
|
<label id="title" pos="26,8"></label>
|
||||||
</container>
|
</container>
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,78 @@ local function reload_model(filename, name)
|
||||||
assets.parse_model(file.ext(filename), document.editor.text, name)
|
assets.parse_model(file.ext(filename), document.editor.text, name)
|
||||||
end
|
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()
|
function run_current_file()
|
||||||
if not current_file.filename then
|
if not current_file.filename then
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue