diff --git a/UndertaleModLib/Compiler/Parser.cs b/UndertaleModLib/Compiler/Parser.cs index e73662c0e..fe5f6a672 100644 --- a/UndertaleModLib/Compiler/Parser.cs +++ b/UndertaleModLib/Compiler/Parser.cs @@ -660,10 +660,19 @@ private static Statement ParseFunction(CompileContext context) { Statement result = new Statement(Statement.StatementKind.FunctionDef, EnsureTokenKind(TokenKind.KeywordFunction).Token); Statement args = new Statement(); + bool expression = true; + Statement destination = null; + + if (GetNextTokenKind() == TokenKind.ProcFunction) + { + expression = false; + Statement s = remainingStageOne.Dequeue(); + destination = new Statement(Statement.StatementKind.ExprFuncName, s.Token) { ID = s.ID }; + } EnsureTokenKind(TokenKind.OpenParen); - while (remainingStageOne.Count > 0 && !hasError && !IsNextToken(TokenKind.EOF) && !IsNextToken(TokenKind.CloseParen)) + while (remainingStageOne.Count > 0 && !hasError && !IsNextToken(TokenKind.EOF, TokenKind.CloseParen)) { Statement expr = ParseExpression(context); if (expr != null) @@ -682,7 +691,16 @@ private static Statement ParseFunction(CompileContext context) if (EnsureTokenKind(TokenKind.CloseParen) == null) return null; result.Children.Add(ParseStatement(context)); - return result; + if (expression) + return result; + else // Whatever you call non-anonymous definitions + { + Statement trueResult = new Statement(Statement.StatementKind.Assign, new Lexer.Token(TokenKind.Assign)); + trueResult.Children.Add(destination); + trueResult.Children.Add(new Statement(Statement.StatementKind.Token, trueResult.Token)); + trueResult.Children.Add(result); + return trueResult; + } } private static Statement ParseFor(CompileContext context) diff --git a/UndertaleModLib/Decompiler/Decompiler.cs b/UndertaleModLib/Decompiler/Decompiler.cs index 8ade85ecb..ad11b421f 100644 --- a/UndertaleModLib/Decompiler/Decompiler.cs +++ b/UndertaleModLib/Decompiler/Decompiler.cs @@ -1173,6 +1173,14 @@ public override string ToString(DecompileContext context) } } + // Someone enlighten me on structs, I'm steering clear for now. + // And find the "right" way to do this. + if (Value is FunctionDefinition functionVal && functionVal.Subtype != FunctionDefinition.FunctionType.Struct) + { + functionVal.IsStatement = true; + return functionVal.ToString(context); + } + string varPrefix = (HasVarKeyword ? "var " : ""); // Check for possible ++, --, or operation equal (for single vars) @@ -1306,6 +1314,7 @@ public enum FunctionType public UndertaleCode FunctionBodyCodeEntry { get; private set; } public Block FunctionBodyEntryBlock { get; private set; } public FunctionType Subtype { get; private set; } + public bool IsStatement = false; // I know it's an expression, yes. But I'm not duplicating the rest. internal List Arguments; @@ -1354,12 +1363,19 @@ public override string ToString(DecompileContext context) FunctionDefinition def; var oldDecompilingStruct = context.DecompilingStruct; var oldReplacements = context.ArgumentReplacements; + if (Subtype == FunctionType.Struct) context.DecompilingStruct = true; else { context.DecompilingStruct = false; - sb.Append("function("); + sb.Append("function"); + if (IsStatement) + { + sb.Append(" "); + sb.Append((context.Statements[0].Last() as AssignmentStatement).Destination.Var.Name.Content); + } + sb.Append("("); for (int i = 0; i < FunctionBodyCodeEntry.ArgumentsCount; ++i) { if (i != 0) diff --git a/UndertaleModLib/Models/UndertaleRoom.cs b/UndertaleModLib/Models/UndertaleRoom.cs index 171e17372..f61c8615e 100644 --- a/UndertaleModLib/Models/UndertaleRoom.cs +++ b/UndertaleModLib/Models/UndertaleRoom.cs @@ -1178,7 +1178,7 @@ protected void OnPropertyChanged([CallerMemberName] string name = null) // GMS 2022.1+ public bool EffectEnabled { get; set; } public UndertaleString EffectType { get; set; } - public UndertaleSimpleList EffectProperties { get; set; } + public UndertaleSimpleList EffectProperties { get; set; } = new(); public void UpdateParentRoom() { diff --git a/UndertaleModTool/Scripts/CommunityScripts/FancyRoomSelect.csx b/UndertaleModTool/Scripts/CommunityScripts/FancyRoomSelect.csx index 497d75135..fc28e0e82 100644 --- a/UndertaleModTool/Scripts/CommunityScripts/FancyRoomSelect.csx +++ b/UndertaleModTool/Scripts/CommunityScripts/FancyRoomSelect.csx @@ -1,20 +1,9 @@ //Originally created by _creepersbane#2074 //Adapted to work with all games by Grossley +//Adapted to GMS 2.3+ by Space Core/Jacky720 EnsureDataLoaded(); -if (Data?.GeneralInfo?.DisplayName?.Content.ToLower() == "deltarune chapter 1 & 2") -{ - ScriptError("Error 0: Incompatible with the new Deltarune Chapter 1 & 2 demo"); - return; -} -else if (Data?.GeneralInfo?.DisplayName?.Content.ToLower() == "deltarune chapter 1&2") -{ - ScriptError("Error 1: Incompatible with the new Deltarune Chapter 1 & 2 demo"); - return; -} - - var obj = Data.GameObjects.ByName("obj_roomselector"); if(obj == null) { @@ -127,14 +116,19 @@ update = 1 scale = 1 fnt = -4 len = 0 -ss = -4 -for (i = room_first; i <= room_last; i++) +ss = -4" ++ (!Data.GMS2_3 + ? "for (i = room_first; i <= room_last; i++)" + : "for (i = 0; room_exists(i); i++)") ++ @" { if room_exists(i) room_names[i] = (((room_get_name(i) + "" ("") + string(i)) + "")"") else room_names[i] = -4 } +// for 2.3 +myroom_last = i ww = -1 hh = -1 xx = 0 @@ -164,8 +158,11 @@ if selector_active positions[0] = -1 roomid = -1 if (dest_room != """" && dest_room == string_digits(dest_room)) - roomid = real(dest_room) - for (i = room_first; i <= room_last; i++) + roomid = real(dest_room)" + + (!Data.GMS2_3 + ? "for (i = room_first; i <= room_last; i++)" + : "for (i = 0; i < myroom_last; i++)") + + @" { if is_string(room_names[i]) { @@ -410,8 +407,15 @@ selector_active = 0 exiting = 0 ", Data); +string version; +if (Data.GMS2_3) + version = "2.3"; +else if (gms2) + version = "2"; +else + version = "1"; -ScriptMessage("Successfully applied for Gamemaker " + (gms2 ? 2 : 1).ToString() + @" +ScriptMessage(@$"Successfully applied for Gamemaker {version} Controls: - F3: open/close menu - Escape: close menu