Skip to content
This repository was archived by the owner on Jan 9, 2025. It is now read-only.

Commit 039a88e

Browse files
committed
fix save&load bug
1 parent ef8d10f commit 039a88e

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

index.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,23 @@ export default class StoryScript {
4343
saveScope: variable.getSaveScope()
4444
}
4545
}
46-
setData(data, object) {
47-
variable.getGlobalScope(object.globalScope);
48-
variable.getSaveScope(object.saveScope);
46+
setData(object) {
47+
variable.setGlobalScope(object.globalScope);
48+
variable.setSaveScope(object.saveScope);
4949

50-
const result = parser.parse(data);
51-
const system = new IfBlock(result);
52-
this.CURRENTBLOCK = system;
53-
this.BLOCKSTACK = [];
50+
// must has excuted .load()
51+
// const result = parser.parse(data);
52+
// const system = new IfBlock(result);
53+
// this.CURRENTBLOCK = system;
54+
// this.BLOCKSTACK = [];
5455

5556
const scopes = [object.blocks[0].scope];
57+
variable.setScopes(scopes);
58+
this.CURRENTBLOCK.setCurrentLine(object.blocks[0].currentLine);
59+
60+
if (object.blocks.length === 1) {
61+
return true
62+
}
5663

5764
for (let i = 0; i < object.blocks.length; i++) {
5865
const block = object.blocks[i];
@@ -64,24 +71,24 @@ export default class StoryScript {
6471
case 'if':
6572
const ifBlock = new IfBlock(line.blocks[nextBlock.blockIndex], nextBlock.blockIndex);
6673
ifBlock.setCurrentLine(nextBlock.currentLine);
67-
scopes.push(nextBlock.scope);
68-
variable.popScope();
74+
variable.pushScope(nextBlock.scope);
75+
// variable.popScope();
6976
this.BLOCKSTACK.push(this.CURRENTBLOCK);
7077
this.CURRENTBLOCK = ifBlock;
7178
break;
7279
case 'while':
7380
const whileBlock = new WhileBlock(line.block, line.condition);
7481
whileBlock.setCurrentLine(nextBlock.currentLine);
75-
scopes.push(nextBlock.scope);
76-
variable.popScope();
82+
variable.pushScope(nextBlock.scope);
83+
// variable.popScope();
7784
this.BLOCKSTACK.push(this.CURRENTBLOCK);
7885
this.CURRENTBLOCK = whileBlock;
7986
break;
8087
case 'foreach':
8188
const foreachBlock = new ForeachBlock(line.block, line.child, line.children);
8289
foreachBlock.setCurrentLine(nextBlock.currentLine);
83-
scopes.push(nextBlock.scope);
84-
variable.popScope();
90+
variable.pushScope(nextBlock.scope);
91+
// variable.popScope();
8592
this.BLOCKSTACK.push(this.CURRENTBLOCK);
8693
this.CURRENTBLOCK = foreachBlock;
8794
break;
@@ -93,7 +100,7 @@ export default class StoryScript {
93100
}
94101
}
95102

96-
variable.setScopes(scopes);
103+
// variable.setScopes(scopes);
97104
}
98105
[Symbol.iterator]() {
99106
return this;

libs/variable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ module.exports = {
140140
SCOPES = SCOPES;
141141
this.popScope();
142142
},
143-
pushScope() {
143+
pushScope(scope={}) {
144144
SCOPES.push(CURRENTSCOPE);
145-
CURRENTSCOPE = {};
145+
CURRENTSCOPE = scope;
146146
},
147147
popScope() {
148148
CURRENTSCOPE = SCOPES.pop();

0 commit comments

Comments
 (0)