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 8, 2023
2 parents d2cb581 + a3f4cc5 commit a4ec063
Show file tree
Hide file tree
Showing 13 changed files with 1,059 additions and 884 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.2</Version>
<Version>0.3.3</Version>
<OutputType>Library</OutputType>
<AssemblyVersion>0.3.2.0</AssemblyVersion>
<FileVersion>0.3.2.0</FileVersion>
<AssemblyVersion>0.3.3.0</AssemblyVersion>
<FileVersion>0.3.3.0</FileVersion>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
</PropertyGroup>

Expand Down
1,145 changes: 566 additions & 579 deletions CathodeLib/Scripts/CATHODE/Commands.cs

Large diffs are not rendered by default.

30 changes: 13 additions & 17 deletions CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Composite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,29 @@ public Entity GetEntityByID(ShortGuid id)
/* Returns a collection of all entities in the composite */
public List<Entity> GetEntities()
{
List<Entity> toReturn = new List<Entity>();
List<Entity> toReturn = new List<Entity>(variables.Count + functions.Count + overrides.Count + proxies.Count);
toReturn.AddRange(variables);
toReturn.AddRange(functions);
toReturn.AddRange(overrides);
toReturn.AddRange(proxies);
return toReturn;
}

/* Sort all entity arrays */
public void SortEntities()
{
variables.OrderBy(o => o.shortGUID.ToUInt32());
functions.OrderBy(o => o.shortGUID.ToUInt32());
overrides.OrderBy(o => o.shortGUID.ToUInt32());
proxies.OrderBy(o => o.shortGUID.ToUInt32());
}

/* Add a new function entity */
public FunctionEntity AddFunction(FunctionType function, bool autopopulateParameters = false)
{
FunctionEntity func = new FunctionEntity(function, autopopulateParameters);
functions.Add(func);
return func;
}
public FunctionEntity AddFunction(string function, bool autopopulateParameters = false)
{
FunctionEntity func = new FunctionEntity(function, autopopulateParameters);
FunctionEntity func = null;
switch (function) {
case FunctionType.CAGEAnimation:
func = new CAGEAnimation(autopopulateParameters);
break;
case FunctionType.TriggerSequence:
func = new TriggerSequence(autopopulateParameters);
break;
default:
func = new FunctionEntity(function, autopopulateParameters);
break;
}
functions.Add(func);
return func;
}
Expand Down
116 changes: 64 additions & 52 deletions CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Parameter GetParameter(string name)
}
public Parameter GetParameter(ShortGuid id)
{
return parameters.FirstOrDefault(o => o.shortGUID == id);
return parameters.FirstOrDefault(o => o.name == id);
}

/* Add a data-supplying parameter to the entity */
Expand Down Expand Up @@ -81,6 +81,48 @@ public Parameter AddParameter<T>(string name, T data, ParameterVariant variant =
throw new Exception("Tried to AddParameter using templated function, but type is not supported.");
}
*/
public Parameter AddParameter(string name, DataType type, ParameterVariant variant = ParameterVariant.PARAMETER)
{
return AddParameter(ShortGuidUtils.Generate(name), type, variant);
}
public Parameter AddParameter(ShortGuid id, DataType type, ParameterVariant variant = ParameterVariant.PARAMETER)
{
ParameterData data = null;
switch (type)
{
case DataType.STRING:
data = new cString();
break;
case DataType.FLOAT:
data = new cFloat();
break;
case DataType.INTEGER:
data = new cInteger();
break;
case DataType.BOOL:
data = new cBool();
break;
case DataType.VECTOR:
data = new cVector3();
break;
case DataType.TRANSFORM:
data = new cTransform();
break;
case DataType.ENUM:
data = new cEnum();
break;
case DataType.SPLINE:
data = new cSpline();
break;
case DataType.RESOURCE:
data = new cResource(shortGUID);
break;
default:
Console.WriteLine("WARNING: Tried to add parameter of type which is currently unsupported by CathodeLib (" + type + ")");
return null;
}
return AddParameter(id, data, variant);
}
public Parameter AddParameter(string name, ParameterData data, ParameterVariant variant = ParameterVariant.PARAMETER)
{
return AddParameter(ShortGuidUtils.Generate(name), data, variant);
Expand All @@ -107,7 +149,7 @@ public Parameter AddParameter(ShortGuid id, ParameterData data, ParameterVariant
public void RemoveParameter(string name)
{
ShortGuid name_id = ShortGuidUtils.Generate(name);
parameters.RemoveAll(o => o.shortGUID == name_id);
parameters.RemoveAll(o => o.name == name_id);
}

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

public VariableEntity(string parameter, DataType type, bool addDefaultParam = false) : base(EntityVariant.DATATYPE)
public VariableEntity(string parameter, DataType type, bool addDefaultParam = false) : base(EntityVariant.VARIABLE)
{
this.parameter = ShortGuidUtils.Generate(parameter);
this.name = ShortGuidUtils.Generate(parameter);
this.type = type;
if (addDefaultParam) AddDefaultParam();
if (addDefaultParam) AddParameter(name, type);
}

public VariableEntity(ShortGuid shortGUID, ShortGuid parameter, DataType type, bool addDefaultParam = false) : base(shortGUID, EntityVariant.DATATYPE)
public VariableEntity(ShortGuid shortGUID, ShortGuid parameter, DataType type, bool addDefaultParam = false) : base(shortGUID, EntityVariant.VARIABLE)
{
this.parameter = parameter;
this.name = parameter;
this.type = type;
if (addDefaultParam) AddDefaultParam();
if (addDefaultParam) AddParameter(name, type);
}
public VariableEntity(ShortGuid shortGUID, string parameter, DataType type, bool addDefaultParam = false) : base(shortGUID, EntityVariant.DATATYPE)
public VariableEntity(ShortGuid shortGUID, string parameter, DataType type, bool addDefaultParam = false) : base(shortGUID, EntityVariant.VARIABLE)
{
this.parameter = ShortGuidUtils.Generate(parameter);
this.name = ShortGuidUtils.Generate(parameter);
this.type = type;
if (addDefaultParam) AddDefaultParam();
}

/* Add a default parameter on us when created, to provide a value from */
private void AddDefaultParam()
{
ParameterData thisParam = null;
switch (type)
{
case DataType.STRING:
thisParam = new cString("");
break;
case DataType.FLOAT:
thisParam = new cFloat(0.0f);
break;
case DataType.INTEGER:
thisParam = new cInteger(0);
break;
case DataType.BOOL:
thisParam = new cBool(true);
break;
case DataType.VECTOR:
thisParam = new cVector3(new Vector3(0, 0, 0));
break;
case DataType.TRANSFORM:
thisParam = new cTransform(new Vector3(0, 0, 0), new Vector3(0, 0, 0));
break;
case DataType.ENUM:
thisParam = new cEnum(EnumType.ALERTNESS_STATE, 0);
break;
case DataType.SPLINE:
thisParam = new cSpline();
break;
}
parameters.Add(new Parameter(parameter, thisParam));
if (addDefaultParam) AddParameter(name, type);
}

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

public override string ToString()
{
return parameter.ToString();
return name.ToString();
}
}
[Serializable]
Expand Down Expand Up @@ -234,7 +242,7 @@ public FunctionEntity(ShortGuid shortGUID, FunctionType function, bool autoGener
if (autoGenerateParameters) EntityUtils.ApplyDefaults(this);
}

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

/* Add a new resource reference of type */
Expand Down Expand Up @@ -291,15 +299,19 @@ public OverrideEntity(ShortGuid shortGUID) : base(shortGUID, EntityVariant.OVERR
[Serializable]
public class CAGEAnimation : FunctionEntity
{
public CAGEAnimation(ShortGuid id) : base(id) { function = ShortGuidUtils.Generate("CAGEAnimation"); }
public CAGEAnimation(bool autoGenerateParameters = false) : base(FunctionType.CAGEAnimation, autoGenerateParameters) { }
public CAGEAnimation(ShortGuid id, bool autoGenerateParameters = false) : base(id, FunctionType.CAGEAnimation, autoGenerateParameters) { }

public List<CathodeParameterKeyframeHeader> keyframeHeaders = new List<CathodeParameterKeyframeHeader>();
public List<CathodeParameterKeyframe> keyframeData = new List<CathodeParameterKeyframe>();
public List<TEMP_CAGEAnimationExtraDataHolder3> paramsData3 = new List<TEMP_CAGEAnimationExtraDataHolder3>(); //events?
}
[Serializable]
public class TriggerSequence : FunctionEntity
{
public TriggerSequence(ShortGuid id) : base(id) { function = ShortGuidUtils.Generate("TriggerSequence"); }
public TriggerSequence(bool autoGenerateParameters = false) : base(FunctionType.TriggerSequence, autoGenerateParameters) { }
public TriggerSequence(ShortGuid id, bool autoGenerateParameters = false) : base(id, FunctionType.TriggerSequence, autoGenerateParameters) { }

public List<CathodeTriggerSequenceTrigger> triggers = new List<CathodeTriggerSequenceTrigger>();
public List<CathodeTriggerSequenceEvent> events = new List<CathodeTriggerSequenceEvent>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ public class Parameter
{
public Parameter(string name, ParameterData data, ParameterVariant var = ParameterVariant.PARAMETER)
{
shortGUID = ShortGuidUtils.Generate(name);
this.name = ShortGuidUtils.Generate(name);
content = data;
variant = var;
}
public Parameter(ShortGuid id, ParameterData data, ParameterVariant var = ParameterVariant.PARAMETER)
{
shortGUID = id;
name = id;
content = data;
variant = var;
}

public ShortGuid shortGUID; //The ID of the param in the entity
public ShortGuid name;
public ParameterData content = null;
public ParameterVariant variant = ParameterVariant.PARAMETER;
}
Expand Down
20 changes: 12 additions & 8 deletions CathodeLib/Scripts/CATHODE/CommandsPAK/Components/ParameterData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ParameterData(DataType type)
case DataType.FLOAT:
return ((cFloat)x).value == ((cFloat)y).value;
case DataType.RESOURCE:
return ((cResource)x).resourceID == ((cResource)y).resourceID;
return ((cResource)x).shortGUID == ((cResource)y).shortGUID;
case DataType.VECTOR:
return ((cVector3)x).value == ((cVector3)y).value;
case DataType.ENUM:
Expand Down Expand Up @@ -80,7 +80,7 @@ public override int GetHashCode()
case DataType.FLOAT:
return ((cFloat)this).value.GetHashCode();
case DataType.RESOURCE:
return ((cResource)this).resourceID.GetHashCode();
return ((cResource)this).shortGUID.GetHashCode();
case DataType.VECTOR:
return ((cVector3)this).value.GetHashCode();
case DataType.ENUM:
Expand Down Expand Up @@ -188,21 +188,25 @@ public cFloat(float value)
[Serializable]
public class cResource : ParameterData
{
public cResource() { dataType = DataType.RESOURCE; }
public cResource(ShortGuid resourceID)
public cResource()
{
this.resourceID = resourceID;
this.shortGUID = ShortGuidUtils.GenerateRandom();
dataType = DataType.RESOURCE;
}
public cResource(ShortGuid shortGuid)
{
this.shortGUID = shortGuid;
dataType = DataType.RESOURCE;
}
public cResource(List<ResourceReference> value, ShortGuid resourceID)
{
this.value = value;
this.resourceID = resourceID;
this.shortGUID = resourceID;
dataType = DataType.RESOURCE;
}

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

/* Add a new resource reference of type */
public ResourceReference AddResource(ResourceType type)
Expand All @@ -212,7 +216,7 @@ public ResourceReference AddResource(ResourceType type)
if (rr == null)
{
rr = new ResourceReference(type);
rr.resourceID = resourceID;
rr.resourceID = shortGUID;
switch (rr.entryType)
{
case ResourceType.DYNAMIC_PHYSICS_SYSTEM:
Expand Down
18 changes: 16 additions & 2 deletions CathodeLib/Scripts/CATHODE/CommandsPAK/Components/TypeEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace CATHODE.Scripting
/* Entity variants */
public enum EntityVariant
{
DATATYPE,
VARIABLE,
FUNCTION,

PROXY,
Expand Down Expand Up @@ -41,11 +41,12 @@ public enum DataType
VECTOR,
TRANSFORM,
ENUM,

SPLINE,
RESOURCE,

NONE, //Translates to a blank string

RESOURCE,
FILEPATH,
OBJECT,
ZONE_LINK_PTR,
Expand Down Expand Up @@ -1131,4 +1132,17 @@ public enum CompositeFileData

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

/* Custom tables written at the end of the PAK to store extra info */
public enum CustomEndTables
{
//NOTE: NEVER remove options from here, or re-order them.
// Doing this will cause issues with backwards compatibility.
ENTITY_NAMES,
SHORT_GUIDS,

//Add new entries here

NUMBER_OF_END_TABLES, //USED FOR COUNTING ONLY
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static CompositeUtils()
int compositeCount = reader.ReadInt32();
pathLookup = new Dictionary<ShortGuid, string>(compositeCount);
for (int i = 0; i < compositeCount; i++)
pathLookup.Add(CathodeLib.Utilities.Consume<ShortGuid>(reader), reader.ReadString());
pathLookup.Add(Utilities.Consume<ShortGuid>(reader), reader.ReadString());
}

public static string GetFullPath(ShortGuid guid)
Expand Down
Loading

0 comments on commit a4ec063

Please sign in to comment.