Skip to content

Commit

Permalink
organize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PssbleTrngle committed Oct 12, 2023
1 parent 239c000 commit 23aaa5e
Show file tree
Hide file tree
Showing 16 changed files with 518 additions and 467 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
with:
node-version: 16

- uses: pnpm/action-setup@v2.2.2
- uses: pnpm/action-setup@v2
with:
run_install: |
- recursive: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
with:
node-version: 16

- uses: pnpm/action-setup@v2.2.2
- uses: pnpm/action-setup@v2
with:
run_install: |
- recursive: true
Expand Down
68 changes: 68 additions & 0 deletions src/emit/custom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import Rule from '../rule'
import { Acceptor } from '@pssbletrngle/pack-resolver'
import { Recipe } from '../parser/recipe'
import { toJson } from '../textHelper'
import { RecipeDefinition } from '../schema/recipe'
import { createId, Id, IdInput } from '../common/id'
import Registry from '../common/registry'
import { LootTable } from '../loader/loot'

export interface RegistryProvider<T> {
forEach(consumer: (recipe: T, id: Id) => void): void
}

export default abstract class RuledEmitter<TEntry, TRule extends Rule<TEntry>> {

protected constructor(private readonly provider: RegistryProvider<TEntry>) {
}


private customEntries = new Registry<TEntry>()
private rulesArray: TRule[] = []

protected get rules(): ReadonlyArray<TRule> {
return this.rulesArray
}

clear() {
this.rulesArray = []
}

protected addRule(rule: TRule) {
this.rulesArray.push(rule)
}

protected addCustom(
id: IdInput,
value: TEntry
) {
this.customEntries.set(createId(id), value)
}

private async modify(acceptor: Acceptor) {
this.provider.forEach((recipe, id) => {
if (this.customRecipe.has(id)) return

const path = this.recipePath(id)

const rules = this.rules.filter(it => it.matches(id, recipe, this.logger))
if (rules.length === 0) return

const modified = rules.reduce<Recipe | null>((previous, rule) => previous && rule.modify(previous), recipe)

acceptor(path, toJson(modified?.toDefinition() ?? RecipeEmitter.EMPTY_RECIPE))
})
}

private async create(acceptor: Acceptor) {
this.customRecipe.forEach((recipe, id) => {
const path = this.recipePath(id)
acceptor(path, toJson(recipe))
})
}

async emit(acceptor: Acceptor) {
await Promise.all([this.modifyRecipes(acceptor), this.createRecipes(acceptor)])
}

}
Empty file added src/emit/index.ts
Empty file.
Empty file added src/emit/loot.ts
Empty file.
Empty file added src/emit/ruled.ts
Empty file.
Empty file added src/loader/loot.ts
Empty file.
Empty file added src/rule/index.ts
Empty file.
1 change: 1 addition & 0 deletions src/rule/lootTable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default class LootRule {}
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 23aaa5e

Please sign in to comment.