Save/load ini string API, ported examples, README

This commit is contained in:
4DBug committed 2026-10-17 04:45:03 -05:00
1 parent 16872277f2
commit ad9af52825
5 files changed
+356 -5

No files matched your search

+62 -1
View File
@@ -2594,7 +2594,68 @@ return function(G)
return ImVec2(origin.x, origin.y) -- [Port] returned by value
end
-- [Port] TODO: SaveCurrentEditorStateToIniString/Load*
-- [Port] *ToIniString returns the string (data_size dropped: use #s). *IniFile variants not available on Roblox.
local function trunc(v)
return if v < 0 then math.ceil(v) else math.floor(v)
end
function ImNodes.SaveEditorStateToIniString(editor)
IM_ASSERT(editor ~= nil)
local out = { string.format("[editor]\npanning=%d,%d\n", trunc(editor.Panning.x), trunc(editor.Panning.y)) }
for i = 1, editor.Nodes.Pool.Size do
if editor.Nodes.InUse[i] then
local node = editor.Nodes.Pool[i]
table.insert(out, string.format("\n[node.%d]\norigin=%d,%d\n", node.Id, trunc(node.Origin.x), trunc(node.Origin.y)))
end
end
return table.concat(out)
end
function ImNodes.SaveCurrentEditorStateToIniString()
return ImNodes.SaveEditorStateToIniString(internal.EditorContextGet())
end
function ImNodes.LoadEditorStateFromIniString(editor, data)
if data == nil or #data == 0 then
return
end
editor = editor or internal.EditorContextGet()
local handler = nil
for line in string.gmatch(data, "[^\r\n]+") do
if string.sub(line, 1, 1) ~= ";" then
if string.match(line, "^%[.*%]$") then
if string.sub(line, 2, 5) == "node" then
handler = "node"
elseif line == "[editor]" then
handler = "editor"
end
end
if handler == "node" then
local id = tonumber(string.match(line, "^%[node%.(%-?%d+)"))
if id then
local node_idx = internal.ObjectPoolFindOrCreateIndex(editor.Nodes, id)
internal.GImNodes.CurrentNodeIdx = node_idx
editor.Nodes.Pool[node_idx].Id = id
else
local x, y = string.match(line, "^origin=(%-?%d+),(%-?%d+)")
if x then
editor.Nodes.Pool[internal.GImNodes.CurrentNodeIdx].Origin =
internal.SnapOriginToGrid(ImVec2(tonumber(x), tonumber(y)))
end
end
elseif handler == "editor" then
local x, y = string.match(line, "^panning=([^,]+),(.+)$")
if x and tonumber(x) and tonumber(y) then
editor.Panning = ImVec2(tonumber(x), tonumber(y))
end
end
end
end
end
function ImNodes.LoadCurrentEditorStateFromIniString(data)
ImNodes.LoadEditorStateFromIniString(internal.EditorContextGet(), data)
end
function ImNodes.MiniMap(minimap_size_fraction, location, node_hovering_callback, node_hovering_callback_data)
minimap_size_fraction = minimap_size_fraction or 0.2