Allow editing thing info through Lua

This commit is contained in:
spherallic 2023-09-21 01:36:59 +02:00
parent 9046f6a4f7
commit fe4aef43b7
3 changed files with 41 additions and 13 deletions

View file

@ -1936,6 +1936,11 @@ namespace CodeImp.DoomBuilder.Data
{
// Update the thing
thingtypes[actor.DoomEdNum].ModifyByDecorateActor(actor);
// Re-assign category in case it changed
thingtypes[actor.DoomEdNum].Category.RemoveThing(thingtypes[actor.DoomEdNum]);
ThingCategory tc = GetThingCategory(null, thingcategories, GetCategoryInfo(actor));
tc.AddThing(thingtypes[actor.DoomEdNum]);
}
else
{

View file

@ -14,7 +14,7 @@ namespace CodeImp.DoomBuilder.ZDoom
{
#region ================== DECORATE Actor Structure parsing
internal LuaMobjStructure(ZDTextParser zdparser, string objname)
internal LuaMobjStructure(ZDTextParser zdparser, string objname, int editnum)
{
classname = string.Empty;
@ -22,12 +22,15 @@ namespace CodeImp.DoomBuilder.ZDoom
bool done = false; //mxd
General.WriteLogLine(objname);
if (string.IsNullOrEmpty(objname))
if (string.IsNullOrEmpty(objname) && editnum == 0)
{
parser.ReportError("Expected actor class name");
parser.ReportError("Lua object structure has no object name or map thing number");
return;
}
if (editnum > 0)
doomednum = editnum;
// Now parse the contents of actor structure
while (parser.SkipWhitespace(true))
@ -38,6 +41,7 @@ namespace CodeImp.DoomBuilder.ZDoom
switch (token)
{
case "}":
case "$}":
// Actor scope ends here, break out of this parse loop
done = true;
break;
@ -94,7 +98,7 @@ namespace CodeImp.DoomBuilder.ZDoom
props["yscale"] = values;
break;
case "doomednum":
doomednum = int.Parse(values[0]);
doomednum = (editnum > 0) ? editnum : int.Parse(values[0]);
goto default;
case "height":
case "radius":

View file

@ -121,29 +121,48 @@ namespace CodeImp.DoomBuilder.ZDoom
{
// Read a token
string token = ReadToken();
if (!string.IsNullOrEmpty(token))
{
if (!token.StartsWith("mobjinfo[") || !token.EndsWith("]")) continue;
string objname = token.Substring(9).TrimEnd(new char[] { ']' });
string objname = null;
int editnum = 0;
SkipWhitespace(true);
token = ReadToken();
if (token != "=")
if (token.Contains("$EditInfo"))
{
continue;
SkipWhitespace(true);
token = ReadToken();
bool valid = int.TryParse(token, out editnum);
if (!valid || editnum <= 0)
{
continue;
}
}
else
{
if (!token.StartsWith("mobjinfo[") || !token.EndsWith("]")) continue;
objname = token.Substring(9).TrimEnd(new char[] { ']' });
SkipWhitespace(true);
token = ReadToken();
if (token != "=")
{
continue;
}
}
SkipWhitespace(true);
token = ReadToken();
if (token != "{")
{
ReportError("Invalid object definition, missing {");
return false;
}
// Read actor structure
ActorStructure mobj = new LuaMobjStructure(this, objname);
if (mobj.props.ContainsKey("doomednum"))
General.WriteLogLine("Mobj doomednum = " + mobj.props["doomednum"][0]);
ActorStructure mobj = new LuaMobjStructure(this, objname, editnum);
if (this.HasError) return false;
mobjs[mobj.DoomEdNum] = mobj;