Skip to content

Commit

Permalink
fix(script): use scope state for broadcast search
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed May 16, 2021
1 parent 1a418a6 commit 7a1c5de
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/service/script/LocalScriptController.ts
@@ -1,10 +1,10 @@
import { doesExist, isNil } from '@apextoaster/js-utils';
import { isNil } from '@apextoaster/js-utils';
import { BaseOptions, Inject, Logger } from 'noicejs';

import { ScriptController, ScriptFunction, ScriptTarget, SuppliedScope } from '.';
import { State } from '../../model/State';
import { WorldEntity } from '../../model/entity';
import { INJECT_LOGGER } from '../../module';
import { matchMetadata, SearchParams, searchState } from '../../util/state';
import { SearchParams, searchState } from '../../util/state';
import { ActorHit } from './common/ActorHit';
import { ActorStep } from './common/ActorStep';
import { ItemStep } from './common/ItemStep';
Expand Down Expand Up @@ -59,11 +59,11 @@ export class LocalScriptController implements ScriptController {
});
}

async broadcast(state: State, filter: Partial<SearchParams>, slot: string, scope: SuppliedScope): Promise<void> {
const targets = searchState(state, filter);
async broadcast(filter: Partial<SearchParams>, slot: string, scope: SuppliedScope): Promise<void> {
const targets = searchState(scope.state, filter);

for (const target of targets) {
await this.invoke(target, slot, scope);
await this.invoke(target as WorldEntity, slot, scope);
}
}
}
2 changes: 1 addition & 1 deletion src/service/script/common/RoomStep.ts
Expand Up @@ -15,7 +15,7 @@ export async function RoomStep(this: ScriptTarget, scope: ScriptScope): Promise<
}

// TODO: remove
await scope.script.broadcast(scope.state, {
await scope.script.broadcast({
meta: {
id: 'actor-goblin',
},
Expand Down
2 changes: 1 addition & 1 deletion src/service/script/index.ts
Expand Up @@ -79,6 +79,6 @@ export interface ScriptScope extends SuppliedScope {
}

export interface ScriptController {
broadcast(state: Immutable<State>, search: Partial<SearchParams>, slot: string, scope: SuppliedScope): Promise<void>;
broadcast(search: Partial<SearchParams>, slot: string, scope: SuppliedScope): Promise<void>;
invoke(target: ScriptTarget, slot: string, scope: SuppliedScope): Promise<void>;
}

0 comments on commit 7a1c5de

Please sign in to comment.