Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
MattFiler committed Jan 3, 2023
2 parents 585c268 + f2ffb0c commit d2cb581
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 303 deletions.
6 changes: 3 additions & 3 deletions CathodeLib/CathodeLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
<Authors>Matt Filer</Authors>
<Description>Provides support for parsing and writing common Alien: Isolation formats from the Cathode engine.</Description>
<Copyright>Matt Filer 2023</Copyright>
<Version>0.3.1</Version>
<Version>0.3.2</Version>
<OutputType>Library</OutputType>
<AssemblyVersion>0.3.1.0</AssemblyVersion>
<FileVersion>0.3.1.0</FileVersion>
<AssemblyVersion>0.3.2.0</AssemblyVersion>
<FileVersion>0.3.2.0</FileVersion>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
</PropertyGroup>

Expand Down
103 changes: 49 additions & 54 deletions CathodeLib/Scripts/CATHODE/Commands.cs

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Composite.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CATHODE.Scripting.Internal;
using CATHODE.Scripting.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -18,14 +18,11 @@ public Composite(string name)
{
shortGUID = ShortGuidUtils.GenerateRandom();
this.name = name;
unknownPair = new OffsetPair(5, 6); //TODO: what on earth this this?
}

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

public OffsetPair unknownPair;

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
public List<FunctionEntity> functions = new List<FunctionEntity>(); //Functional nodes, including hard-coded functions and references to other composites

Expand Down Expand Up @@ -75,9 +72,9 @@ public FunctionEntity AddFunction(string function, bool autopopulateParameters =
functions.Add(func);
return func;
}
public FunctionEntity AddFunction(Composite function, bool autopopulateParameters = false)
public FunctionEntity AddFunction(Composite composite, bool autopopulateParameters = false)
{
FunctionEntity func = new FunctionEntity(function.shortGUID, autopopulateParameters);
FunctionEntity func = new FunctionEntity(composite.shortGUID, autopopulateParameters);
functions.Add(func);
return func;
}
Expand All @@ -89,5 +86,10 @@ public VariableEntity AddVariable(string parameter, DataType type, bool addDefau
variables.Add(vari);
return vari;
}

public override string ToString()
{
return name;
}
}
}
37 changes: 36 additions & 1 deletion CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,31 @@ public Parameter GetParameter(ShortGuid id)
}

/* Add a data-supplying parameter to the entity */
/*
public Parameter AddParameter<T>(string name, T data, ParameterVariant variant = ParameterVariant.PARAMETER)
{
ShortGuid id = ShortGuidUtils.Generate(name);
switch (Type.GetTypeCode(typeof(T)))
{
case TypeCode.String:
return AddParameter(id, new cString((string)(object)data), variant);
case TypeCode.Int16:
case TypeCode.Int32:
case TypeCode.Int64:
case TypeCode.UInt16:
case TypeCode.UInt32:
case TypeCode.UInt64:
return AddParameter(id, new cInteger((int)(object)data), variant);
case TypeCode.Boolean:
return AddParameter(id, new cBool((bool)(object)data), variant);
case TypeCode.Double:
return AddParameter(id, new cFloat((float)((double)(object)data)), variant);
case TypeCode.Single:
return AddParameter(id, new cFloat((float)(object)data), variant);
}
throw new Exception("Tried to AddParameter using templated function, but type is not supported.");
}
*/
public Parameter AddParameter(string name, ParameterData data, ParameterVariant variant = ParameterVariant.PARAMETER)
{
return AddParameter(ShortGuidUtils.Generate(name), data, variant);
Expand Down Expand Up @@ -154,7 +179,7 @@ private void AddDefaultParam()
thisParam = new cTransform(new Vector3(0, 0, 0), new Vector3(0, 0, 0));
break;
case DataType.ENUM:
thisParam = new cEnum("ALERTNESS_STATE", 0); //ALERTNESS_STATE is the first alphabetically
thisParam = new cEnum(EnumType.ALERTNESS_STATE, 0);
break;
case DataType.SPLINE:
thisParam = new cSpline();
Expand All @@ -165,6 +190,11 @@ private void AddDefaultParam()

public ShortGuid parameter; //Translates to string via ShortGuidUtils.FindString
public DataType type = DataType.NONE;

public override string ToString()
{
return parameter.ToString();
}
}
[Serializable]
public class FunctionEntity : Entity
Expand Down Expand Up @@ -234,6 +264,11 @@ public ResourceReference GetResource(ResourceType type)
{
return resources.FirstOrDefault(o => o.entryType == type);
}

public override string ToString()
{
return function.ToString();
}
}
[Serializable]
public class ProxyEntity : Entity
Expand Down
50 changes: 20 additions & 30 deletions CathodeLib/Scripts/CATHODE/CommandsPAK/Components/ParameterData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,43 +70,27 @@ public override int GetHashCode()
{
case DataType.TRANSFORM:
cTransform x_t = (cTransform)this;
return Convert.ToInt32(
x_t.rotation.x.ToString() + x_t.rotation.y.ToString() + x_t.rotation.z.ToString() +
x_t.position.x.ToString() + x_t.position.y.ToString() + x_t.position.z.ToString());
return x_t.position.GetHashCode() + x_t.rotation.GetHashCode();
case DataType.INTEGER:
return ((cInteger)this).value;
return ((cInteger)this).value.GetHashCode();
case DataType.STRING:
cString x_s = (cString)this;
string num = "";
for (int i = 0; i < x_s.value.Length; i++) num += ((int)x_s.value[i]).ToString();
return Convert.ToInt32(num);
return ((cString)this).value.GetHashCode();
case DataType.BOOL:
return ((cBool)this).value ? 1 : 0;
return ((cBool)this).value.GetHashCode();
case DataType.FLOAT:
return Convert.ToInt32(((cFloat)this).value.ToString().Replace(".", ""));
return ((cFloat)this).value.GetHashCode();
case DataType.RESOURCE:
string x_g_s = ((cString)this).value.ToString();
string num2 = "";
for (int i = 0; i < x_g_s.Length; i++) num2 += ((int)x_g_s[i]).ToString();
return Convert.ToInt32(num2);
return ((cResource)this).resourceID.GetHashCode();
case DataType.VECTOR:
cVector3 x_v = (cVector3)this;
return Convert.ToInt32(x_v.value.x.ToString() + x_v.value.y.ToString() + x_v.value.z.ToString());
return ((cVector3)this).value.GetHashCode();
case DataType.ENUM:
cEnum x_e = (cEnum)this;
string x_e_s = x_e.enumID.ToString();
string num3 = "";
for (int i = 0; i < x_e_s.Length; i++) num3 += ((int)x_e_s[i]).ToString();
return Convert.ToInt32(num3 + x_e.enumIndex.ToString());
return x_e.enumID.ToByteString().GetHashCode() + x_e.enumIndex;
case DataType.SPLINE:
cSpline x_sd = (cSpline)this;
string x_sd_s = "";
for (int i = 0; i < x_sd.splinePoints.Count; i++) x_sd_s += x_sd.splinePoints[i].position.GetHashCode().ToString();
ShortGuid x_sd_g = ShortGuidUtils.Generate(x_sd_s);
string x_sd_g_s = x_sd_g.ToString();
string num4 = "";
for (int i = 0; i < x_sd_g_s.Length; i++) num4 += ((int)x_sd_g_s[i]).ToString();
return Convert.ToInt32(num4);
int x_sd_i = 0;
for (int i = 0; i < x_sd.splinePoints.Count; i++) x_sd_i += x_sd.splinePoints[i].GetHashCode();
return x_sd_i;
default:
return -1;
}
Expand Down Expand Up @@ -263,15 +247,21 @@ public cVector3(Vector3 value)
[Serializable]
public class cEnum : ParameterData
{
public cEnum(ShortGuid enumID, int enumIndex)
public cEnum()
{
this.enumID = ShortGuidUtils.Generate(((EnumType)0).ToString());
this.enumIndex = 0;
dataType = DataType.ENUM;
}
public cEnum(ShortGuid enumID, int enumIndex) //todo: deprecate?
{
this.enumID = enumID;
this.enumIndex = enumIndex;
dataType = DataType.ENUM;
}
public cEnum(string enumName = "ALERTNESS_STATE", int enumIndex = 0)
public cEnum(EnumType enumType, int enumIndex = 0)
{
this.enumID = ShortGuidUtils.Generate(enumName);
this.enumID = ShortGuidUtils.Generate(enumType.ToString());
this.enumIndex = enumIndex;
dataType = DataType.ENUM;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public override bool Equals(object obj)
}
public static bool operator ==(ShortGuid x, string y)
{
return x.ToString() == y;
return x.ToByteString() == y;
}
public static bool operator !=(ShortGuid x, string y)
{
return x.ToString() != y;
return x.ToByteString() != y;
}
public override int GetHashCode()
{
Expand All @@ -87,6 +87,10 @@ public int CompareTo(ShortGuid x)
}

public override string ToString()
{
return ShortGuidUtils.FindString(this);
}
public string ToByteString()
{
return BitConverter.ToString(val);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1110,9 +1110,11 @@ public enum EnumType
WEAPON_PROPERTY,
WEAPON_TYPE,
}

}
namespace CATHODE.Scripting.Internal
{
/* Blocks of data in each compiled composite */
public enum DataBlock
public enum CompositeFileData
{
COMPOSITE_HEADER, //Defines the header of the composite, with global ID and string name
ENTITY_CONNECTIONS, //Defines the links between entities in the composite
Expand All @@ -1125,9 +1127,7 @@ public enum DataBlock
RESOURCE_REFERENCES, //Defines renderable data which is referenced by entities in this composite
CAGEANIMATION_DATA, //Appears to define additional data for CAGEAnimation type entities (TODO)
TRIGGERSEQUENCE_DATA, //Appears to define additional data for TriggerSequence type entities (TODO)

UNUSED, //Unused values
UNKNOWN_COUNTS, //TODO - unused?

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!
}
Expand Down
Loading

0 comments on commit d2cb581

Please sign in to comment.