|
@@ -24,30 +24,13 @@
|
|
|
public serialize(): any {
|
|
|
}
|
|
|
|
|
|
- protected _serialize(serializedCondition: any, target?: Node | Scene): any {
|
|
|
- var serializationObject = {
|
|
|
- type: 3, // Condition
|
|
|
+ protected _serialize(serializedCondition: any): any {
|
|
|
+ return {
|
|
|
+ type: 2, // Condition
|
|
|
children: [],
|
|
|
name: serializedCondition.name,
|
|
|
properties: serializedCondition.properties
|
|
|
};
|
|
|
-
|
|
|
- // If target, auto-complete
|
|
|
- if (target) {
|
|
|
- var targetObject = {
|
|
|
- name: "target",
|
|
|
- targetType: target instanceof Mesh ? "MeshProperties"
|
|
|
- : target instanceof Light ? "LightProperties"
|
|
|
- : target instanceof Camera ? "CameraProperties"
|
|
|
- : "Scene",
|
|
|
- value: target instanceof Scene ? "Scene" : target.name
|
|
|
- }
|
|
|
-
|
|
|
- // Concat action's properties
|
|
|
- serializationObject.properties = [targetObject].concat(serializationObject.properties);
|
|
|
- }
|
|
|
-
|
|
|
- return serializationObject;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -78,12 +61,14 @@
|
|
|
public _actionManager: ActionManager;
|
|
|
|
|
|
private _target: any;
|
|
|
+ private _effectiveTarget: any;
|
|
|
private _property: string;
|
|
|
|
|
|
constructor(actionManager: ActionManager, target: any, public propertyPath: string, public value: any, public operator: number = ValueCondition.IsEqual) {
|
|
|
super(actionManager);
|
|
|
|
|
|
- this._target = this._getEffectiveTarget(target, this.propertyPath);
|
|
|
+ this._target = target;
|
|
|
+ this._effectiveTarget = this._getEffectiveTarget(target, this.propertyPath);
|
|
|
this._property = this._getProperty(this.propertyPath);
|
|
|
}
|
|
|
|
|
@@ -91,23 +76,45 @@
|
|
|
public isValid(): boolean {
|
|
|
switch (this.operator) {
|
|
|
case ValueCondition.IsGreater:
|
|
|
- return this._target[this._property] > this.value;
|
|
|
+ return this._effectiveTarget[this._property] > this.value;
|
|
|
case ValueCondition.IsLesser:
|
|
|
- return this._target[this._property] < this.value;
|
|
|
+ return this._effectiveTarget[this._property] < this.value;
|
|
|
case ValueCondition.IsEqual:
|
|
|
case ValueCondition.IsDifferent:
|
|
|
var check: boolean;
|
|
|
|
|
|
if (this.value.equals) {
|
|
|
- check = this.value.equals(this._target[this._property]);
|
|
|
+ check = this.value.equals(this._effectiveTarget[this._property]);
|
|
|
} else {
|
|
|
- check = this.value === this._target[this._property];
|
|
|
+ check = this.value === this._effectiveTarget[this._property];
|
|
|
}
|
|
|
return this.operator === ValueCondition.IsEqual ? check : !check;
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+ public serialize(): any {
|
|
|
+ return this._serialize({
|
|
|
+ name: "ValueCondition",
|
|
|
+ properties: [
|
|
|
+ Action._GetTargetProperty(this._target),
|
|
|
+ { name: "propertyPath", value: this.propertyPath },
|
|
|
+ { name: "value", value: Action._SerializeValueAsString(this.value) },
|
|
|
+ { name: "operator", value: ValueCondition.GetOperatorName(this.operator) }
|
|
|
+ ]
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ public static GetOperatorName(operator: number): string {
|
|
|
+ switch (operator) {
|
|
|
+ case ValueCondition._IsEqual: return "IsEqual";
|
|
|
+ case ValueCondition._IsDifferent: return "IsDifferent";
|
|
|
+ case ValueCondition._IsGreater: return "IsGreater";
|
|
|
+ case ValueCondition._IsLesser: return "IsLesser";
|
|
|
+ default: return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export class PredicateCondition extends Condition {
|
|
@@ -144,8 +151,11 @@
|
|
|
public serialize(): any {
|
|
|
return this._serialize({
|
|
|
name: "StateCondition",
|
|
|
- properties: [{ name: "value", value: this.value }]
|
|
|
- }, this._target);
|
|
|
+ properties: [
|
|
|
+ Action._GetTargetProperty(this._target),
|
|
|
+ { name: "value", value: this.value }
|
|
|
+ ]
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|