Skip to content

Commit

Permalink
fix: copy full context when calling transfer scripts, test stack map …
Browse files Browse the repository at this point in the history
…more
  • Loading branch information
ssube committed Jun 1, 2021
1 parent 700c147 commit d0bbeab
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/service/script/index.ts
Expand Up @@ -18,6 +18,8 @@ export type ScriptFunction = (this: ScriptTarget, context: ScriptContext) => Pro

export interface StateHelper {
enter: (target: ShowSource) => Promise<void>;
// find: () => Promise<Array<WorldEntity>>; // replaces searchState
// move: () => Promise<void>; // replaces transfer
show: (msg: string, context?: LocaleContext, volume?: ShowVolume, source?: ShowSource) => Promise<void>;
quit: () => Promise<void>;
}
Expand Down
10 changes: 2 additions & 8 deletions src/util/state/EntityTransfer.ts
Expand Up @@ -92,14 +92,11 @@ export class StateEntityTransfer {
target.actors.push(transfer.moving);

await context.script.invoke(target, SLOT_ENTER, {
...context,
actor: transfer.moving,
data: new Map([
['source', transfer.source],
]),
random: context.random,
state: context.state,
stateHelper: context.stateHelper,
transfer: context.transfer,
});
}

Expand Down Expand Up @@ -155,14 +152,11 @@ export class StateEntityTransfer {
target.items.push(transfer.moving);

await context.script.invoke(target, SLOT_GET, {
...context,
item: transfer.moving,
data: new Map([
['source', transfer.source],
]),
random: context.random,
state: context.state,
stateHelper: context.stateHelper,
transfer: context.transfer,
});
}
}
10 changes: 9 additions & 1 deletion test/util/collection/TestStackMap.ts
Expand Up @@ -41,7 +41,7 @@ describe('stack map', () => {
expect(map.get('bar')).to.deep.equal([]);
});

it('should clear items normally', async () => {
it('should clear data normally', async () => {
const map = new StackMap();
map.push('foo', 1);
map.push('bar', 1);
Expand All @@ -50,4 +50,12 @@ describe('stack map', () => {
map.clear();
expect(map.size).to.equal(0);
});

it('should test key presence normally', async () => {
const map = new StackMap();
map.push('foo', 1);

expect(map.has('foo')).to.equal(true);
expect(map.has('bar')).to.equal(false);
});
});

0 comments on commit d0bbeab

Please sign in to comment.