Skip to content

Commit

Permalink
LostArtefacts#241 Environment Click Function
Browse files Browse the repository at this point in the history
Adds a basic surface click function to move a sector's floor or ceiling up or down - this differs from the EMFloor and EMCeiling functions as it doesn't take faces into consideration.
  • Loading branch information
lahm86 committed Dec 11, 2021
1 parent 1d47f8a commit 92ef55b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions TREnvironmentEditor/Model/EMType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public enum EMType
Flood = 2,
Drain = 3,
Ceiling = 4,
Click = 5,

// Texture types 21-40
Reface = 21,
Expand Down
46 changes: 46 additions & 0 deletions TREnvironmentEditor/Model/Types/Surfaces/EMClickFunction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using TREnvironmentEditor.Helpers;
using TRFDControl;
using TRFDControl.Utilities;
using TRLevelReader.Model;

namespace TREnvironmentEditor.Model.Types
{
public class EMClickFunction : BaseEMFunction
{
// This differs from dedicated floor/ceiling functions by only shifting sector values and does not deal with faces.
// See example in Masonic room in Aldwych.
public EMLocation Location { get; set; }
public sbyte? FloorClicks { get; set; }
public sbyte? CeilingClicks { get; set; }

public override void ApplyToLevel(TR2Level level)
{
FDControl floorData = new FDControl();
floorData.ParseFromLevel(level);

TRRoomSector sector = FDUtilities.GetRoomSector(Location.X, Location.Y, Location.Z, Location.Room, level, floorData);
MoveSector(sector);
}

public override void ApplyToLevel(TR3Level level)
{
FDControl floorData = new FDControl();
floorData.ParseFromLevel(level);

TRRoomSector sector = FDUtilities.GetRoomSector(Location.X, Location.Y, Location.Z, Location.Room, level, floorData);
MoveSector(sector);
}

private void MoveSector(TRRoomSector sector)
{
if (FloorClicks.HasValue)
{
sector.Floor += FloorClicks.Value;
}
if (CeilingClicks.HasValue)
{
sector.Ceiling += CeilingClicks.Value;
}
}
}
}
2 changes: 2 additions & 0 deletions TREnvironmentEditor/Parsing/EMConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ private object ReadEMType(JObject jo)
return JsonConvert.DeserializeObject<EMDrainFunction>(jo.ToString(), _resolver);
case EMType.Ceiling:
return JsonConvert.DeserializeObject<EMCeilingFunction>(jo.ToString(), _resolver);
case EMType.Click:
return JsonConvert.DeserializeObject<EMClickFunction>(jo.ToString(), _resolver);

// Texture types
case EMType.Reface:
Expand Down

0 comments on commit 92ef55b

Please sign in to comment.