--- /dev/null
+name,level,strength,constitution,intelligence,dexterity,hp,exp,gold,helmAp,chestAp,armsAp,legsAp\r
+Giant Rat,1,3,3,3,3,5,2,1,0,0,0,0\r
+Slime,2,1,5,2,3,12,3,1,0,0,0,0\r
+Drunk Thug,3,5,4,2,5,16,5,8,0,5,0,0\r
+Kobold,4,7,8,4,7,22,9,2,3,3,0,0\r
import { Knex } from "knex";
+import { join } from 'path';
+import { readFile } from 'fs';
+import { promisify } from 'util';
+import {Monster} from "@shared/monsters";
+
+const read = promisify(readFile);
export async function seed(knex: Knex): Promise<void> {
// Deletes ALL existing entries
await knex("monsters").del();
+ await knex("fight").del();
+
+ const data = await read(join(__dirname, '..', 'data', 'monsters.csv'), 'utf8');
+
+
+ const monsters: Omit<Monster, 'id'>[] = [];
+ data.split("\r\n").slice(1).forEach(line => {
+ let pieces = line.split(',');
+ if(pieces.length === 13) {
+ console.log('Creating', pieces[0]);
+ monsters.push({
+ name: pieces[0],
+ level: parseInt(pieces[1]),
+ strength: parseInt(pieces[2]),
+ constitution: parseInt(pieces[3]),
+ intelligence: parseInt(pieces[4]),
+ dexterity: parseInt(pieces[5]),
+ hp: parseInt(pieces[6]),
+ maxHp: parseInt(pieces[6]),
+ exp: parseInt(pieces[7]),
+ gold: parseInt(pieces[8]),
+ helmAp: parseInt(pieces[9]),
+ chestAp: parseInt(pieces[10]),
+ armsAp: parseInt(pieces[11]),
+ legsAp: parseInt(pieces[12])
+ })
+ }
+ else {
+ console.log(`Skipping`, line);
+ }
+ })
// Inserts seed entries
- await knex("monsters").insert([
- {
- name: 'Rat',
- strength: 1,
- dexterity: 1,
- intelligence: 1,
- constitution: 1,
- level: 1,
- gold: 1,
- exp: 1,
- hp: 5,
- maxHp: 5
- },
- {
- name: 'Skulking Bandit',
- strength: 3,
- dexterity: 2,
- intelligence: 1,
- constitution: 3,
- level: 2,
- gold: 5,
- exp: 3,
- hp: 10,
- maxHp: 10
- },
- ]);
+ await knex("monsters").insert(monsters);
};