Skip to content

Commit

Permalink
2.3 FancyRoomSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacky720 committed May 21, 2022
1 parent 1f4f460 commit 199edb6
Showing 1 changed file with 64 additions and 44 deletions.
108 changes: 64 additions & 44 deletions UndertaleModTool/CommunityScripts/FancyRoomSelect.csx
Original file line number Diff line number Diff line change
@@ -1,103 +1,115 @@
//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,
LayerDepth = -1000,
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
});
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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])
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 199edb6

Please sign in to comment.