@@ -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 }
0 commit comments