Skip to content

Commit

Permalink
Update environment JSON (LostArtefacts#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahm86 authored May 3, 2024
1 parent 0d337a0 commit acce0b2
Show file tree
Hide file tree
Showing 82 changed files with 857 additions and 19,383 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void MovePickups<T>(IEnumerable<TREntity<T>> entities, EMLevelData data,
else
{
// Only look for the types we are interested in.
matchingEntities = entities.Where(e => Types.Select(t => (T)(object)(int)t).Contains(e.TypeID));
matchingEntities = entities.Where(e => Types.Select(t => (T)(object)(uint)t).Contains(e.TypeID));
}

foreach (TREntity<T> match in matchingEntities)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ private void ConvertSpriteSequence<T, E>(TRDictionary<T, TRSpriteSequence> seque
where T : Enum
where E : TREntity<T>
{
T oldID = (T)(object)OldSpriteID;
T newID = (T)(object)NewSpriteID;
T oldID = (T)(object)(uint)OldSpriteID;
T newID = (T)(object)(uint)NewSpriteID;
if (!sequences.ChangeKey(oldID, newID))
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public override void ApplyToLevel(TR3Level level)
private void CopySpriteSequence<T>(TRDictionary<T, TRSpriteSequence> sequences)
where T : Enum
{
T baseID = (T)(object)BaseSpriteID;
T targetID = (T)(object)TargetSpriteID;
T baseID = (T)(object)(uint)BaseSpriteID;
T targetID = (T)(object)(uint)TargetSpriteID;
if (!sequences.ContainsKey(baseID) || sequences.ContainsKey(targetID))
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private Dictionary<T, T> GetAliasPriority<T>()
where T : Enum
{
return AliasPriority?
.Select(kv => new KeyValuePair<T, T>((T)(object)(int)kv.Key, (T)(object)(int)kv.Value))
.Select(kv => new KeyValuePair<T, T>((T)(object)(uint)kv.Key, (T)(object)(uint)kv.Value))
.ToDictionary(kv => kv.Key, kv => kv.Value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ public override void ApplyToLevel(TR3Level level)
private IEnumerable<EMMeshTextureData> PrepareImportData<T>(SortedDictionary<T, TRModel> existingModels)
where T : Enum
{
return Data.Where(d => !existingModels.ContainsKey((T)(object)d.ModelID));
return Data.Where(d => !existingModels.ContainsKey((T)(object)(uint)d.ModelID));
}

private static void RemapFaces<T>(IEnumerable<EMMeshTextureData> data, int maximumTexture, SortedDictionary<T, TRModel> models)
where T : Enum
{
foreach (EMMeshTextureData textureData in data)
{
TRModel model = models[(T)(object)textureData.ModelID];
TRModel model = models[(T)(object)(uint)textureData.ModelID];
foreach (TRMesh mesh in model.Meshes)
{
foreach (TRMeshFace face in mesh.ColouredTriangles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,20 @@ namespace TREnvironmentEditor.Model;
public class EMCreateStaticMeshFunction : BaseEMFunction
{
public uint ID { get; set; }
public TRMesh Mesh { get; set; }
public TRStaticMesh Info { get; set; }

public override void ApplyToLevel(TR1Level level)
{
TRStaticMesh newMesh = Info.Clone();
newMesh.Mesh = Mesh;
level.StaticMeshes[(TR1Type)ID] = newMesh;
level.StaticMeshes[(TR1Type)ID] = Info.Clone();
}

public override void ApplyToLevel(TR2Level level)
{
TRStaticMesh newMesh = Info.Clone();
newMesh.Mesh = Mesh;
level.StaticMeshes[(TR2Type)ID] = newMesh;
level.StaticMeshes[(TR2Type)ID] = Info.Clone();
}

public override void ApplyToLevel(TR3Level level)
{
TRStaticMesh newMesh = Info.Clone();
newMesh.Mesh = Mesh;
level.StaticMeshes[(TR3Type)ID] = newMesh;
level.StaticMeshes[(TR3Type)ID] = Info.Clone();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,10 @@ public override void ApplyToLevel(TR3Level level)

private static void RemoveEntries<T>(List<T> items, List<int> indices)
{
List<T> itemList = items.ToList();

indices.Sort();
for (int i = indices.Count - 1; i >= 0; i--)
{
itemList.RemoveAt(indices[i]);
items.RemoveAt(indices[i]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private void AppendActions(TRRoomSector sector, FDControl floorData, List<FDActi
{
if (!trigger.Actions.Any(a => a.Action == item.Action && a.Parameter == item.Parameter))
{
trigger.Actions.Add(item);
trigger.Actions.Add(item.Clone());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private void AttachToSector(TRRoomSector sector, FDControl control, short camera
if (control[sector.FDIndex].Find(e => e is FDTriggerEntry) is FDTriggerEntry trigger
&& trigger.TrigType != FDTrigType.Dummy)
{
trigger.Actions.Add(new FDActionItem
trigger.Actions.Add(new()
{
Action = FDTrigAction.Camera,
CamAction = CameraAction,
Expand All @@ -181,7 +181,7 @@ private void AttachToSector(TRRoomSector sector, FDControl control, short camera

if (LookAtItem != ushort.MaxValue)
{
trigger.Actions.Add(new FDActionItem
trigger.Actions.Add(new()
{
Action = FDTrigAction.LookAtItem,
Parameter = data.ConvertEntity(LookAtItem)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private static void AppendTriggers(TRRoomSector sector, List<FDEntry> triggerEnt
List<FDEntry> entries = control[sector.FDIndex];
if (entries.FindIndex(e => e is FDTriggerEntry) == -1)
{
entries.AddRange(triggerEntries);
entries.AddRange(triggerEntries.Select(t => t.Clone()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private void CreateTrigger(TRRoomSector sector, FDControl control, FDTriggerEntr
}
if (entries.FindIndex(e => e is FDTriggerEntry) == -1)
{
entries.Add(triggerEntry);
entries.Add(triggerEntry.Clone());
}
}

Expand Down
1 change: 1 addition & 0 deletions TREnvironmentEditor/Parsing/EMSerializationResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class EMSerializationResolver : DefaultContractResolver
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
{
return base.CreateProperties(type, memberSerialization)
?.Where(p => !p.Ignored && p.Writable)
?.OrderBy(p => p.DeclaringType.BaseTypesAndSelf().Count()).ToList();
}
}
Expand Down
21 changes: 4 additions & 17 deletions TRLevelControl/Build/TRFDBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,39 +323,26 @@ private static List<ushort> Flatten(FDTriggerEntry trigger)
data.Add(switchRef);
}

for (int i = 0; i < trigger.Actions.Count; i++)
foreach (FDActionItem action in trigger.Actions)
{
FDActionItem action = trigger.Actions[i];
int actionValue = action.Parameter & 0x03FF;
actionValue |= ((byte)action.Action & 0x001F) << 10;

bool isCamera = action.CamAction != null
&& (action.Action == FDTrigAction.Camera || action.Action == FDTrigAction.Flyby);
if (i == trigger.Actions.Count - 1 && !isCamera)
{
actionValue |= 0x8000;
}

data.Add((ushort)actionValue);

if (isCamera)
if (action.CamAction != null
&& (action.Action == FDTrigAction.Camera || action.Action == FDTrigAction.Flyby))
{
int cameraValue = action.CamAction.Timer;
if (action.CamAction.Once)
{
cameraValue |= 0x0100;
}
cameraValue |= (action.CamAction.MoveTimer & 0x001F) << 9;

if (i == trigger.Actions.Count - 1)
{
cameraValue |= 0x8000;
}

data.Add((ushort)cameraValue);
}
}

data[^1] |= 0x8000;
return data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@
"Triangles": {
"75": [
{
"Type": 3,
"Vertices": [
287,
253,
Expand All @@ -625,6 +626,7 @@
"Texture": 100
},
{
"Type": 3,
"Vertices": [
256,
288,
Expand Down
Loading

0 comments on commit acce0b2

Please sign in to comment.