From: xangelo Date: Thu, 1 Jun 2023 17:43:40 +0000 (-0400) Subject: import item csv as seed X-Git-Tag: v0.0.1~89 X-Git-Url: https://git.xangelo.ca/?a=commitdiff_plain;h=911ecff4b6158c5949be0d3e8c05cb290099f002;p=risinglegends.git import item csv as seed --- diff --git a/data/inventory.csv b/data/inventory.csv new file mode 100644 index 0000000..add61fa --- /dev/null +++ b/data/inventory.csv @@ -0,0 +1,6 @@ +Name,Type,Sub Type,Profession,Cost,Required Level,Required STR,Required CON,Required DEX,Required INT,Boost STR,Boost CON,Boost DEX,Boost INT,Boost DMG,Armour Points +Plain Helm,ARMOUR,HELM,Wanderer,3,1,0,0,0,0,0,0,0,0,0,20 +Gloves,ARMOUR,ARMS,Wanderer,2,1,0,0,0,0,0,0,0,0,0,20 +Tunic,ARMOUR,CHEST,Wanderer,5,1,0,0,0,0,0,0,0,0,0,20 +Boots,ARMOUR,LEGS,Wanderer,3,1,0,0,0,0,0,0,0,0,0,20 +Short Sword,WEAPON,BLADE,Wanderer,5,1,0,0,0,0,0,0,0,0,3,50 diff --git a/seeds/shop_items.ts b/seeds/shop_items.ts index ea9e108..3b5e215 100644 --- a/seeds/shop_items.ts +++ b/seeds/shop_items.ts @@ -1,5 +1,11 @@ -import {ShopItem} from "../src/shared/inventory"; +import {ShopItem, InventoryType, SubType} from "../src/shared/inventory"; import { Knex } from "knex"; +import { join } from 'path'; +import { readFile } from 'fs'; +import { promisify } from 'util'; +import {Profession} from "../src/shared/player"; + +const read = promisify(readFile); export async function seed(knex: Knex): Promise { // Deletes ALL existing entries @@ -7,88 +13,39 @@ export async function seed(knex: Knex): Promise { await knex("equipped").del(); await knex("inventory").del(); - const data: Partial[] = [ - { - name: 'Tattered Helm', - type: 'ARMOUR', - subType: 'HELM', - cost: 3, - count: 1, - requirement_level: 1, - requirement_strength: 0, - requirement_constitution: 0, - requirement_dexterity: 0, - requirement_intelligence: 0, - profession: 'Wanderer', - boost_strength: 0, - boost_constitution: 0, - boost_dexterity: 0, - boost_intelligence: 0, - boost_damage: 0, - currentAp: 20, - maxAp: 20 - }, - { - name: 'Trainee\'s Helm', - type: 'ARMOUR', - subType: 'HELM', - cost: 10, - count: 1, - requirement_level: 2, - requirement_strength: 0, - requirement_constitution: 0, - requirement_dexterity: 0, - requirement_intelligence: 0, - profession: 'Wanderer', - boost_strength: 0, - boost_constitution: 0, - boost_dexterity: 0, - boost_intelligence: 0, - boost_damage: 0, - currentAp: 20, - maxAp: 20 - }, - { - name: 'Torn Leather Gauntlets', - type: 'ARMOUR', - subType: 'ARMS', - cost: 3, - count: 1, - requirement_level: 1, - requirement_strength: 0, - requirement_constitution: 0, - requirement_dexterity: 0, - requirement_intelligence: 0, - profession: 'Wanderer', - boost_strength: 0, - boost_constitution: 0, - boost_dexterity: 0, - boost_intelligence: 0, - boost_damage: 0, - currentAp: 20, - maxAp: 20 - }, - { - name: 'Short Sword', - type: 'WEAPON', - subType: 'BLADE', - cost: 5, - count: 1, - requirement_level: 1, - requirement_strength: 0, - requirement_constitution: 0, - requirement_dexterity: 0, - requirement_intelligence: 0, - profession: 'Wanderer', - boost_strength: 0, - boost_constitution: 0, - boost_dexterity: 0, - boost_intelligence: 0, - boost_damage: 4, - currentAp: 50, - maxAp: 50 + const data = await read(join(__dirname, '..', 'data', 'inventory.csv'), 'utf8'); + + const items: Omit[] = []; + + data.split("\r\n").slice(1).forEach(line => { + let pieces = line.split(','); + if(pieces.length === 16) { + console.log('Adding', pieces[0]); + items.push({ + name: pieces[0], + type: pieces[1] as InventoryType, + subType: pieces[2] as SubType, + profession: pieces[3] as Profession, + cost: parseInt(pieces[4]), + count: 1, + requirement_level: parseInt(pieces[5]), + requirement_strength: parseInt(pieces[6]), + requirement_constitution: parseInt(pieces[7]), + requirement_dexterity: parseInt(pieces[8]), + requirement_intelligence: parseInt(pieces[9]), + boost_strength: parseInt(pieces[10]), + boost_constitution: parseInt(pieces[11]), + boost_dexterity: parseInt(pieces[12]), + boost_intelligence: parseInt(pieces[13]), + boost_damage: parseInt(pieces[14]), + currentAp: parseInt(pieces[15]), + maxAp: parseInt(pieces[15]) + }); + } + else { + console.log(`Skipped ${line}`); } - ]; + }); - await knex('shop_items').insert(data); + await knex('shop_items').insert(items); }; diff --git a/src/shared/inventory.ts b/src/shared/inventory.ts index ffe4c27..0f81a4c 100644 --- a/src/shared/inventory.ts +++ b/src/shared/inventory.ts @@ -13,6 +13,7 @@ export type ShopItem = { name: string; type: InventoryType; subType: SubType; + profession: Profession; cost: number; count: number; requirement_level: number; @@ -20,7 +21,6 @@ export type ShopItem = { requirement_constitution: number; requirement_dexterity: number; requirement_intelligence: number; - profession: Profession; boost_strength: number; boost_constitution: number; boost_dexterity: number;