3
0
Эх сурвалжийг харах

hotfix: if you store Actions, you need to serialize them

Stephan Fuchs 2 сар өмнө
parent
commit
0b043b7fd1

+ 24 - 1
sugarcube/src/actions/action.ts

@@ -8,7 +8,7 @@ class Action{
 
 	captured = {};
 
-	constructor(settings){
+	constructor(settings={}){
 		Object.keys(settings).forEach(function (pn) {
 			this[pn] = clone(settings[pn]);
 		}, this);
@@ -20,6 +20,29 @@ class Action{
 		}
 		$.wiki(this.contents);
 	}
+
+	//#region System
+		_init(action){
+			Object.keys(action).forEach(function (pn) {
+				this[pn] = clone(action[pn]);
+			}, this);
+
+			return this;
+		}
+
+		clone = function () {
+			return (new setup.Action())._init(this);
+		};
+
+		toJSON = function () {
+			var ownData = {};
+			Object.keys(this).forEach(function (pn) {
+				if(typeof this[pn] !== "function")
+					ownData[pn] = clone(this[pn]);
+			}, this);
+			return JSON.reviveWrapper('(new setup.Action())._init($ReviveData$)', ownData);
+		};
+	//#endregion
 }
 
 setup.Action ??= Action;

+ 1 - 1
sugarcube/src/interfaces.d.ts

@@ -1,6 +1,6 @@
 declare module "twine-sugarcube" {
 	export interface SugarCubeSetupObject {
-		Action: { new(parameter:any): Action };
+		Action: { new(parameter?:any): Action };
 		Appearance: { new(playerCharacter: PlayerCharacter): Appearance };
 		BodyDescription: { new(character:Character): BodyDescription };
 		Consumable: { new(): Consumable };