0
0
Fork 0

Make CSV parsing actually work.

This commit is contained in:
Oliver-Akins 2021-01-01 16:02:46 -07:00
parent 8b2b360621
commit aed8f3972c

View file

@ -51,31 +51,24 @@ export class Game {
}; };
private parseDeckCSV(conf: config): void {
private parseDeckCSV(conf: config): any {
/** /**
* Parses out the CSV files and creates the decks for the game to run on * Parses out the CSV files and creates the decks for the game to run on
* *
* @param conf -> The config object * @param path -> The filepath of the CSV file
*/ */
let questions: question_deck[] = [];
let objects: object_deck[] = [];
// parse the questions from the CSV and adding them to the array // parse the questions from the CSV
createReadStream(conf.game.cards.questions) let questions = readFileSync(conf.game.cards.questions, `utf-8`).replace(/\r/g, ``);
.pipe(csv([`q`])) this._questions = new Deck(questions.split(`\n`).slice(1))
.on(`data`, (data) => { questions.push(data.q)})
.on(`end`, () => {
log.debug(`Loaded questions cards from CSV file: ${conf.game.cards.questions}`);
});
this._questions = new Deck(questions);
// parse the objects from the CSV and add them to the array // Parse the object deck from CSV
createReadStream(conf.game.cards.questions) let objectsCSV = readFileSync(conf.game.cards.objects, `utf-8`).replace(/\r/g, ``);
.pipe(csv([`q`])) let objects: string[][] = [];
.on(`data`, (data) => { objects.push(Object.values(data))}) for (var line of objectsCSV.split(`\n`).slice(1)) {
.on(`end`, () => { objects.push(line.split(`,`));
log.debug(`Loaded object cards from CSV file: ${conf.game.cards.questions}`); };
});
this._objects = new Deck(objects); this._objects = new Deck(objects);
}; };