123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- module BABYLON {
- export class SwitchBooleanAction extends Action {
- private _target: any;
- private _effectiveTarget: any;
- private _property: string;
- constructor(triggerOptions: any, target: any, public propertyPath: string, condition?: Condition) {
- super(triggerOptions, condition);
- this._target = this._effectiveTarget = target;
- }
- public _prepare(): void {
- this._effectiveTarget = this._getEffectiveTarget(this._effectiveTarget, this.propertyPath);
- this._property = this._getProperty(this.propertyPath);
- }
- public execute(): void {
- this._effectiveTarget[this._property] = !this._effectiveTarget[this._property];
- }
-
- public serialize(parent: any): any {
- return super._serialize({
- name: "SwitchBooleanAction",
- properties: [
- Action._GetTargetProperty(this._target),
- { name: "propertyPath", value: this.propertyPath }
- ]
- }, parent);
- }
- }
- export class SetStateAction extends Action {
- private _target: any;
- constructor(triggerOptions: any, target: any, public value: string, condition?: Condition) {
- super(triggerOptions, condition);
- this._target = target;
- }
- public execute(): void {
- this._target.state = this.value;
- }
-
- public serialize(parent: any): any {
- return super._serialize({
- name: "SetStateAction",
- properties: [
- Action._GetTargetProperty(this._target),
- { name: "value", value: this.value }
- ]
- }, parent);
- }
- }
- export class SetValueAction extends Action {
- private _target: any;
- private _effectiveTarget: any;
- private _property: string;
- constructor(triggerOptions: any, target: any, public propertyPath: string, public value: any, condition?: Condition) {
- super(triggerOptions, condition);
- this._target = this._effectiveTarget = target;
- }
- public _prepare(): void {
- this._effectiveTarget = this._getEffectiveTarget(this._effectiveTarget, this.propertyPath);
- this._property = this._getProperty(this.propertyPath);
- }
- public execute(): void {
- this._effectiveTarget[this._property] = this.value;
- }
-
- public serialize(parent: any): any {
- return super._serialize({
- name: "SetValueAction",
- properties: [
- Action._GetTargetProperty(this._target),
- { name: "propertyPath", value: this.propertyPath },
- { name: "value", value: Action._SerializeValueAsString(this.value) }
- ]
- }, parent);
- }
- }
- export class IncrementValueAction extends Action {
- private _target: any;
- private _effectiveTarget: any;
- private _property: string;
- constructor(triggerOptions: any, target: any, public propertyPath: string, public value: any, condition?: Condition) {
- super(triggerOptions, condition);
- this._target = this._effectiveTarget = target;
- }
- public _prepare(): void {
- this._effectiveTarget = this._getEffectiveTarget(this._effectiveTarget, this.propertyPath);
- this._property = this._getProperty(this.propertyPath);
- if (typeof this._effectiveTarget[this._property] !== "number") {
- Tools.Warn("Warning: IncrementValueAction can only be used with number values");
- }
- }
- public execute(): void {
- this._effectiveTarget[this._property] += this.value;
- }
-
- public serialize(parent: any): any {
- return super._serialize({
- name: "IncrementValueAction",
- properties: [
- Action._GetTargetProperty(this._target),
- { name: "propertyPath", value: this.propertyPath },
- { name: "value", value: Action._SerializeValueAsString(this.value) }
- ]
- }, parent);
- }
- }
- export class PlayAnimationAction extends Action {
- private _target: any;
- constructor(triggerOptions: any, target: any, public from: number, public to: number, public loop?: boolean, condition?: Condition) {
- super(triggerOptions, condition);
- this._target = target;
- }
- public _prepare(): void {
- }
- public execute(): void {
- var scene = this._actionManager.getScene();
- scene.beginAnimation(this._target, this.from, this.to, this.loop);
- }
-
- public serialize(parent: any): any {
- return super._serialize({
- name: "PlayAnimationAction",
- properties: [
- Action._GetTargetProperty(this._target),
- { name: "from", value: String(this.from) },
- { name: "to", value: String(this.to) },
- { name: "loop", value: Action._SerializeValueAsString(this.loop) || false }
- ]
- }, parent);
- }
- }
- export class StopAnimationAction extends Action {
- private _target: any;
- constructor(triggerOptions: any, target: any, condition?: Condition) {
- super(triggerOptions, condition);
- this._target = target;
- }
- public _prepare(): void {
- }
- public execute(): void {
- var scene = this._actionManager.getScene();
- scene.stopAnimation(this._target);
- }
-
- public serialize(parent: any): any {
- return super._serialize({
- name: "StopAnimationAction",
- properties: [Action._GetTargetProperty(this._target)]
- }, parent);
- }
- }
- export class DoNothingAction extends Action {
- constructor(triggerOptions: any = ActionManager.NothingTrigger, condition?: Condition) {
- super(triggerOptions, condition);
- }
- public execute(): void {
- }
-
- public serialize(parent: any): any {
- return super._serialize({
- name: "DoNothingAction",
- properties: []
- }, parent);
- }
- }
- export class CombineAction extends Action {
- constructor(triggerOptions: any, public children: Action[], condition?: Condition) {
- super(triggerOptions, condition);
- }
- public _prepare(): void {
- for (var index = 0; index < this.children.length; index++) {
- this.children[index]._actionManager = this._actionManager;
- this.children[index]._prepare();
- }
- }
- public execute(evt: ActionEvent): void {
- for (var index = 0; index < this.children.length; index++) {
- this.children[index].execute(evt);
- }
- }
-
- public serialize(parent: any): any {
- var serializationObject = super._serialize({
- name: "CombineAction",
- properties: [],
- combine: []
- }, parent);
-
- for (var i=0; i < this.children.length; i++) {
- serializationObject.combine.push(this.children[i].serialize(null));
- }
-
- return serializationObject;
- }
- }
- export class ExecuteCodeAction extends Action {
- constructor(triggerOptions: any, public func: (evt: ActionEvent) => void, condition?: Condition) {
- super(triggerOptions, condition);
- }
- public execute(evt: ActionEvent): void {
- this.func(evt);
- }
- }
- export class SetParentAction extends Action {
- private _parent: any;
- private _target: any;
- constructor(triggerOptions: any, target: any, parent: any, condition?: Condition) {
- super(triggerOptions, condition);
- this._target = target;
- this._parent = parent;
- }
- public _prepare(): void {
- }
- public execute(): void {
- if (this._target.parent === this._parent) {
- return;
- }
- var invertParentWorldMatrix = this._parent.getWorldMatrix().clone();
- invertParentWorldMatrix.invert();
- this._target.position = Vector3.TransformCoordinates(this._target.position, invertParentWorldMatrix);
- this._target.parent = this._parent;
- }
-
- public serialize(parent: any): any {
- return super._serialize({
- name: "SetParentAction",
- properties: [
- Action._GetTargetProperty(this._target),
- Action._GetTargetProperty(this._parent),
- ]
- }, parent);
- }
- }
- export class PlaySoundAction extends Action {
- private _sound: Sound;
- constructor(triggerOptions: any, sound: Sound, condition?: Condition) {
- super(triggerOptions, condition);
- this._sound = sound;
- }
- public _prepare(): void {
- }
- public execute(): void {
- if (this._sound !== undefined)
- this._sound.play();
- }
-
- public serialize(parent: any): any {
- return super._serialize({
- name: "PlaySoundAction",
- properties: [{ name: "sound", value: this._sound.name }]
- }, parent);
- }
- }
- export class StopSoundAction extends Action {
- private _sound: Sound;
- constructor(triggerOptions: any, sound: Sound, condition?: Condition) {
- super(triggerOptions, condition);
- this._sound = sound;
- }
- public _prepare(): void {
- }
- public execute(): void {
- if (this._sound !== undefined)
- this._sound.stop();
- }
-
- public serialize(parent: any): any {
- return super._serialize({
- name: "StopSoundAction",
- properties: [{ name: "sound", value: this._sound.name }]
- }, parent);
- }
- }
- }
|