Skip to content

Commit

Permalink
CurMapSCR incremental load
Browse files Browse the repository at this point in the history
  • Loading branch information
audinowho committed Jun 5, 2024
1 parent c874c32 commit 884cd63
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions RogueEssence/Lua/LuaEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,20 @@ private void ModDoFile(string moduleName)
}
}

private LuaTable ModLoadTable(string loadPath, string importpath)
/// <summary>
/// Assigns a table to the specified variable in layers.
/// First the base game's table is applied
/// then each mod adds on top of it
/// </summary>
/// <param name="loadPath"></param>
/// <param name="importpath"></param>
/// <returns></returns>
/// <exception cref="InvalidDataException"></exception>
private void ModLayerTable(string assignVar, string loadPath, string importpath)
{
LuaTable tbl = LuaEngine.Instance.RunString("return {}").First() as LuaTable;
LuaState[assignVar] = tbl;

LuaFunction addmeta = LuaEngine.Instance.RunString(@"local mergeTables = function(t1, t2)
for k, v in pairs(t2) do
if (type(v) == ""table"") and (type(t1[k] or false) == ""table"") then
Expand All @@ -667,7 +678,6 @@ private LuaTable ModLoadTable(string loadPath, string importpath)
addmeta.Call(tbl, tbl2);
}
}
return tbl;
}

/// <summary>
Expand Down Expand Up @@ -1336,8 +1346,7 @@ private void RunAssetScript(string relpath, string assetname, string importpath,
//RunString(String.Format("{0} = require('{1}');", globalsymbol, importpath), abspath);
//LuaState[globalsymbol] = LuaEngine.Instance.RunString("return {}").First() as LuaTable;
//ModDoFile(relpath);
LuaTable state = ModLoadTable(relpath, importpath);
LuaState[globalsymbol] = state;
ModLayerTable(globalsymbol, relpath, importpath);
}

/// <summary>
Expand Down

0 comments on commit 884cd63

Please sign in to comment.