Skip to content

Commit 80a5153

Browse files
committed
Add read/write support for SpecialRoomnames
Ved now puts the special roomnames from the XML into data structures, and writes those data structures back to XML. As Ally fixed in TerryCavanagh/VVVVVV#1265, it turned out the game couldn't deal with empty (or whitespace-only) roomnames, since TinyXML's element GetText() method returns NULL if it doesn't find a text node (or only stripped out whitespace). Luckily this is easy for Ved to workaround by just using a <![CDATA[]]> instead of raw text in that case, since that also counts as a text node (it's basically just an escape). The bug just got fixed in the VVVVVV repo, but it can't hurt to include the CDATA anyway (it's just two lines of code and it parses the same) [pre11]
1 parent 7a06d3b commit 80a5153

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

Source/level.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ function Level:new()
2424
o.vedmetadata = false
2525
o.textboxcolors = {}
2626
o.textboxcolors_order = {}
27+
o.specialroomnames = {}
28+
o.specialroomnames_order = {}
2729

2830
return o
2931
end

Source/vvvvvvxml.lua

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,56 @@ function loadlevel(path)
544544
end
545545
end
546546
end
547+
548+
local xspecialroomnames = xml:find_or_nil(xdata, "SpecialRoomnames")
549+
if xspecialroomnames ~= nil then
550+
for roomname in xml:each_child_element(xspecialroomnames) do
551+
local mode = xml:get_name(roomname)
552+
local attr = xml:get_attributes(roomname)
553+
local rx, ry, flag = tonumber(attr.x), tonumber(attr.y), tonumber(attr.flag)
554+
if rx == nil then rx = 0 end
555+
if ry == nil then ry = 0 end
556+
if flag == nil then flag = -1 end
557+
local loop = attr.loop == "1"
558+
559+
local name
560+
if mode == "transform" or mode == "glitch" then
561+
name = {}
562+
for child in xml:each_child_element(roomname, "text") do
563+
table.insert(name, xml:get_text(child))
564+
end
565+
if mode == "transform" then
566+
if #name < 1 then
567+
table.insert(name, "")
568+
end
569+
else
570+
while #name < 2 do
571+
table.insert(name, "")
572+
end
573+
end
574+
else
575+
mode = "static"
576+
name = xml:get_text(roomname)
577+
end
578+
579+
if lvl.specialroomnames[ry] == nil then
580+
lvl.specialroomnames[ry] = {}
581+
end
582+
if lvl.specialroomnames[ry][rx] == nil then
583+
lvl.specialroomnames[ry][rx] = {}
584+
table.insert(lvl.specialroomnames_order, {x=rx, y=ry})
585+
end
586+
table.insert(lvl.specialroomnames[ry][rx],
587+
{
588+
mode = mode,
589+
flag = flag,
590+
loop = loop,
591+
name = name,
592+
progress = 0
593+
}
594+
)
595+
end
596+
end
547597
end)
548598

549599
if not success then
@@ -902,6 +952,49 @@ function savelevel(path, lvl, crashed, invvvvvvfolder)
902952
lvl.xml:delete_each_child_element(xdata, "TextboxColours")
903953
end
904954

955+
local any_roomname_tag = false
956+
local xspecialroomnames
957+
for _,room in pairs(lvl.specialroomnames_order) do
958+
for k,roomname in pairs(lvl.specialroomnames[room.y][room.x]) do
959+
if not any_roomname_tag then
960+
-- Like <colour> above - this is the first special roomname tag!
961+
xspecialroomnames = lvl.xml:find_or_add(xdata, "SpecialRoomnames")
962+
lvl.xml:clear_open(xspecialroomnames)
963+
any_roomname_tag = true
964+
end
965+
local xroomname = lvl.xml:add_element_in_last(xspecialroomnames, roomname.mode)
966+
lvl.xml:set_attribute(xroomname, "x", room.x)
967+
lvl.xml:set_attribute(xroomname, "y", room.y)
968+
if roomname.flag ~= -1 then
969+
lvl.xml:set_attribute(xroomname, "flag", roomname.flag)
970+
end
971+
if roomname.mode == "transform" then
972+
lvl.xml:set_attribute(xroomname, "loop", roomname.loop and "1" or "0")
973+
end
974+
if roomname.mode == "transform" or roomname.mode == "glitch" then
975+
for k2,item in pairs(roomname.name) do
976+
local item_tag = lvl.xml:add_element_in_last(xroomname, "text")
977+
if item:gsub(" ", "") == "" then
978+
-- Workaround TinyXML gotcha with a CDATA...
979+
lvl.xml:add_text_in_first(item_tag, item, true)
980+
else
981+
lvl.xml:set_text(item_tag, item)
982+
end
983+
end
984+
else
985+
if roomname.name:gsub(" ", "") == "" then
986+
-- Workaround TinyXML gotcha with a CDATA...
987+
lvl.xml:add_text_in_first(xroomname, roomname.name, true)
988+
else
989+
lvl.xml:set_text(xroomname, roomname.name)
990+
end
991+
end
992+
end
993+
end
994+
if not any_roomname_tag then
995+
lvl.xml:delete_each_child_element(xdata, "SpecialRoomnames")
996+
end
997+
905998
-- Alright, let's save!
906999
cons("Saving file...")
9071000
local success, iferrmsg

0 commit comments

Comments
 (0)