Use proper CSV parsing.
This commit is contained in:
parent
52ec31eb0b
commit
4a9092bedb
1 changed files with 24 additions and 13 deletions
|
|
@ -1,9 +1,10 @@
|
||||||
import { Team } from "./Team";
|
import { Team } from "./Team";
|
||||||
import { Deck } from "./Deck";
|
import { Deck } from "./Deck";
|
||||||
|
import neatCSV from "neat-csv";
|
||||||
import { Logger } from "tslog";
|
import { Logger } from "tslog";
|
||||||
import { games } from "../main";
|
import { games } from "../main";
|
||||||
import { Player } from "./Player";
|
import { Player } from "./Player";
|
||||||
import { readFileSync } from "fs";
|
import { readFile } from "fs";
|
||||||
|
|
||||||
export class Game {
|
export class Game {
|
||||||
readonly id: string;
|
readonly id: string;
|
||||||
|
|
@ -70,20 +71,30 @@ export class Game {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// parse the questions from the CSV
|
// parse the questions from the CSV
|
||||||
let data = readFileSync(conf.game.cards.questions.fingerprint, `utf-8`).replace(/\r/g, ``);
|
readFile(conf.game.cards.questions.fingerprint, `utf-8`, (err, filebuffer) => {
|
||||||
let questions: question_deck[] = [];
|
if (err) throw err;
|
||||||
for (var line of data.split(`\n`).slice(conf.game.cards.questions.header_rows)) {
|
neatCSV(filebuffer)
|
||||||
questions.push(line.split(`,`)[conf.game.cards.questions.column]);
|
.then((data) => {
|
||||||
};
|
let questions: question_deck[] = [];
|
||||||
this._questions = new Deck(questions);
|
for (var entry of data) {
|
||||||
|
questions.push(Object.values(entry)[conf.game.cards.questions.column]);
|
||||||
|
};
|
||||||
|
this._questions = new Deck(questions);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Parse the object deck from CSV
|
// Parse the object deck from CSV
|
||||||
let objectsCSV = readFileSync(conf.game.cards.objects.fingerprint, `utf-8`).replace(/\r/g, ``);
|
readFile(conf.game.cards.objects.fingerprint, `utf-8`, (err, filebuffer) => {
|
||||||
let objects: object_deck[] = [];
|
if (err) throw err;
|
||||||
for (var line of objectsCSV.split(`\n`).slice(conf.game.cards.objects.header_rows)) {
|
neatCSV(filebuffer)
|
||||||
objects.push(line.split(`,`));
|
.then((data) => {
|
||||||
};
|
let objects: object_deck[] = [];
|
||||||
this._objects = new Deck(objects);
|
for (var line of data) {
|
||||||
|
objects.push(Object.values(line));
|
||||||
|
};
|
||||||
|
this._objects = new Deck(objects);
|
||||||
|
})
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
private parseDeckGoogleSheets(conf: config): void {
|
private parseDeckGoogleSheets(conf: config): void {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue