7520faaf30e90ee90f931113563b97d9abc2cc775aa6745393b8ed2255709d2c.json 19 KB

1
  1. {"ast":null,"code":"import { Action } from \"./action.js\";\nimport { RegisterClass } from \"../Misc/typeStore.js\";\n/**\n * A Condition applied to an Action\n */\nexport class Condition {\n /**\n * Creates a new Condition\n * @param actionManager the manager of the action the condition is applied to\n */\n constructor(actionManager) {\n this._actionManager = actionManager;\n }\n /**\n * Check if the current condition is valid\n * @returns a boolean\n */\n isValid() {\n return true;\n }\n /**\n * @internal\n */\n _getProperty(propertyPath) {\n return this._actionManager._getProperty(propertyPath);\n }\n /**\n * @internal\n */\n _getEffectiveTarget(target, propertyPath) {\n return this._actionManager._getEffectiveTarget(target, propertyPath);\n }\n // eslint-disable-next-line jsdoc/require-returns-check\n /**\n * Serialize placeholder for child classes\n * @returns the serialized object\n */\n serialize() {}\n /**\n * @internal\n */\n _serialize(serializedCondition) {\n return {\n type: 2,\n // Condition\n children: [],\n name: serializedCondition.name,\n properties: serializedCondition.properties\n };\n }\n}\n/**\n * Defines specific conditional operators as extensions of Condition\n */\nexport class ValueCondition extends Condition {\n /**\n * returns the number for IsEqual\n */\n static get IsEqual() {\n return ValueCondition._IsEqual;\n }\n /**\n * Returns the number for IsDifferent\n */\n static get IsDifferent() {\n return ValueCondition._IsDifferent;\n }\n /**\n * Returns the number for IsGreater\n */\n static get IsGreater() {\n return ValueCondition._IsGreater;\n }\n /**\n * Returns the number for IsLesser\n */\n static get IsLesser() {\n return ValueCondition._IsLesser;\n }\n /**\n * Creates a new ValueCondition\n * @param actionManager manager for the action the condition applies to\n * @param target for the action\n * @param propertyPath path to specify the property of the target the conditional operator uses\n * @param value the value compared by the conditional operator against the current value of the property\n * @param operator the conditional operator, default ValueCondition.IsEqual\n */\n constructor(actionManager, target, /** path to specify the property of the target the conditional operator uses */\n propertyPath, /** the value compared by the conditional operator against the current value of the property */\n value, /** [number] the conditional operator, default ValueCondition.IsEqual */\n operator = ValueCondition.IsEqual) {\n super(actionManager);\n this.propertyPath = propertyPath;\n this.value = value;\n this.operator = operator;\n this._target = target;\n this._effectiveTarget = this._getEffectiveTarget(target, this.propertyPath);\n this._property = this._getProperty(this.propertyPath);\n }\n /**\n * Compares the given value with the property value for the specified conditional operator\n * @returns the result of the comparison\n */\n isValid() {\n switch (this.operator) {\n case ValueCondition.IsGreater:\n return this._effectiveTarget[this._property] > this.value;\n case ValueCondition.IsLesser:\n return this._effectiveTarget[this._property] < this.value;\n case ValueCondition.IsEqual:\n case ValueCondition.IsDifferent:\n {\n let check;\n if (this.value.equals) {\n check = this.value.equals(this._effectiveTarget[this._property]);\n } else {\n check = this.value === this._effectiveTarget[this._property];\n }\n return this.operator === ValueCondition.IsEqual ? check : !check;\n }\n }\n return false;\n }\n /**\n * Serialize the ValueCondition into a JSON compatible object\n * @returns serialization object\n */\n serialize() {\n return this._serialize({\n name: \"ValueCondition\",\n properties: [Action._GetTargetProperty(this._target), {\n name: \"propertyPath\",\n value: this.propertyPath\n }, {\n name: \"value\",\n value: Action._SerializeValueAsString(this.value)\n }, {\n name: \"operator\",\n value: ValueCondition.GetOperatorName(this.operator)\n }]\n });\n }\n /**\n * Gets the name of the conditional operator for the ValueCondition\n * @param operator the conditional operator\n * @returns the name\n */\n static GetOperatorName(operator) {\n switch (operator) {\n case ValueCondition._IsEqual:\n return \"IsEqual\";\n case ValueCondition._IsDifferent:\n return \"IsDifferent\";\n case ValueCondition._IsGreater:\n return \"IsGreater\";\n case ValueCondition._IsLesser:\n return \"IsLesser\";\n default:\n return \"\";\n }\n }\n}\nValueCondition._IsEqual = 0;\nValueCondition._IsDifferent = 1;\nValueCondition._IsGreater = 2;\nValueCondition._IsLesser = 3;\n/**\n * Defines a predicate condition as an extension of Condition\n */\nexport class PredicateCondition extends Condition {\n /**\n * Creates a new PredicateCondition\n * @param actionManager manager for the action the condition applies to\n * @param predicate defines the predicate function used to validate the condition\n */\n constructor(actionManager, /** defines the predicate function used to validate the condition */\n predicate) {\n super(actionManager);\n this.predicate = predicate;\n }\n /**\n * @returns the validity of the predicate condition\n */\n isValid() {\n return this.predicate();\n }\n}\n/**\n * Defines a state condition as an extension of Condition\n */\nexport class StateCondition extends Condition {\n /**\n * Creates a new StateCondition\n * @param actionManager manager for the action the condition applies to\n * @param target of the condition\n * @param value to compare with target state\n */\n constructor(actionManager, target, /** Value to compare with target state */\n value) {\n super(actionManager);\n this.value = value;\n this._target = target;\n }\n /**\n * Gets a boolean indicating if the current condition is met\n * @returns the validity of the state\n */\n isValid() {\n return this._target.state === this.value;\n }\n /**\n * Serialize the StateCondition into a JSON compatible object\n * @returns serialization object\n */\n serialize() {\n return this._serialize({\n name: \"StateCondition\",\n properties: [Action._GetTargetProperty(this._target), {\n name: \"value\",\n value: this.value\n }]\n });\n }\n}\nRegisterClass(\"BABYLON.ValueCondition\", ValueCondition);\nRegisterClass(\"BABYLON.PredicateCondition\", PredicateCondition);\nRegisterClass(\"BABYLON.StateCondition\", StateCondition);","map":{"version":3,"names":["Action","RegisterClass","Condition","constructor","actionManager","_actionManager","isValid","_getProperty","propertyPath","_getEffectiveTarget","target","serialize","_serialize","serializedCondition","type","children","name","properties","ValueCondition","IsEqual","_IsEqual","IsDifferent","_IsDifferent","IsGreater","_IsGreater","IsLesser","_IsLesser","value","operator","_target","_effectiveTarget","_property","check","equals","_GetTargetProperty","_SerializeValueAsString","GetOperatorName","PredicateCondition","predicate","StateCondition","state"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/Actions/condition.js"],"sourcesContent":["import { Action } from \"./action.js\";\nimport { RegisterClass } from \"../Misc/typeStore.js\";\n/**\n * A Condition applied to an Action\n */\nexport class Condition {\n /**\n * Creates a new Condition\n * @param actionManager the manager of the action the condition is applied to\n */\n constructor(actionManager) {\n this._actionManager = actionManager;\n }\n /**\n * Check if the current condition is valid\n * @returns a boolean\n */\n isValid() {\n return true;\n }\n /**\n * @internal\n */\n _getProperty(propertyPath) {\n return this._actionManager._getProperty(propertyPath);\n }\n /**\n * @internal\n */\n _getEffectiveTarget(target, propertyPath) {\n return this._actionManager._getEffectiveTarget(target, propertyPath);\n }\n // eslint-disable-next-line jsdoc/require-returns-check\n /**\n * Serialize placeholder for child classes\n * @returns the serialized object\n */\n serialize() { }\n /**\n * @internal\n */\n _serialize(serializedCondition) {\n return {\n type: 2, // Condition\n children: [],\n name: serializedCondition.name,\n properties: serializedCondition.properties,\n };\n }\n}\n/**\n * Defines specific conditional operators as extensions of Condition\n */\nexport class ValueCondition extends Condition {\n /**\n * returns the number for IsEqual\n */\n static get IsEqual() {\n return ValueCondition._IsEqual;\n }\n /**\n * Returns the number for IsDifferent\n */\n static get IsDifferent() {\n return ValueCondition._IsDifferent;\n }\n /**\n * Returns the number for IsGreater\n */\n static get IsGreater() {\n return ValueCondition._IsGreater;\n }\n /**\n * Returns the number for IsLesser\n */\n static get IsLesser() {\n return ValueCondition._IsLesser;\n }\n /**\n * Creates a new ValueCondition\n * @param actionManager manager for the action the condition applies to\n * @param target for the action\n * @param propertyPath path to specify the property of the target the conditional operator uses\n * @param value the value compared by the conditional operator against the current value of the property\n * @param operator the conditional operator, default ValueCondition.IsEqual\n */\n constructor(actionManager, target, \n /** path to specify the property of the target the conditional operator uses */\n propertyPath, \n /** the value compared by the conditional operator against the current value of the property */\n value, \n /** [number] the conditional operator, default ValueCondition.IsEqual */\n operator = ValueCondition.IsEqual) {\n super(actionManager);\n this.propertyPath = propertyPath;\n this.value = value;\n this.operator = operator;\n this._target = target;\n this._effectiveTarget = this._getEffectiveTarget(target, this.propertyPath);\n this._property = this._getProperty(this.propertyPath);\n }\n /**\n * Compares the given value with the property value for the specified conditional operator\n * @returns the result of the comparison\n */\n isValid() {\n switch (this.operator) {\n case ValueCondition.IsGreater:\n return this._effectiveTarget[this._property] > this.value;\n case ValueCondition.IsLesser:\n return this._effectiveTarget[this._property] < this.value;\n case ValueCondition.IsEqual:\n case ValueCondition.IsDifferent: {\n let check;\n if (this.value.equals) {\n check = this.value.equals(this._effectiveTarget[this._property]);\n }\n else {\n check = this.value === this._effectiveTarget[this._property];\n }\n return this.operator === ValueCondition.IsEqual ? check : !check;\n }\n }\n return false;\n }\n /**\n * Serialize the ValueCondition into a JSON compatible object\n * @returns serialization object\n */\n serialize() {\n return this._serialize({\n name: \"ValueCondition\",\n properties: [\n Action._GetTargetProperty(this._target),\n { name: \"propertyPath\", value: this.propertyPath },\n { name: \"value\", value: Action._SerializeValueAsString(this.value) },\n { name: \"operator\", value: ValueCondition.GetOperatorName(this.operator) },\n ],\n });\n }\n /**\n * Gets the name of the conditional operator for the ValueCondition\n * @param operator the conditional operator\n * @returns the name\n */\n static GetOperatorName(operator) {\n switch (operator) {\n case ValueCondition._IsEqual:\n return \"IsEqual\";\n case ValueCondition._IsDifferent:\n return \"IsDifferent\";\n case ValueCondition._IsGreater:\n return \"IsGreater\";\n case ValueCondition._IsLesser:\n return \"IsLesser\";\n default:\n return \"\";\n }\n }\n}\nValueCondition._IsEqual = 0;\nValueCondition._IsDifferent = 1;\nValueCondition._IsGreater = 2;\nValueCondition._IsLesser = 3;\n/**\n * Defines a predicate condition as an extension of Condition\n */\nexport class PredicateCondition extends Condition {\n /**\n * Creates a new PredicateCondition\n * @param actionManager manager for the action the condition applies to\n * @param predicate defines the predicate function used to validate the condition\n */\n constructor(actionManager, \n /** defines the predicate function used to validate the condition */\n predicate) {\n super(actionManager);\n this.predicate = predicate;\n }\n /**\n * @returns the validity of the predicate condition\n */\n isValid() {\n return this.predicate();\n }\n}\n/**\n * Defines a state condition as an extension of Condition\n */\nexport class StateCondition extends Condition {\n /**\n * Creates a new StateCondition\n * @param actionManager manager for the action the condition applies to\n * @param target of the condition\n * @param value to compare with target state\n */\n constructor(actionManager, target, \n /** Value to compare with target state */\n value) {\n super(actionManager);\n this.value = value;\n this._target = target;\n }\n /**\n * Gets a boolean indicating if the current condition is met\n * @returns the validity of the state\n */\n isValid() {\n return this._target.state === this.value;\n }\n /**\n * Serialize the StateCondition into a JSON compatible object\n * @returns serialization object\n */\n serialize() {\n return this._serialize({\n name: \"StateCondition\",\n properties: [Action._GetTargetProperty(this._target), { name: \"value\", value: this.value }],\n });\n }\n}\nRegisterClass(\"BABYLON.ValueCondition\", ValueCondition);\nRegisterClass(\"BABYLON.PredicateCondition\", PredicateCondition);\nRegisterClass(\"BABYLON.StateCondition\", StateCondition);\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,aAAa;AACpC,SAASC,aAAa,QAAQ,sBAAsB;AACpD;AACA;AACA;AACA,OAAO,MAAMC,SAAS,CAAC;EACnB;AACJ;AACA;AACA;EACIC,WAAWA,CAACC,aAAa,EAAE;IACvB,IAAI,CAACC,cAAc,GAAGD,aAAa;EACvC;EACA;AACJ;AACA;AACA;EACIE,OAAOA,CAAA,EAAG;IACN,OAAO,IAAI;EACf;EACA;AACJ;AACA;EACIC,YAAYA,CAACC,YAAY,EAAE;IACvB,OAAO,IAAI,CAACH,cAAc,CAACE,YAAY,CAACC,YAAY,CAAC;EACzD;EACA;AACJ;AACA;EACIC,mBAAmBA,CAACC,MAAM,EAAEF,YAAY,EAAE;IACtC,OAAO,IAAI,CAACH,cAAc,CAACI,mBAAmB,CAACC,MAAM,EAAEF,YAAY,CAAC;EACxE;EACA;EACA;AACJ;AACA;AACA;EACIG,SAASA,CAAA,EAAG,CAAE;EACd;AACJ;AACA;EACIC,UAAUA,CAACC,mBAAmB,EAAE;IAC5B,OAAO;MACHC,IAAI,EAAE,CAAC;MAAE;MACTC,QAAQ,EAAE,EAAE;MACZC,IAAI,EAAEH,mBAAmB,CAACG,IAAI;MAC9BC,UAAU,EAAEJ,mBAAmB,CAACI;IACpC,CAAC;EACL;AACJ;AACA;AACA;AACA;AACA,OAAO,MAAMC,cAAc,SAAShB,SAAS,CAAC;EAC1C;AACJ;AACA;EACI,WAAWiB,OAAOA,CAAA,EAAG;IACjB,OAAOD,cAAc,CAACE,QAAQ;EAClC;EACA;AACJ;AACA;EACI,WAAWC,WAAWA,CAAA,EAAG;IACrB,OAAOH,cAA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alDependencies":[]}