Skip to content

Commit

Permalink
LostArtefacts#219 TR3 Environment support
Browse files Browse the repository at this point in the history
Initial updates for TREnvironmentEditor to support TR3. Most functions remain to be implemented, but the simpler ones have been done. New functions added for copying rooms (TR3 only so far) and copying vertex attributes so that new faces added to rooms can match their neighbours (mainly lighting).
  • Loading branch information
lahm86 committed Oct 30, 2021
1 parent e095674 commit 8cde85e
Show file tree
Hide file tree
Showing 49 changed files with 1,113 additions and 100 deletions.
4 changes: 2 additions & 2 deletions TREnvironmentEditor/EMEditorMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace TREnvironmentEditor
{
public class EMEditorMapping
{
private static readonly EMConverter _converter = new EMConverter();
public static readonly EMConverter Converter = new EMConverter();

public EMEditorSet All { get; set; }
public EMEditorSet NonPurist { get; set; }
Expand All @@ -34,7 +34,7 @@ public static EMEditorMapping Get(string packPath)
{
if (File.Exists(packPath))
{
return JsonConvert.DeserializeObject<EMEditorMapping>(File.ReadAllText(packPath), _converter);
return JsonConvert.DeserializeObject<EMEditorMapping>(File.ReadAllText(packPath), Converter);
}

return null;
Expand Down
1 change: 1 addition & 0 deletions TREnvironmentEditor/Model/BaseEMCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public abstract class BaseEMCondition
public EMConditionType ConditionType { get; set; }

public abstract bool GetResult(TR2Level level);
public abstract bool GetResult(TR3Level level);
}
}
12 changes: 12 additions & 0 deletions TREnvironmentEditor/Model/BaseEMFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public abstract class BaseEMFunction
public EMType EMType { get; set; }

public abstract void ApplyToLevel(TR2Level level);
public abstract void ApplyToLevel(TR3Level level);

/// <summary>
/// Gets the expected vertices for a flat tile.
Expand Down Expand Up @@ -71,5 +72,16 @@ public ISet<byte> GetAdjacentRooms(TR2Room room, bool above)
}
return rooms;
}

// This allows us to access the last item in a specific list, so if for example one mod has created
// a new room, subsequent mods can retrieve its number using short.MaxValue.
protected int ConvertItemNumber(int itemNumber, ushort numItems)
{
if (itemNumber == short.MaxValue)
{
itemNumber = numItems - 1;
}
return itemNumber;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using TRLevelReader.Model;
using TRLevelReader.Model.Enums;

namespace TREnvironmentEditor.Model.Conditions
{
public class EMEntityPropertyCondition : BaseEMCondition
{
public int EntityIndex { get; set; }
public TR2Entities? EntityType { get; set; }
public short? EntityType { get; set; }
public bool? Invisible { get; set; }
public bool? ClearBody { get; set; }
public short? Intensity1 { get; set; }
Expand All @@ -15,11 +14,20 @@ public class EMEntityPropertyCondition : BaseEMCondition

public override bool GetResult(TR2Level level)
{
TR2Entity entity = level.Entities[EntityIndex];
return GetResult(level.Entities[EntityIndex]);
}

public override bool GetResult(TR3Level level)
{
return GetResult(level.Entities[EntityIndex]);
}

private bool GetResult(TR2Entity entity)
{
bool result = true;
if (EntityType.HasValue)
{
result &= (TR2Entities)entity.TypeID == EntityType.Value;
result &= entity.TypeID == EntityType.Value;
}
if (Invisible.HasValue)
{
Expand Down
5 changes: 5 additions & 0 deletions TREnvironmentEditor/Model/EMConditionalEditorSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@ public List<EMEditorSet> GetApplicableSets(TR2Level level)
{
return Condition.GetResult(level) ? OnTrue : OnFalse;
}

public List<EMEditorSet> GetApplicableSets(TR3Level level)
{
return Condition.GetResult(level) ? OnTrue : OnFalse;
}
}
}
9 changes: 9 additions & 0 deletions TREnvironmentEditor/Model/EMEditorGroupedSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,14 @@ public void ApplyToLevel(TR2Level level, EMEditorSet follower, IEnumerable<EMTyp
follower.ApplyToLevel(level, excludedTypes);
}
}

public void ApplyToLevel(TR3Level level, EMEditorSet follower, IEnumerable<EMType> excludedTypes)
{
if (Leader.IsApplicable(excludedTypes) && follower.IsApplicable(excludedTypes))
{
Leader.ApplyToLevel(level, excludedTypes);
follower.ApplyToLevel(level, excludedTypes);
}
}
}
}
24 changes: 19 additions & 5 deletions TREnvironmentEditor/Model/EMEditorSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@ public class EMEditorSet : List<BaseEMFunction>, ITextureModifier
{
// A set of modifications that must be done together e.g. adding a ladder and a step

public void ApplyToLevel(TR2Level level, IEnumerable<EMType> excludedTypes)
public void ApplyToLevel(TR2Level level, IEnumerable<EMType> excludedTypes = null)
{
if (IsApplicable(excludedTypes))
{
foreach (BaseEMFunction mod in this)
{
mod.ApplyToLevel(level);
}
}
}

public void ApplyToLevel(TR3Level level, IEnumerable<EMType> excludedTypes = null)
{
if (IsApplicable(excludedTypes))
{
Expand All @@ -21,12 +32,15 @@ public void ApplyToLevel(TR2Level level, IEnumerable<EMType> excludedTypes)

public bool IsApplicable(IEnumerable<EMType> excludedTypes)
{
// The modification will only be performed if all types in this set are to be included.
foreach (BaseEMFunction mod in this)
if (excludedTypes != null)
{
if (excludedTypes.Contains(mod.EMType))
// The modification will only be performed if all types in this set are to be included.
foreach (BaseEMFunction mod in this)
{
return false;
if (excludedTypes.Contains(mod.EMType))
{
return false;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions TREnvironmentEditor/Model/EMType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public enum EMType
// Room types 121+
ModifyRoom = 121,
ModifyOverlaps = 122,
CopyRoom = 123,
CopyVertexAttributes = 124,

// NOOP/Placeholder
NOOP = 1000
Expand Down
2 changes: 2 additions & 0 deletions TREnvironmentEditor/Model/Types/EMPlaceholderFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ public override void ApplyToLevel(TR2Level level)
{
// NOOP
}

public override void ApplyToLevel(TR3Level level) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,31 @@
using System.Linq;
using TREnvironmentEditor.Helpers;
using TRLevelReader.Model;
using TRLevelReader.Model.Enums;

namespace TREnvironmentEditor.Model.Types
{
public class EMAdjustEntityPositionFunction : BaseEMFunction
{
public TR2Entities EntityType { get; set; }
public short EntityType { get; set; }
public Dictionary<int, Dictionary<short, EMLocation>> RoomMap { get; set; }

public override void ApplyToLevel(TR2Level level)
{
// Example use case is rotating wall blades, which need various different angles across the levels after mirroring.
// X, Y, Z in the target relocation will be relative to the current location; the angle will be the new angle.

List<TR2Entity> entities = level.Entities.ToList().FindAll(e => (TR2Entities)e.TypeID == EntityType);
List<TR2Entity> entities = level.Entities.ToList().FindAll(e => e.TypeID == EntityType);
AdjustEntities(entities);
}

public override void ApplyToLevel(TR3Level level)
{
List<TR2Entity> entities = level.Entities.ToList().FindAll(e => e.TypeID == EntityType);
AdjustEntities(entities);
}

private void AdjustEntities(List<TR2Entity> entities)
{
foreach (int roomNumber in RoomMap.Keys)
{
foreach (short currentAngle in RoomMap[roomNumber].Keys)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public override void ApplyToLevel(TR2Level level)
}
}
}

public override void ApplyToLevel(TR3Level level)
{
throw new System.NotImplementedException();
}
}

public enum EnemyType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ namespace TREnvironmentEditor.Model.Types
public class EMConvertEntityFunction : BaseEMFunction
{
public int EntityIndex { get; set; }
public TR2Entities NewEntityType { get; set; }
public short NewEntityType { get; set; }

public override void ApplyToLevel(TR2Level level)
{
level.Entities[EntityIndex].TypeID = (short)NewEntityType;
level.Entities[EntityIndex].TypeID = NewEntityType;
}

public override void ApplyToLevel(TR3Level level)
{
level.Entities[EntityIndex].TypeID = NewEntityType;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ public class EMModifyEntityFunction : BaseEMFunction

public override void ApplyToLevel(TR2Level level)
{
TR2Entity entity = level.Entities[EntityIndex];
ModifyEntity(level.Entities[EntityIndex]);
}

public override void ApplyToLevel(TR3Level level)
{
ModifyEntity(level.Entities[EntityIndex]);
}

private void ModifyEntity(TR2Entity entity)
{
if (Invisible.HasValue)
{
entity.Invisible = Invisible.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@ public override void ApplyToLevel(TR2Level level)
// Otherwise, reposition the enemy and its triggers.
RepositionTriggerable(enemy, level);
}

public override void ApplyToLevel(TR3Level level)
{
throw new System.NotImplementedException();
}
}
}
12 changes: 11 additions & 1 deletion TREnvironmentEditor/Model/Types/Entities/EMMoveEntityFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ public class EMMoveEntityFunction : BaseEMFunction

public override void ApplyToLevel(TR2Level level)
{
TR2Entity entity = level.Entities[EntityIndex];
MoveEntity(level.Entities[EntityIndex]);

}

public override void ApplyToLevel(TR3Level level)
{
MoveEntity(level.Entities[EntityIndex]);
}

private void MoveEntity(TR2Entity entity)
{
entity.X = TargetLocation.X;
entity.Y = TargetLocation.Y;
entity.Z = TargetLocation.Z;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,10 @@ public override void ApplyToLevel(TR2Level level)
}
}
}

public override void ApplyToLevel(TR3Level level)
{
throw new System.NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public override void ApplyToLevel(TR2Level level)
}
}

public override void ApplyToLevel(TR3Level level)
{
throw new System.NotImplementedException();
}

protected void MoveTriggers(FDControl control, TRRoomSector currentSector, TRRoomSector newSector)
{
if (newSector.FDIndex == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ public override void ApplyToLevel(TR2Level level)
TR2Entity trap = level.Entities[EntityIndex];
RepositionTriggerable(trap, level);
}

public override void ApplyToLevel(TR3Level level)
{
throw new System.NotImplementedException();
}
}
}
5 changes: 5 additions & 0 deletions TREnvironmentEditor/Model/Types/Mirroring/EMMirrorFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,5 +522,10 @@ private void MirrorTextures(TR2Level level)
}
}
}

public override void ApplyToLevel(TR3Level level)
{
throw new NotImplementedException();
}
}
}
Loading

0 comments on commit 8cde85e

Please sign in to comment.