Skip to content

Commit d2cb581

Browse files
committed
Merge branch 'staging'
2 parents 585c268 + f2ffb0c commit d2cb581

File tree

9 files changed

+329
-303
lines changed

9 files changed

+329
-303
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.1</Version>
13+
<Version>0.3.2</Version>
1414
<OutputType>Library</OutputType>
15-
<AssemblyVersion>0.3.1.0</AssemblyVersion>
16-
<FileVersion>0.3.1.0</FileVersion>
15+
<AssemblyVersion>0.3.2.0</AssemblyVersion>
16+
<FileVersion>0.3.2.0</FileVersion>
1717
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
1818
</PropertyGroup>
1919

CathodeLib/Scripts/CATHODE/Commands.cs

Lines changed: 49 additions & 54 deletions
Large diffs are not rendered by default.

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using CATHODE.Scripting.Internal;
1+
using CATHODE.Scripting.Internal;
22
using System;
33
using System.Collections.Generic;
44
using System.Linq;
@@ -18,14 +18,11 @@ public Composite(string name)
1818
{
1919
shortGUID = ShortGuidUtils.GenerateRandom();
2020
this.name = name;
21-
unknownPair = new OffsetPair(5, 6); //TODO: what on earth this this?
2221
}
2322

2423
public ShortGuid shortGUID; //The id when this composite is used as an entity in another composite
2524
public string name = ""; //The string name of the composite
2625

27-
public OffsetPair unknownPair;
28-
2926
public List<VariableEntity> variables = new List<VariableEntity>(); //Variables which can be accessed outside of this flowgraph as parameters, and connected to nodes as parameters internally
3027
public List<FunctionEntity> functions = new List<FunctionEntity>(); //Functional nodes, including hard-coded functions and references to other composites
3128

@@ -75,9 +72,9 @@ public FunctionEntity AddFunction(string function, bool autopopulateParameters =
7572
functions.Add(func);
7673
return func;
7774
}
78-
public FunctionEntity AddFunction(Composite function, bool autopopulateParameters = false)
75+
public FunctionEntity AddFunction(Composite composite, bool autopopulateParameters = false)
7976
{
80-
FunctionEntity func = new FunctionEntity(function.shortGUID, autopopulateParameters);
77+
FunctionEntity func = new FunctionEntity(composite.shortGUID, autopopulateParameters);
8178
functions.Add(func);
8279
return func;
8380
}
@@ -89,5 +86,10 @@ public VariableEntity AddVariable(string parameter, DataType type, bool addDefau
8986
variables.Add(vari);
9087
return vari;
9188
}
89+
90+
public override string ToString()
91+
{
92+
return name;
93+
}
9294
}
9395
}

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,31 @@ public Parameter GetParameter(ShortGuid id)
5656
}
5757

5858
/* Add a data-supplying parameter to the entity */
59+
/*
60+
public Parameter AddParameter<T>(string name, T data, ParameterVariant variant = ParameterVariant.PARAMETER)
61+
{
62+
ShortGuid id = ShortGuidUtils.Generate(name);
63+
switch (Type.GetTypeCode(typeof(T)))
64+
{
65+
case TypeCode.String:
66+
return AddParameter(id, new cString((string)(object)data), variant);
67+
case TypeCode.Int16:
68+
case TypeCode.Int32:
69+
case TypeCode.Int64:
70+
case TypeCode.UInt16:
71+
case TypeCode.UInt32:
72+
case TypeCode.UInt64:
73+
return AddParameter(id, new cInteger((int)(object)data), variant);
74+
case TypeCode.Boolean:
75+
return AddParameter(id, new cBool((bool)(object)data), variant);
76+
case TypeCode.Double:
77+
return AddParameter(id, new cFloat((float)((double)(object)data)), variant);
78+
case TypeCode.Single:
79+
return AddParameter(id, new cFloat((float)(object)data), variant);
80+
}
81+
throw new Exception("Tried to AddParameter using templated function, but type is not supported.");
82+
}
83+
*/
5984
public Parameter AddParameter(string name, ParameterData data, ParameterVariant variant = ParameterVariant.PARAMETER)
6085
{
6186
return AddParameter(ShortGuidUtils.Generate(name), data, variant);
@@ -154,7 +179,7 @@ private void AddDefaultParam()
154179
thisParam = new cTransform(new Vector3(0, 0, 0), new Vector3(0, 0, 0));
155180
break;
156181
case DataType.ENUM:
157-
thisParam = new cEnum("ALERTNESS_STATE", 0); //ALERTNESS_STATE is the first alphabetically
182+
thisParam = new cEnum(EnumType.ALERTNESS_STATE, 0);
158183
break;
159184
case DataType.SPLINE:
160185
thisParam = new cSpline();
@@ -165,6 +190,11 @@ private void AddDefaultParam()
165190

166191
public ShortGuid parameter; //Translates to string via ShortGuidUtils.FindString
167192
public DataType type = DataType.NONE;
193+
194+
public override string ToString()
195+
{
196+
return parameter.ToString();
197+
}
168198
}
169199
[Serializable]
170200
public class FunctionEntity : Entity
@@ -234,6 +264,11 @@ public ResourceReference GetResource(ResourceType type)
234264
{
235265
return resources.FirstOrDefault(o => o.entryType == type);
236266
}
267+
268+
public override string ToString()
269+
{
270+
return function.ToString();
271+
}
237272
}
238273
[Serializable]
239274
public class ProxyEntity : Entity

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

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -70,43 +70,27 @@ public override int GetHashCode()
7070
{
7171
case DataType.TRANSFORM:
7272
cTransform x_t = (cTransform)this;
73-
return Convert.ToInt32(
74-
x_t.rotation.x.ToString() + x_t.rotation.y.ToString() + x_t.rotation.z.ToString() +
75-
x_t.position.x.ToString() + x_t.position.y.ToString() + x_t.position.z.ToString());
73+
return x_t.position.GetHashCode() + x_t.rotation.GetHashCode();
7674
case DataType.INTEGER:
77-
return ((cInteger)this).value;
75+
return ((cInteger)this).value.GetHashCode();
7876
case DataType.STRING:
79-
cString x_s = (cString)this;
80-
string num = "";
81-
for (int i = 0; i < x_s.value.Length; i++) num += ((int)x_s.value[i]).ToString();
82-
return Convert.ToInt32(num);
77+
return ((cString)this).value.GetHashCode();
8378
case DataType.BOOL:
84-
return ((cBool)this).value ? 1 : 0;
79+
return ((cBool)this).value.GetHashCode();
8580
case DataType.FLOAT:
86-
return Convert.ToInt32(((cFloat)this).value.ToString().Replace(".", ""));
81+
return ((cFloat)this).value.GetHashCode();
8782
case DataType.RESOURCE:
88-
string x_g_s = ((cString)this).value.ToString();
89-
string num2 = "";
90-
for (int i = 0; i < x_g_s.Length; i++) num2 += ((int)x_g_s[i]).ToString();
91-
return Convert.ToInt32(num2);
83+
return ((cResource)this).resourceID.GetHashCode();
9284
case DataType.VECTOR:
93-
cVector3 x_v = (cVector3)this;
94-
return Convert.ToInt32(x_v.value.x.ToString() + x_v.value.y.ToString() + x_v.value.z.ToString());
85+
return ((cVector3)this).value.GetHashCode();
9586
case DataType.ENUM:
9687
cEnum x_e = (cEnum)this;
97-
string x_e_s = x_e.enumID.ToString();
98-
string num3 = "";
99-
for (int i = 0; i < x_e_s.Length; i++) num3 += ((int)x_e_s[i]).ToString();
100-
return Convert.ToInt32(num3 + x_e.enumIndex.ToString());
88+
return x_e.enumID.ToByteString().GetHashCode() + x_e.enumIndex;
10189
case DataType.SPLINE:
10290
cSpline x_sd = (cSpline)this;
103-
string x_sd_s = "";
104-
for (int i = 0; i < x_sd.splinePoints.Count; i++) x_sd_s += x_sd.splinePoints[i].position.GetHashCode().ToString();
105-
ShortGuid x_sd_g = ShortGuidUtils.Generate(x_sd_s);
106-
string x_sd_g_s = x_sd_g.ToString();
107-
string num4 = "";
108-
for (int i = 0; i < x_sd_g_s.Length; i++) num4 += ((int)x_sd_g_s[i]).ToString();
109-
return Convert.ToInt32(num4);
91+
int x_sd_i = 0;
92+
for (int i = 0; i < x_sd.splinePoints.Count; i++) x_sd_i += x_sd.splinePoints[i].GetHashCode();
93+
return x_sd_i;
11094
default:
11195
return -1;
11296
}
@@ -263,15 +247,21 @@ public cVector3(Vector3 value)
263247
[Serializable]
264248
public class cEnum : ParameterData
265249
{
266-
public cEnum(ShortGuid enumID, int enumIndex)
250+
public cEnum()
251+
{
252+
this.enumID = ShortGuidUtils.Generate(((EnumType)0).ToString());
253+
this.enumIndex = 0;
254+
dataType = DataType.ENUM;
255+
}
256+
public cEnum(ShortGuid enumID, int enumIndex) //todo: deprecate?
267257
{
268258
this.enumID = enumID;
269259
this.enumIndex = enumIndex;
270260
dataType = DataType.ENUM;
271261
}
272-
public cEnum(string enumName = "ALERTNESS_STATE", int enumIndex = 0)
262+
public cEnum(EnumType enumType, int enumIndex = 0)
273263
{
274-
this.enumID = ShortGuidUtils.Generate(enumName);
264+
this.enumID = ShortGuidUtils.Generate(enumType.ToString());
275265
this.enumIndex = enumIndex;
276266
dataType = DataType.ENUM;
277267
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ public override bool Equals(object obj)
5858
}
5959
public static bool operator ==(ShortGuid x, string y)
6060
{
61-
return x.ToString() == y;
61+
return x.ToByteString() == y;
6262
}
6363
public static bool operator !=(ShortGuid x, string y)
6464
{
65-
return x.ToString() != y;
65+
return x.ToByteString() != y;
6666
}
6767
public override int GetHashCode()
6868
{
@@ -87,6 +87,10 @@ public int CompareTo(ShortGuid x)
8787
}
8888

8989
public override string ToString()
90+
{
91+
return ShortGuidUtils.FindString(this);
92+
}
93+
public string ToByteString()
9094
{
9195
return BitConverter.ToString(val);
9296
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,9 +1110,11 @@ public enum EnumType
11101110
WEAPON_PROPERTY,
11111111
WEAPON_TYPE,
11121112
}
1113-
1113+
}
1114+
namespace CATHODE.Scripting.Internal
1115+
{
11141116
/* Blocks of data in each compiled composite */
1115-
public enum DataBlock
1117+
public enum CompositeFileData
11161118
{
11171119
COMPOSITE_HEADER, //Defines the header of the composite, with global ID and string name
11181120
ENTITY_CONNECTIONS, //Defines the links between entities in the composite
@@ -1125,9 +1127,7 @@ public enum DataBlock
11251127
RESOURCE_REFERENCES, //Defines renderable data which is referenced by entities in this composite
11261128
CAGEANIMATION_DATA, //Appears to define additional data for CAGEAnimation type entities (TODO)
11271129
TRIGGERSEQUENCE_DATA, //Appears to define additional data for TriggerSequence type entities (TODO)
1128-
11291130
UNUSED, //Unused values
1130-
UNKNOWN_COUNTS, //TODO - unused?
11311131

11321132
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!
11331133
}

0 commit comments

Comments
 (0)