From 199edb6c9f526c879071f9b281720f2d72d2cf06 Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Fri, 20 May 2022 21:43:51 -0400 Subject: [PATCH] 2.3 FancyRoomSelect --- .../CommunityScripts/FancyRoomSelect.csx | 108 +++++++++++------- 1 file changed, 64 insertions(+), 44 deletions(-) diff --git a/UndertaleModTool/CommunityScripts/FancyRoomSelect.csx b/UndertaleModTool/CommunityScripts/FancyRoomSelect.csx index 497d75135..f5a520ec3 100644 --- a/UndertaleModTool/CommunityScripts/FancyRoomSelect.csx +++ b/UndertaleModTool/CommunityScripts/FancyRoomSelect.csx @@ -1,70 +1,74 @@ //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) { +if (obj == null) +{ obj = new UndertaleGameObject() { Name = Data.Strings.MakeString("obj_roomselector"), Persistent = true }; Data.GameObjects.Add(obj); } -if(Data.GeneralInfo.Name.Content.StartsWith("UNDERTALE")) { +if (Data.GeneralInfo.Name.Content.StartsWith("UNDERTALE")) +{ // Remove existing F3 handler to avoid accidentally // creating system_information_962 Data.GameObjects.ByName("obj_time").EventHandlerFor(EventType.KeyPress, (uint)114, Data.Strings, Data.Code, Data.CodeLocals).ReplaceGML("", Data); } -bool gms2 = Data.IsVersionAtLeast(2,0,0,0); +bool gms2 = Data.IsVersionAtLeast(2, 0, 0, 0); var entry_room = Data.GeneralInfo.RoomOrder[0].Resource; var object_list = entry_room.GameObjects; bool add_to_room = true; -if(gms2) { +if (gms2) +{ UndertaleRoom.Layer target_layer = null; - foreach(var layer in entry_room.Layers) { - if(layer.LayerType == UndertaleRoom.LayerType.Instances) { - foreach(var layer_obj in layer.InstancesData.Instances) { - if(layer_obj.ObjectDefinition == obj) { + foreach (var layer in entry_room.Layers) + { + if (layer.LayerType == UndertaleRoom.LayerType.Instances) + { + foreach (var layer_obj in layer.InstancesData.Instances) + { + if (layer_obj.ObjectDefinition == obj) + { add_to_room = false; break; } } - if(!add_to_room) { + if (!add_to_room) + { break; } - if(target_layer == null || target_layer.LayerDepth > layer.LayerDepth) { + if (target_layer == null || target_layer.LayerDepth > layer.LayerDepth) + { target_layer = layer; } } } - - if(add_to_room) { - if(target_layer == null) { + + if (add_to_room) + { + if (target_layer == null) + { uint layer_id = 0; - foreach(var room in Data.Rooms) { - foreach(var layer in room.Layers) { - if(layer.LayerId > layer_id) { + foreach (var room in Data.Rooms) + { + foreach (var layer in room.Layers) + { + if (layer.LayerId > layer_id) + { layer_id = (uint)layer.LayerId; } } } - - target_layer = new UndertaleRoom.Layer() { + + target_layer = new UndertaleRoom.Layer() + { LayerName = Data.Strings.MakeString("Room_Selector_Layer"), Data = new UndertaleRoom.Layer.LayerInstancesData(), LayerType = UndertaleRoom.LayerType.Instances, @@ -72,32 +76,40 @@ if(gms2) { LayerId = layer_id, IsVisible = true }; - + entry_room.Layers.Add(target_layer); } - var obj_to_add = new UndertaleRoom.GameObject() { + var obj_to_add = new UndertaleRoom.GameObject() + { InstanceID = Data.GeneralInfo.LastObj++, ObjectDefinition = obj, - X = 0, Y = 0 + X = 0, + Y = 0 }; target_layer.InstancesData.Instances.Add(obj_to_add); object_list.Add(obj_to_add); } } -else { +else +{ - foreach(var room_obj in object_list) { - if(room_obj.ObjectDefinition == obj) { + foreach (var room_obj in object_list) + { + if (room_obj.ObjectDefinition == obj) + { add_to_room = false; break; } } - if(add_to_room) { - object_list.Add(new UndertaleRoom.GameObject() { + if (add_to_room) + { + object_list.Add(new UndertaleRoom.GameObject() + { InstanceID = Data.GeneralInfo.LastObj++, ObjectDefinition = obj, - X = 0, Y = 0 + X = 0, + Y = 0 }); } } @@ -127,14 +139,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 +181,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]) { @@ -411,7 +431,7 @@ exiting = 0 ", Data); -ScriptMessage("Successfully applied for Gamemaker " + (gms2 ? 2 : 1).ToString() + @" +ScriptMessage("Successfully applied for Gamemaker " + (Data.GMS2_3 ? "2.3" : (gms2 ? "2" : "1")) + @" Controls: - F3: open/close menu - Escape: close menu