11using CATHODE . Scripting . Internal ;
2+ #if DEBUG
3+ using Newtonsoft . Json . Converters ;
4+ using Newtonsoft . Json ;
5+ #endif
26using System ;
37using System . Collections . Generic ;
8+ using System . Data ;
49using System . Linq ;
510using System . Runtime . InteropServices ;
11+ #if UNITY_EDITOR || UNITY_STANDALONE_WIN
12+ using UnityEngine ;
13+ #else
14+ using System . Numerics ;
15+ #endif
616
717namespace CATHODE . Scripting . Internal
818{
@@ -22,6 +32,9 @@ public Entity(ShortGuid shortGUID, EntityVariant variant)
2232 }
2333
2434 public ShortGuid shortGUID ; //Translates to string via EntityNameLookup.GetEntityName
35+ #if DEBUG
36+ [ JsonConverter ( typeof ( StringEnumConverter ) ) ]
37+ #endif
2538 public EntityVariant variant ;
2639
2740 public List < EntityLink > childLinks = new List < EntityLink > ( ) ;
@@ -190,6 +203,9 @@ public VariableEntity(ShortGuid shortGUID, string parameter, DataType type, bool
190203 }
191204
192205 public ShortGuid name ;
206+ #if DEBUG
207+ [ JsonConverter ( typeof ( StringEnumConverter ) ) ]
208+ #endif
193209 public DataType type = DataType . NONE ;
194210
195211 public override string ToString ( )
@@ -280,31 +296,19 @@ public ProxyEntity(ShortGuid shortGUID) : base(shortGUID, EntityVariant.PROXY) {
280296 public ProxyEntity ( List < ShortGuid > hierarchy = null , ShortGuid targetType = new ShortGuid ( ) , bool autoGenerateParameters = false ) : base ( EntityVariant . PROXY )
281297 {
282298 this . targetType = targetType ;
283- if ( hierarchy != null ) this . hierarchy = hierarchy ;
284- if ( autoGenerateParameters ) ApplyDefaults ( ) ;
299+ if ( hierarchy != null ) this . connectedEntity . hierarchy = hierarchy ;
300+ if ( autoGenerateParameters ) EntityUtils . ApplyDefaults ( this ) ;
285301 }
286302 public ProxyEntity ( ShortGuid shortGUID , List < ShortGuid > hierarchy = null , ShortGuid targetType = new ShortGuid ( ) , bool autoGenerateParameters = false ) : base ( shortGUID , EntityVariant . PROXY )
287303 {
288304 this . shortGUID = shortGUID ;
289305 this . targetType = targetType ;
290- if ( hierarchy != null ) this . hierarchy = hierarchy ;
291- if ( autoGenerateParameters ) ApplyDefaults ( ) ;
306+ if ( hierarchy != null ) this . connectedEntity . hierarchy = hierarchy ;
307+ if ( autoGenerateParameters ) EntityUtils . ApplyDefaults ( this ) ;
292308 }
293309
294310 public ShortGuid targetType ; //The "function" value on the entity we're pointing to
295- public List < ShortGuid > hierarchy = new List < ShortGuid > ( ) ;
296-
297- private void ApplyDefaults ( )
298- {
299- AddParameter ( "proxy_filter_targets" , new cBool ( false ) ) ;
300- AddParameter ( "proxy_enable_on_reset" , new cBool ( false ) ) ;
301- AddParameter ( "proxy_enable" , new cFloat ( 0.0f ) ) ;
302- AddParameter ( "proxy_enabled" , new cFloat ( 0.0f ) ) ;
303- AddParameter ( "proxy_disable" , new cFloat ( 0.0f ) ) ;
304- AddParameter ( "proxy_disabled" , new cFloat ( 0.0f ) ) ;
305- AddParameter ( "reference" , new cString ( "" ) ) ;
306- AddParameter ( "trigger" , new cFloat ( 0.0f ) ) ;
307- }
311+ public EntityHierarchy connectedEntity = new EntityHierarchy ( ) ;
308312 }
309313 [ Serializable ]
310314 public class OverrideEntity : Entity
@@ -315,17 +319,17 @@ public OverrideEntity(ShortGuid shortGUID) : base(shortGUID, EntityVariant.OVERR
315319 public OverrideEntity ( List < ShortGuid > hierarchy = null ) : base ( EntityVariant . OVERRIDE )
316320 {
317321 checksum = ShortGuidUtils . GenerateRandom ( ) ;
318- if ( hierarchy != null ) this . hierarchy = hierarchy ;
322+ if ( hierarchy != null ) this . connectedEntity . hierarchy = hierarchy ;
319323 }
320324 public OverrideEntity ( ShortGuid shortGUID , List < ShortGuid > hierarchy = null ) : base ( shortGUID , EntityVariant . OVERRIDE )
321325 {
322326 this . shortGUID = shortGUID ;
323327 checksum = ShortGuidUtils . GenerateRandom ( ) ;
324- if ( hierarchy != null ) this . hierarchy = hierarchy ;
328+ if ( hierarchy != null ) this . connectedEntity . hierarchy = hierarchy ;
325329 }
326330
327331 public ShortGuid checksum ; //TODO: This value is apparently a hash of the hierarchy GUIDs, but need to verify that, and work out the salt.
328- public List < ShortGuid > hierarchy = new List < ShortGuid > ( ) ;
332+ public EntityHierarchy connectedEntity = new EntityHierarchy ( ) ;
329333 }
330334
331335 #region SPECIAL FUNCTION ENTITIES
@@ -335,63 +339,63 @@ public class CAGEAnimation : FunctionEntity
335339 public CAGEAnimation ( bool autoGenerateParameters = false ) : base ( FunctionType . CAGEAnimation , autoGenerateParameters ) { }
336340 public CAGEAnimation ( ShortGuid id , bool autoGenerateParameters = false ) : base ( id , FunctionType . CAGEAnimation , autoGenerateParameters ) { }
337341
338- public List < Header > keyframeHeaders = new List < Header > ( ) ;
339- public List < Keyframe > keyframeData = new List < Keyframe > ( ) ; //anim keyframes
340- public List < Keyframe2 > keyframeData2 = new List < Keyframe2 > ( ) ; //TODO: events?
342+ public List < Connection > connections = new List < Connection > ( ) ;
343+ public List < Animation > animations = new List < Animation > ( ) ;
344+ public List < Event > events = new List < Event > ( ) ;
341345
342346 [ Serializable ]
343- public class Header
347+ public class Connection
344348 {
345- public ShortGuid ID ;
346- public DataType unk2 ;
347- public ShortGuid keyframeDataID ;
348- //public float unk3;
349+ public ShortGuid shortGUID ; //Unique ID - TODO: can we just generate this?
350+ public ShortGuid keyframeID ; //The keyframe ID we're pointing to
351+
352+ #if DEBUG
353+ [ JsonConverter ( typeof ( StringEnumConverter ) ) ]
354+ #endif
355+ public ObjectType objectType ; //The type of object at the connected entity
356+
357+ //Specifics for the parameter we're connected to
349358 public ShortGuid parameterID ;
350- public DataType parameterDataType ;
359+ #if DEBUG
360+ [ JsonConverter ( typeof ( StringEnumConverter ) ) ]
361+ #endif
362+ public DataType parameterDataType ;
351363 public ShortGuid parameterSubID ; //if parameterID is position, this might be x for example
352- public List < ShortGuid > connectedEntity ; //path to controlled entity
364+
365+ //The path to the connected entity which has the above parameter
366+ public EntityHierarchy connectedEntity = new EntityHierarchy ( ) ;
353367 }
354368
355369 [ Serializable ]
356- public class Keyframe
370+ public class Animation
357371 {
358- public float minSeconds ;
359- public float maxSeconds ;
360- public ShortGuid ID ;
361- public List < Data > keyframes = new List < Data > ( ) ;
372+ public ShortGuid shortGUID ;
373+ public List < Keyframe > keyframes = new List < Keyframe > ( ) ;
362374
363375 [ Serializable ]
364- public class Data
376+ public class Keyframe
365377 {
366- public float unk1 ;
367- public float secondsSinceStart ;
368- public float secondsSinceStartValidation ;
369- public float paramValue ;
370- public float unk2 ;
371- public float unk3 ;
372- public float unk4 ;
373- public float unk5 ;
378+ public float secondsSinceStart = 0.0f ;
379+ public float paramValue = 0.0f ;
380+
381+ public Vector2 startVelocity = new Vector2 ( 1 , 0 ) ;
382+ public Vector2 endVelocity = new Vector2 ( 1 , 0 ) ;
374383 }
375384 }
376385
377- //TODO: what actually is this?
378386 [ Serializable ]
379- public class Keyframe2
387+ public class Event
380388 {
381- public float minSeconds ;
382- public float maxSeconds ;
383- public ShortGuid ID ;
384- public List < Data > keyframes = new List < Data > ( ) ;
389+ public ShortGuid shortGUID ;
390+ public List < Keyframe > keyframes = new List < Keyframe > ( ) ;
385391
386392 [ Serializable ]
387- public class Data
393+ public class Keyframe
388394 {
389- public float unk1 ;
390- public float secondsSinceStart ;
391- public float unk2 ;
392- public float unk3 ;
393- public float unk4 ;
394- public float unk5 ;
395+ public float secondsSinceStart = 0.0f ;
396+ public ShortGuid start ;
397+
398+ public ShortGuid unk3 ; //this never translates to a string, but is a param on the node -> do we trigger it?
395399 }
396400 }
397401 }
@@ -407,14 +411,8 @@ public TriggerSequence(ShortGuid id, bool autoGenerateParameters = false) : base
407411 [ Serializable ]
408412 public class Entity
409413 {
410- public Entity ( )
411- {
412- hierarchy = new List < ShortGuid > ( ) ;
413- hierarchy . Add ( new ShortGuid ( "00-00-00-00" ) ) ;
414- }
415-
416414 public float timing = 0.0f ;
417- public List < ShortGuid > hierarchy ;
415+ public EntityHierarchy connectedEntity = new EntityHierarchy ( ) ;
418416 }
419417 [ Serializable ]
420418 public class Event
@@ -451,4 +449,108 @@ public EntityLink(ShortGuid childEntityID, ShortGuid parentParam, ShortGuid chil
451449 public ShortGuid childParamID ; //The ID of the parameter we're providing into the child
452450 public ShortGuid childID ; //The ID of the entity we're linking to to provide the value for
453451 }
452+
453+ [ Serializable ]
454+ #if DEBUG
455+ [ JsonConverter ( typeof ( EntityHierarchyConverter ) ) ]
456+ #endif
457+ public class EntityHierarchy
458+ {
459+ public EntityHierarchy ( ) { }
460+ public EntityHierarchy ( List < ShortGuid > _hierarchy )
461+ {
462+ hierarchy = _hierarchy ;
463+
464+ if ( hierarchy [ hierarchy . Count - 1 ] . ToByteString ( ) != "00-00-00-00" )
465+ hierarchy . Add ( new ShortGuid ( "00-00-00-00" ) ) ;
466+ }
467+ public List < ShortGuid > hierarchy = new List < ShortGuid > ( ) ;
468+
469+ public static bool operator == ( EntityHierarchy x , EntityHierarchy y )
470+ {
471+ if ( ReferenceEquals ( x , null ) ) return ReferenceEquals ( y , null ) ;
472+ if ( ReferenceEquals ( y , null ) ) return ReferenceEquals ( x , null ) ;
473+ if ( x . hierarchy . Count != y . hierarchy . Count ) return false ;
474+ for ( int i = 0 ; i < x . hierarchy . Count ; i ++ )
475+ {
476+ if ( x . hierarchy [ i ] . ToByteString ( ) != y . hierarchy [ i ] . ToByteString ( ) )
477+ return false ;
478+ }
479+ return true ;
480+ }
481+ public static bool operator != ( EntityHierarchy x , EntityHierarchy y )
482+ {
483+ return ! ( x == y ) ;
484+ }
485+
486+ public override bool Equals ( object obj )
487+ {
488+ return obj is EntityHierarchy hierarchy &&
489+ EqualityComparer < List < ShortGuid > > . Default . Equals ( this . hierarchy , hierarchy . hierarchy ) ;
490+ }
491+
492+ public override int GetHashCode ( )
493+ {
494+ return 218564712 + EqualityComparer < List < ShortGuid > > . Default . GetHashCode ( hierarchy ) ;
495+ }
496+
497+ /* Get this hierarchy as a string */
498+ public string GetHierarchyAsString ( )
499+ {
500+ string val = "" ;
501+ for ( int i = 0 ; i < hierarchy . Count ; i ++ )
502+ {
503+ val += hierarchy [ i ] . ToByteString ( ) ;
504+ if ( i != hierarchy . Count - 1 ) val += " -> " ;
505+ }
506+ return val ;
507+ }
508+ public string GetHierarchyAsString ( Commands commands , Composite composite , bool withIDs = true )
509+ {
510+ CommandsUtils . ResolveHierarchy ( commands , composite , hierarchy , out Composite comp , out string str , withIDs ) ;
511+ return str ;
512+ }
513+
514+ public UInt32 ToUInt32 ( )
515+ {
516+ UInt32 val = 0 ;
517+ for ( int i = 0 ; i < hierarchy . Count ; i ++ ) val += hierarchy [ i ] . ToUInt32 ( ) ;
518+ return val ;
519+ }
520+
521+ /* Get the entity this hierarchy points to */
522+ public Entity GetPointedEntity ( Commands commands , Composite composite )
523+ {
524+ return CommandsUtils . ResolveHierarchy ( commands , composite , hierarchy , out Composite comp , out string str ) ;
525+ }
526+
527+ /* Does this hierarchy point to a valid entity? */
528+ public bool IsHierarchyValid ( Commands commands , Composite composite )
529+ {
530+ return GetPointedEntity ( commands , composite ) != null ;
531+ }
532+ }
533+
534+ #if DEBUG
535+ public class EntityHierarchyConverter : JsonConverter
536+ {
537+ public override void WriteJson ( JsonWriter writer , object value , JsonSerializer serializer )
538+ {
539+ writer . WriteValue ( ( ( EntityHierarchy ) value ) . GetHierarchyAsString ( ) ) ;
540+ }
541+
542+ public override object ReadJson ( JsonReader reader , Type objectType , object existingValue , JsonSerializer serializer )
543+ {
544+ EntityHierarchy e = new EntityHierarchy ( ) ;
545+ List < string > vals = reader . Value . ToString ( ) . Split ( new [ ] { " -> " } , StringSplitOptions . None ) . ToList ( ) ;
546+ for ( int i = 0 ; i < vals . Count ; i ++ ) e . hierarchy . Add ( new ShortGuid ( vals [ i ] ) ) ;
547+ return e ;
548+ }
549+
550+ public override bool CanConvert ( Type objectType )
551+ {
552+ return objectType == typeof ( EntityHierarchy ) ;
553+ }
554+ }
555+ #endif
454556}
0 commit comments