Skip to content

Commit

Permalink
feat(template): render verb and mixed-primitive maps
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed May 23, 2021
1 parent b1d63b9 commit 685dfe7
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/service/template/ChainTemplateService.ts
Expand Up @@ -44,7 +44,8 @@ export class ChainTemplateService implements TemplateService {

if (input.step < 1) {
const range = input.max - input.min;
return (this.random.nextFloat() % range) + input.min;
const next = this.random.nextFloat() % range;
return (Math.floor(next / input.step) * input.step) + input.min;
} else {
return this.random.nextInt(input.max, input.min);
}
Expand Down Expand Up @@ -78,13 +79,27 @@ export class ChainTemplateService implements TemplateService {
return result;
}

public renderPrimitiveMap(input: Map<string, TemplateNumber | TemplateString>): Map<string, number | string> {
const result = new Map();

for (const [key, value] of input) {
if (value.type === 'number') {
result.set(key, this.renderNumber(value));
} else {
result.set(key, this.renderString(value));
}
}

return result;
}

public renderVerbMap(input: Map<string, BaseTemplate<VerbSlot>>): VerbMap {
const result = new Map();

for (const [key, value] of input) {
const verb: VerbSlot = {
slot: this.renderString(value.slot),
data: new Map(), // TODO: render this stuff
data: this.renderPrimitiveMap(value.data),
};

result.set(key, verb);
Expand Down

0 comments on commit 685dfe7

Please sign in to comment.