35 lines
888 B
TypeScript
35 lines
888 B
TypeScript
import { DraftSchema, Pack } from "./types";
|
|
import { PackBuilder } from "./booster";
|
|
|
|
export class DraftProvider {
|
|
private schema: DraftSchema;
|
|
|
|
constructor(schema: DraftSchema) {
|
|
this.schema = schema;
|
|
}
|
|
|
|
getPacks(): Pack[] {
|
|
let out = [];
|
|
for (const boosterSlot in this.schema.boosters) {
|
|
const amount = this.schema.boosters[boosterSlot];
|
|
const factory = this.schema.factories[boosterSlot];
|
|
if (!factory) {
|
|
throw new Error(
|
|
`booster type ${boosterSlot} was referenced in schema but was not provided a builder`
|
|
);
|
|
}
|
|
for (let i = 0; i < amount; i++) {
|
|
out.push(factory.buildPack());
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
|
|
static set(factory: PackBuilder, amount: number): DraftProvider {
|
|
return new DraftProvider({
|
|
boosters: { normal: amount },
|
|
factories: { normal: factory }
|
|
});
|
|
}
|
|
}
|