Skip to content

Commit

Permalink
Fix brokenness with research site door implementation (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
Miepee authored Dec 30, 2023
1 parent bbb997c commit efe3b3f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.

This format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)

## [1.1.1] - 2023-12-30
### Fixed
- Crashes when shuffling Research Site hatches, and weird behaviour when its being shuffled to.

## [1.1.0] - 2023-12-27
### Added
- An item collection screen will now be shown, when the user starts with random items.
Expand Down
48 changes: 34 additions & 14 deletions YAMS-LIB/patches/DoorLockRando.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileC
if (gameObject.InstanceID != id) continue;

bool isGotoObject = gameObject.ObjectDefinition.Name.Content == "oGotoRoom";
bool isResearchHatch = gameObject.ObjectDefinition.Name.Content == "oA3LabDoor";
if (isGotoObject && !doorEntry.isDock)
{
throw new NotSupportedException($"The instance id {id} is a GotoRoom object, but the setting whether this instance is a dock is set to false!");
}

if (!gameObject.ObjectDefinition.Name.Content.StartsWith("oDoor") && gameObject.ObjectDefinition.Name.Content != "oA2BigTurbine" && !isGotoObject)
if (!gameObject.ObjectDefinition.Name.Content.StartsWith("oDoor") && gameObject.ObjectDefinition.Name.Content != "oA2BigTurbine" && !isGotoObject &&
!isResearchHatch)
{
throw new NotSupportedException($"The 'door' instance {id} is not actually a door!");
}
Expand Down Expand Up @@ -124,10 +126,32 @@ public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileC
_ => throw new NotSupportedException($"Door {id} has an unsupported door lock ({doorEntry.Lock})!")
};

var doorObject = gmData.GameObjects.ByName("oDoorA5");
var waterTurbineObject = gmData.GameObjects.ByName("oA2BigTurbine");
var researchHatchObject = gmData.GameObjects.ByName("oA3LabDoor");

if (door.ObjectDefinition == researchHatchObject && doorEntry.Lock != DoorLockType.ResearchHatch)
{
var hatchCode = door.CreationCode.GetGMLCode();
bool flipped = hatchCode.Contains("facing = -1");
if (flipped)
{
door.ScaleX *= -1;
door.X += 16;
}
}

if (door.ObjectDefinition != researchHatchObject && doorEntry.Lock == DoorLockType.ResearchHatch)
{
if (door.ScaleX < 0)
{
door.ScaleX = Math.Abs(door.ScaleX);
door.X -= 16;
}
}

if (door.ObjectDefinition == waterTurbineObject && doorEntry.Lock != DoorLockType.A2WaterTurbine)
{
door.ObjectDefinition = gmData.GameObjects.ByName("oDoorA5");
door.X += (24 * (int)door.ScaleX);
door.ScaleX *= -1;
bool leftFacing = door.ScaleX < 0;
Expand All @@ -139,8 +163,8 @@ public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileC

if (door.ObjectDefinition != waterTurbineObject && doorEntry.Lock == DoorLockType.A2WaterTurbine)
{
door.ObjectDefinition = waterTurbineObject;
door.X += (24 * (int)door.ScaleX);
int movingOffset = door.ObjectDefinition == researchHatchObject ? 48 : 24;
door.X += (movingOffset * (int)door.ScaleX);
door.ScaleX *= -1;
if ((door.X - 48) == 0)
room.GameObjects.Add(CreateRoomObject(door.X-72, door.Y, gmData.GameObjects.ByName("oSolid1x4")));
Expand All @@ -149,18 +173,14 @@ public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileC

}

var researchHatchObject = gmData.GameObjects.ByName("oA3LabDoor");
if (door.ObjectDefinition != researchHatchObject && doorEntry.Lock == DoorLockType.ResearchHatch)
{
if (doorEntry.Lock == DoorLockType.ResearchHatch)
door.ObjectDefinition = researchHatchObject;
if (door.ScaleX < 0)
{
door.ScaleX = Math.Abs(door.ScaleX);
door.X -= 16;
}
}
else if (doorEntry.Lock == DoorLockType.A2WaterTurbine)
door.ObjectDefinition = waterTurbineObject;
else
door.ObjectDefinition = doorObject;

door.CreationCode.AppendGMLInCode( codeText);
door.CreationCode.AppendGMLInCode(codeText);
doorEventIndex++;
break;
}
Expand Down

0 comments on commit efe3b3f

Please sign in to comment.