Skip to content

Commit a4ec063

Browse files
committed
Merge branch 'staging'
2 parents d2cb581 + a3f4cc5 commit a4ec063

File tree

13 files changed

+1059
-884
lines changed

13 files changed

+1059
-884
lines changed

CathodeLib/CathodeLib.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
<Authors>Matt Filer</Authors>
1111
<Description>Provides support for parsing and writing common Alien: Isolation formats from the Cathode engine.</Description>
1212
<Copyright>Matt Filer 2023</Copyright>
13-
<Version>0.3.2</Version>
13+
<Version>0.3.3</Version>
1414
<OutputType>Library</OutputType>
15-
<AssemblyVersion>0.3.2.0</AssemblyVersion>
16-
<FileVersion>0.3.2.0</FileVersion>
15+
<AssemblyVersion>0.3.3.0</AssemblyVersion>
16+
<FileVersion>0.3.3.0</FileVersion>
1717
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
1818
</PropertyGroup>
1919

CathodeLib/Scripts/CATHODE/Commands.cs

Lines changed: 566 additions & 579 deletions
Large diffs are not rendered by default.

CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Composite.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,29 @@ public Entity GetEntityByID(ShortGuid id)
4242
/* Returns a collection of all entities in the composite */
4343
public List<Entity> GetEntities()
4444
{
45-
List<Entity> toReturn = new List<Entity>();
45+
List<Entity> toReturn = new List<Entity>(variables.Count + functions.Count + overrides.Count + proxies.Count);
4646
toReturn.AddRange(variables);
4747
toReturn.AddRange(functions);
4848
toReturn.AddRange(overrides);
4949
toReturn.AddRange(proxies);
5050
return toReturn;
5151
}
5252

53-
/* Sort all entity arrays */
54-
public void SortEntities()
55-
{
56-
variables.OrderBy(o => o.shortGUID.ToUInt32());
57-
functions.OrderBy(o => o.shortGUID.ToUInt32());
58-
overrides.OrderBy(o => o.shortGUID.ToUInt32());
59-
proxies.OrderBy(o => o.shortGUID.ToUInt32());
60-
}
61-
6253
/* Add a new function entity */
6354
public FunctionEntity AddFunction(FunctionType function, bool autopopulateParameters = false)
6455
{
65-
FunctionEntity func = new FunctionEntity(function, autopopulateParameters);
66-
functions.Add(func);
67-
return func;
68-
}
69-
public FunctionEntity AddFunction(string function, bool autopopulateParameters = false)
70-
{
71-
FunctionEntity func = new FunctionEntity(function, autopopulateParameters);
56+
FunctionEntity func = null;
57+
switch (function) {
58+
case FunctionType.CAGEAnimation:
59+
func = new CAGEAnimation(autopopulateParameters);
60+
break;
61+
case FunctionType.TriggerSequence:
62+
func = new TriggerSequence(autopopulateParameters);
63+
break;
64+
default:
65+
func = new FunctionEntity(function, autopopulateParameters);
66+
break;
67+
}
7268
functions.Add(func);
7369
return func;
7470
}

CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Entity.cs

Lines changed: 64 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public Parameter GetParameter(string name)
5252
}
5353
public Parameter GetParameter(ShortGuid id)
5454
{
55-
return parameters.FirstOrDefault(o => o.shortGUID == id);
55+
return parameters.FirstOrDefault(o => o.name == id);
5656
}
5757

5858
/* Add a data-supplying parameter to the entity */
@@ -81,6 +81,48 @@ public Parameter AddParameter<T>(string name, T data, ParameterVariant variant =
8181
throw new Exception("Tried to AddParameter using templated function, but type is not supported.");
8282
}
8383
*/
84+
public Parameter AddParameter(string name, DataType type, ParameterVariant variant = ParameterVariant.PARAMETER)
85+
{
86+
return AddParameter(ShortGuidUtils.Generate(name), type, variant);
87+
}
88+
public Parameter AddParameter(ShortGuid id, DataType type, ParameterVariant variant = ParameterVariant.PARAMETER)
89+
{
90+
ParameterData data = null;
91+
switch (type)
92+
{
93+
case DataType.STRING:
94+
data = new cString();
95+
break;
96+
case DataType.FLOAT:
97+
data = new cFloat();
98+
break;
99+
case DataType.INTEGER:
100+
data = new cInteger();
101+
break;
102+
case DataType.BOOL:
103+
data = new cBool();
104+
break;
105+
case DataType.VECTOR:
106+
data = new cVector3();
107+
break;
108+
case DataType.TRANSFORM:
109+
data = new cTransform();
110+
break;
111+
case DataType.ENUM:
112+
data = new cEnum();
113+
break;
114+
case DataType.SPLINE:
115+
data = new cSpline();
116+
break;
117+
case DataType.RESOURCE:
118+
data = new cResource(shortGUID);
119+
break;
120+
default:
121+
Console.WriteLine("WARNING: Tried to add parameter of type which is currently unsupported by CathodeLib (" + type + ")");
122+
return null;
123+
}
124+
return AddParameter(id, data, variant);
125+
}
84126
public Parameter AddParameter(string name, ParameterData data, ParameterVariant variant = ParameterVariant.PARAMETER)
85127
{
86128
return AddParameter(ShortGuidUtils.Generate(name), data, variant);
@@ -107,7 +149,7 @@ public Parameter AddParameter(ShortGuid id, ParameterData data, ParameterVariant
107149
public void RemoveParameter(string name)
108150
{
109151
ShortGuid name_id = ShortGuidUtils.Generate(name);
110-
parameters.RemoveAll(o => o.shortGUID == name_id);
152+
parameters.RemoveAll(o => o.name == name_id);
111153
}
112154

113155
/* Add a link from a parameter on us out to a parameter on another entity */
@@ -131,69 +173,35 @@ namespace CATHODE.Scripting
131173
[Serializable]
132174
public class VariableEntity : Entity
133175
{
134-
public VariableEntity(bool addDefaultParam = false) : base(EntityVariant.DATATYPE) { if (addDefaultParam) AddDefaultParam(); }
135-
public VariableEntity(ShortGuid shortGUID, bool addDefaultParam = false) : base(shortGUID, EntityVariant.DATATYPE) { if (addDefaultParam) AddDefaultParam(); }
176+
public VariableEntity(bool addDefaultParam = false) : base(EntityVariant.VARIABLE) { if (addDefaultParam) AddParameter(name, type); }
177+
public VariableEntity(ShortGuid shortGUID, bool addDefaultParam = false) : base(shortGUID, EntityVariant.VARIABLE) { if (addDefaultParam) AddParameter(name, type); }
136178

137-
public VariableEntity(string parameter, DataType type, bool addDefaultParam = false) : base(EntityVariant.DATATYPE)
179+
public VariableEntity(string parameter, DataType type, bool addDefaultParam = false) : base(EntityVariant.VARIABLE)
138180
{
139-
this.parameter = ShortGuidUtils.Generate(parameter);
181+
this.name = ShortGuidUtils.Generate(parameter);
140182
this.type = type;
141-
if (addDefaultParam) AddDefaultParam();
183+
if (addDefaultParam) AddParameter(name, type);
142184
}
143185

144-
public VariableEntity(ShortGuid shortGUID, ShortGuid parameter, DataType type, bool addDefaultParam = false) : base(shortGUID, EntityVariant.DATATYPE)
186+
public VariableEntity(ShortGuid shortGUID, ShortGuid parameter, DataType type, bool addDefaultParam = false) : base(shortGUID, EntityVariant.VARIABLE)
145187
{
146-
this.parameter = parameter;
188+
this.name = parameter;
147189
this.type = type;
148-
if (addDefaultParam) AddDefaultParam();
190+
if (addDefaultParam) AddParameter(name, type);
149191
}
150-
public VariableEntity(ShortGuid shortGUID, string parameter, DataType type, bool addDefaultParam = false) : base(shortGUID, EntityVariant.DATATYPE)
192+
public VariableEntity(ShortGuid shortGUID, string parameter, DataType type, bool addDefaultParam = false) : base(shortGUID, EntityVariant.VARIABLE)
151193
{
152-
this.parameter = ShortGuidUtils.Generate(parameter);
194+
this.name = ShortGuidUtils.Generate(parameter);
153195
this.type = type;
154-
if (addDefaultParam) AddDefaultParam();
155-
}
156-
157-
/* Add a default parameter on us when created, to provide a value from */
158-
private void AddDefaultParam()
159-
{
160-
ParameterData thisParam = null;
161-
switch (type)
162-
{
163-
case DataType.STRING:
164-
thisParam = new cString("");
165-
break;
166-
case DataType.FLOAT:
167-
thisParam = new cFloat(0.0f);
168-
break;
169-
case DataType.INTEGER:
170-
thisParam = new cInteger(0);
171-
break;
172-
case DataType.BOOL:
173-
thisParam = new cBool(true);
174-
break;
175-
case DataType.VECTOR:
176-
thisParam = new cVector3(new Vector3(0, 0, 0));
177-
break;
178-
case DataType.TRANSFORM:
179-
thisParam = new cTransform(new Vector3(0, 0, 0), new Vector3(0, 0, 0));
180-
break;
181-
case DataType.ENUM:
182-
thisParam = new cEnum(EnumType.ALERTNESS_STATE, 0);
183-
break;
184-
case DataType.SPLINE:
185-
thisParam = new cSpline();
186-
break;
187-
}
188-
parameters.Add(new Parameter(parameter, thisParam));
196+
if (addDefaultParam) AddParameter(name, type);
189197
}
190198

191-
public ShortGuid parameter; //Translates to string via ShortGuidUtils.FindString
199+
public ShortGuid name;
192200
public DataType type = DataType.NONE;
193201

194202
public override string ToString()
195203
{
196-
return parameter.ToString();
204+
return name.ToString();
197205
}
198206
}
199207
[Serializable]
@@ -234,7 +242,7 @@ public FunctionEntity(ShortGuid shortGUID, FunctionType function, bool autoGener
234242
if (autoGenerateParameters) EntityUtils.ApplyDefaults(this);
235243
}
236244

237-
public ShortGuid function; //Translates to string via ShortGuidUtils.FindString
245+
public ShortGuid function;
238246
public List<ResourceReference> resources = new List<ResourceReference>(); //TODO: can we replace this with a cResource to save duplicating functionality?
239247

240248
/* Add a new resource reference of type */
@@ -291,15 +299,19 @@ public OverrideEntity(ShortGuid shortGUID) : base(shortGUID, EntityVariant.OVERR
291299
[Serializable]
292300
public class CAGEAnimation : FunctionEntity
293301
{
294-
public CAGEAnimation(ShortGuid id) : base(id) { function = ShortGuidUtils.Generate("CAGEAnimation"); }
302+
public CAGEAnimation(bool autoGenerateParameters = false) : base(FunctionType.CAGEAnimation, autoGenerateParameters) { }
303+
public CAGEAnimation(ShortGuid id, bool autoGenerateParameters = false) : base(id, FunctionType.CAGEAnimation, autoGenerateParameters) { }
304+
295305
public List<CathodeParameterKeyframeHeader> keyframeHeaders = new List<CathodeParameterKeyframeHeader>();
296306
public List<CathodeParameterKeyframe> keyframeData = new List<CathodeParameterKeyframe>();
297307
public List<TEMP_CAGEAnimationExtraDataHolder3> paramsData3 = new List<TEMP_CAGEAnimationExtraDataHolder3>(); //events?
298308
}
299309
[Serializable]
300310
public class TriggerSequence : FunctionEntity
301311
{
302-
public TriggerSequence(ShortGuid id) : base(id) { function = ShortGuidUtils.Generate("TriggerSequence"); }
312+
public TriggerSequence(bool autoGenerateParameters = false) : base(FunctionType.TriggerSequence, autoGenerateParameters) { }
313+
public TriggerSequence(ShortGuid id, bool autoGenerateParameters = false) : base(id, FunctionType.TriggerSequence, autoGenerateParameters) { }
314+
303315
public List<CathodeTriggerSequenceTrigger> triggers = new List<CathodeTriggerSequenceTrigger>();
304316
public List<CathodeTriggerSequenceEvent> events = new List<CathodeTriggerSequenceEvent>();
305317
}

CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Parameter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ public class Parameter
1111
{
1212
public Parameter(string name, ParameterData data, ParameterVariant var = ParameterVariant.PARAMETER)
1313
{
14-
shortGUID = ShortGuidUtils.Generate(name);
14+
this.name = ShortGuidUtils.Generate(name);
1515
content = data;
1616
variant = var;
1717
}
1818
public Parameter(ShortGuid id, ParameterData data, ParameterVariant var = ParameterVariant.PARAMETER)
1919
{
20-
shortGUID = id;
20+
name = id;
2121
content = data;
2222
variant = var;
2323
}
2424

25-
public ShortGuid shortGUID; //The ID of the param in the entity
25+
public ShortGuid name;
2626
public ParameterData content = null;
2727
public ParameterVariant variant = ParameterVariant.PARAMETER;
2828
}

CathodeLib/Scripts/CATHODE/CommandsPAK/Components/ParameterData.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public ParameterData(DataType type)
3737
case DataType.FLOAT:
3838
return ((cFloat)x).value == ((cFloat)y).value;
3939
case DataType.RESOURCE:
40-
return ((cResource)x).resourceID == ((cResource)y).resourceID;
40+
return ((cResource)x).shortGUID == ((cResource)y).shortGUID;
4141
case DataType.VECTOR:
4242
return ((cVector3)x).value == ((cVector3)y).value;
4343
case DataType.ENUM:
@@ -80,7 +80,7 @@ public override int GetHashCode()
8080
case DataType.FLOAT:
8181
return ((cFloat)this).value.GetHashCode();
8282
case DataType.RESOURCE:
83-
return ((cResource)this).resourceID.GetHashCode();
83+
return ((cResource)this).shortGUID.GetHashCode();
8484
case DataType.VECTOR:
8585
return ((cVector3)this).value.GetHashCode();
8686
case DataType.ENUM:
@@ -188,21 +188,25 @@ public cFloat(float value)
188188
[Serializable]
189189
public class cResource : ParameterData
190190
{
191-
public cResource() { dataType = DataType.RESOURCE; }
192-
public cResource(ShortGuid resourceID)
191+
public cResource()
193192
{
194-
this.resourceID = resourceID;
193+
this.shortGUID = ShortGuidUtils.GenerateRandom();
194+
dataType = DataType.RESOURCE;
195+
}
196+
public cResource(ShortGuid shortGuid)
197+
{
198+
this.shortGUID = shortGuid;
195199
dataType = DataType.RESOURCE;
196200
}
197201
public cResource(List<ResourceReference> value, ShortGuid resourceID)
198202
{
199203
this.value = value;
200-
this.resourceID = resourceID;
204+
this.shortGUID = resourceID;
201205
dataType = DataType.RESOURCE;
202206
}
203207

204208
public List<ResourceReference> value = new List<ResourceReference>();
205-
public ShortGuid resourceID; //TODO: this is only ever gonna be the parent of the resouce (node or entity) - should we just generate on compilation?
209+
public ShortGuid shortGUID;
206210

207211
/* Add a new resource reference of type */
208212
public ResourceReference AddResource(ResourceType type)
@@ -212,7 +216,7 @@ public ResourceReference AddResource(ResourceType type)
212216
if (rr == null)
213217
{
214218
rr = new ResourceReference(type);
215-
rr.resourceID = resourceID;
219+
rr.resourceID = shortGUID;
216220
switch (rr.entryType)
217221
{
218222
case ResourceType.DYNAMIC_PHYSICS_SYSTEM:

CathodeLib/Scripts/CATHODE/CommandsPAK/Components/TypeEnums.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace CATHODE.Scripting
77
/* Entity variants */
88
public enum EntityVariant
99
{
10-
DATATYPE,
10+
VARIABLE,
1111
FUNCTION,
1212

1313
PROXY,
@@ -41,11 +41,12 @@ public enum DataType
4141
VECTOR,
4242
TRANSFORM,
4343
ENUM,
44+
4445
SPLINE,
46+
RESOURCE,
4547

4648
NONE, //Translates to a blank string
4749

48-
RESOURCE,
4950
FILEPATH,
5051
OBJECT,
5152
ZONE_LINK_PTR,
@@ -1131,4 +1132,17 @@ public enum CompositeFileData
11311132

11321133
NUMBER_OF_SCRIPT_BLOCKS, //THIS IS NOT A DATA BLOCK: merely used as an easy way of sanity checking the number of blocks in-code!
11331134
}
1135+
1136+
/* Custom tables written at the end of the PAK to store extra info */
1137+
public enum CustomEndTables
1138+
{
1139+
//NOTE: NEVER remove options from here, or re-order them.
1140+
// Doing this will cause issues with backwards compatibility.
1141+
ENTITY_NAMES,
1142+
SHORT_GUIDS,
1143+
1144+
//Add new entries here
1145+
1146+
NUMBER_OF_END_TABLES, //USED FOR COUNTING ONLY
1147+
}
11341148
}

CathodeLib/Scripts/CATHODE/CommandsPAK/Helpers/CompositeUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static CompositeUtils()
1717
int compositeCount = reader.ReadInt32();
1818
pathLookup = new Dictionary<ShortGuid, string>(compositeCount);
1919
for (int i = 0; i < compositeCount; i++)
20-
pathLookup.Add(CathodeLib.Utilities.Consume<ShortGuid>(reader), reader.ReadString());
20+
pathLookup.Add(Utilities.Consume<ShortGuid>(reader), reader.ReadString());
2121
}
2222

2323
public static string GetFullPath(ShortGuid guid)

0 commit comments

Comments
 (0)