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 // Update the thing
thingtypes[actor.DoomEdNum].ModifyByDecorateActor(actor); 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 else
{ {

View file

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

View file

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