Skip to content

Commit

Permalink
feat(module): split input services into their own module
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed May 17, 2021
1 parent b3713eb commit 2741b22
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 37 deletions.
50 changes: 50 additions & 0 deletions src/module/InputModule.ts
@@ -0,0 +1,50 @@
import { isNil, mustExist } from '@apextoaster/js-utils';
import { Module, ModuleOptions, Provides } from 'noicejs';

import { INJECT_INPUT_MAPPER, INJECT_INPUT_PLAYER } from '.';
import { ActorType } from '../model/entity/Actor';
import { Input } from '../service/input';
import { ActorInputMapper } from '../service/input/ActorInputMapper';
import { BehaviorInput } from '../service/input/BehaviorInput';
import { ClassicInput } from '../service/input/ClassicInput';

export class InputModule extends Module {
protected mapper?: ActorInputMapper;
protected playerInput?: Input;

public async configure(options: ModuleOptions): Promise<void> {
await super.configure(options);
}

/**
* Singleton player input.
*/
@Provides(INJECT_INPUT_PLAYER)
protected async getPlayerInput(): Promise<Input> {
if (isNil(this.playerInput)) {
this.playerInput = await mustExist(this.container).create(ClassicInput);
}

return this.playerInput;
}

/**
* Actor type input mapper.
*
* This construct should not exist.
*/
@Provides(INJECT_INPUT_MAPPER)
protected async getMapper(): Promise<ActorInputMapper> {
if (isNil(this.mapper)) {
this.mapper = await mustExist(this.container).create(ActorInputMapper, {
inputs: {
[ActorType.DEFAULT]: BehaviorInput,
[ActorType.PLAYER]: ClassicInput,
[ActorType.REMOTE]: BehaviorInput,
},
});
}

return this.mapper;
}
}
38 changes: 1 addition & 37 deletions src/module/LocalModule.ts
Expand Up @@ -3,8 +3,6 @@ import { Logger, Module, ModuleOptions, Provides } from 'noicejs';

import {
INJECT_COUNTER,
INJECT_INPUT_MAPPER,
INJECT_INPUT_PLAYER,
INJECT_LOADER,
INJECT_LOGGER,
INJECT_PARSER,
Expand All @@ -14,17 +12,15 @@ import {
INJECT_STATE,
INJECT_TEMPLATE,
} from '.';
import { ActorType } from '../model/entity/Actor';
import { Input } from '../service/input';
import { ActorInputMapper } from '../service/input/ActorInputMapper';
import { BehaviorInput } from '../service/input/BehaviorInput';
import { ClassicInput } from '../service/input/ClassicInput';
import { FileLoader } from '../service/loader/FileLoader';
import { YamlParser } from '../service/parser/YamlParser';
import { RandomGenerator } from '../service/random';
import { SeedRandomGenerator } from '../service/random/SeedRandom';
import { Render } from '../service/render';
import { InkRender } from '../service/render/InkRender';
import { LineRender } from '../service/render/LineRender';
import { ScriptService } from '../service/script';
import { LocalScriptService } from '../service/script/LocalScriptService';
import { StateService } from '../service/state';
Expand Down Expand Up @@ -128,36 +124,4 @@ export class LocalModule extends Module {

return this.state;
}

/**
* Singleton player input.
*/
@Provides(INJECT_INPUT_PLAYER)
protected async getPlayerInput(): Promise<Input> {
if (isNil(this.playerInput)) {
this.playerInput = await mustExist(this.container).create(ClassicInput);
}

return this.playerInput;
}

/**
* Actor type input mapper.
*
* This construct should not exist.
*/
@Provides(INJECT_INPUT_MAPPER)
protected async getMapper(): Promise<ActorInputMapper> {
if (isNil(this.mapper)) {
this.mapper = await mustExist(this.container).create(ActorInputMapper, {
inputs: {
[ActorType.DEFAULT]: BehaviorInput,
[ActorType.PLAYER]: ClassicInput,
[ActorType.REMOTE]: BehaviorInput,
},
});
}

return this.mapper;
}
}

0 comments on commit 2741b22

Please sign in to comment.