import item csv as seed
authorxangelo <git@xangelo.ca>
Thu, 1 Jun 2023 17:43:40 +0000 (13:43 -0400)
committerxangelo <git@xangelo.ca>
Thu, 1 Jun 2023 17:43:40 +0000 (13:43 -0400)
data/inventory.csv [new file with mode: 0644]
seeds/shop_items.ts
src/shared/inventory.ts

diff --git a/data/inventory.csv b/data/inventory.csv
new file mode 100644 (file)
index 0000000..add61fa
--- /dev/null
@@ -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\r
+Plain Helm,ARMOUR,HELM,Wanderer,3,1,0,0,0,0,0,0,0,0,0,20\r
+Gloves,ARMOUR,ARMS,Wanderer,2,1,0,0,0,0,0,0,0,0,0,20\r
+Tunic,ARMOUR,CHEST,Wanderer,5,1,0,0,0,0,0,0,0,0,0,20\r
+Boots,ARMOUR,LEGS,Wanderer,3,1,0,0,0,0,0,0,0,0,0,20\r
+Short Sword,WEAPON,BLADE,Wanderer,5,1,0,0,0,0,0,0,0,0,3,50\r
index ea9e1085aa015d3532f5dc0d1e9a9735290d5c3a..3b5e2157f2850d2b99fd20baa0f4baf7ba601b70 100644 (file)
@@ -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<void> {
   // Deletes ALL existing entries
@@ -7,88 +13,39 @@ export async function seed(knex: Knex): Promise<void> {
   await knex("equipped").del();
   await knex("inventory").del();
 
-  const data: Partial<ShopItem>[] = [
-    {
-      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<ShopItem, 'id'>[] = [];
+
+  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);
 };
index ffe4c2719c9ba85a305f50646c3cb44d11f8aaf3..0f81a4c2a652e7fcf4436c163e39b056c71a9156 100644 (file)
@@ -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;