Added file saving/loading

main
sigonasr2 3 years ago
parent 004dba7ac1
commit 4680935bbb
  1. 182
      src/backend/data.json
  2. 62
      src/backend/logreader.js
  3. 64
      src/backend/logreader.js.bak

@ -0,0 +1,182 @@
{
"pomander": [
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
1,
1
],
[
0,
0,
0
],
[
0,
0,
0
],
[
0,
5,
5
],
[
0,
0,
0
],
[
0,
1,
1
],
[
0,
0,
0
]
],
"accursed_hoard": [
[
0,
1
],
[
0,
0
],
[
0,
0
],
[
0,
0
]
],
"mimics": [
0,
0
],
"traps": [
[
0,
0
],
[
0,
0
],
[
0,
1
],
[
0,
0
],
[
0,
1
]
],
"floor_effects": [
[
0,
0
],
[
0,
0
],
[
0,
0
],
[
0,
0
],
[
0,
0
],
[
0,
0
],
[
0,
0
],
[
0,
0
],
[
0,
0
],
[
0,
1
],
[
0,
0
]
],
"death_count": [
1,
2
],
"floor": 0,
"accursed_hoard_detected": false,
"previous_pomander": "",
"floor_storage": {}
}

@ -1,4 +1,5 @@
Tail = require('tail').Tail;
const fs = require('fs');
var pomander = [
[0,0,0],
@ -80,9 +81,26 @@ var options = {
var previous_pomander=""
var floor_storage={}
var update_file=false;
tail = new Tail(process.argv[2], options);
if (fs.existsSync('./data.json')) {
var master_obj = JSON.parse(fs.readFileSync('./data.json','utf-8'))
console.log("Loaded data from file...")
console.log(master_obj)
pomander=master_obj.pomander
accursed_hoard=master_obj.accursed_hoard
mimics=master_obj.mimics
traps=master_obj.traps
floor_effects=master_obj.floor_effects
death_count=master_obj.death_count
floor=master_obj.floor
accursed_hoard_detected=master_obj.accursed_hoard_detected
previous_pomander=master_obj.previous_pomander
floor_storage=master_obj.floor_storage
}
function GetPomanderSlot(str) {
for (var i=0;i<POMANDER_NAMES.length;i++) {
@ -100,12 +118,14 @@ function ParseString(str) {
//console.log(split[4])
if (split[4].includes("The coffer...bares its fangs!")) {
mimics[1]++
update_file=true
} else
if (split[4].includes("You use a pomander of ")) {
var pomander_name=split[4].substring("You use a pomander of ".length)
pomander_name=pomander_name.substring(0,pomander_name.length-1)
var pomander_slot = GetPomanderSlot(pomander_name)
pomander[pomander_slot][0]-=1
update_file=true
} else
if (split[4].includes("You cannot carry any more of that item.")) {
var pomander_name=split[4].substring("You return the pomander of ".length)
@ -117,10 +137,12 @@ function ParseString(str) {
} else {
floor_storage[pomander_name]=1
}
previous_pomander=pomander_name
pomander[pomander_slot][1]++
pomander[pomander_slot][2]++
mimics[0]++
}
update_file=true
} else
if (split[4].includes("Floor ")) {
var fl=split[4].substring("Floor ".length)
@ -128,6 +150,7 @@ function ParseString(str) {
previous_pomander=""
floor_storage={}
accursed_hoard_detected=false
update_file=true
} else
if (split[4].includes("0) has begun.")) {
var fl=split[4].substring("The Palace of the Dead (Floors ".length)
@ -136,6 +159,7 @@ function ParseString(str) {
previous_pomander=""
floor_storage={}
accursed_hoard_detected=false
update_file=true
} else
if (split[4].includes("0) has ended.")) {
var fl=split[4].substring("The Palace of the Dead (Floors ".length)
@ -160,26 +184,32 @@ function ParseString(str) {
floor_effects[i][0]=0
}
death_count[1]++
update_file=true
} else
if (split[4].includes("The enfeebling trap is triggered...")) {
traps[ENFEEBLING][0]++
traps[ENFEEBLING][1]++
update_file=true
} else
if (split[4].includes("The toading trap is triggered...")) {
traps[TOADING][0]++
traps[TOADING][1]++
update_file=true
} else
if (split[4].includes("The impeding trap is triggered...")) {
traps[IMPEDING][0]++
traps[IMPEDING][1]++
update_file=true
} else
if (split[4].includes("The luring trap is triggered...")) {
traps[LURING][0]++
traps[LURING][1]++
update_file=true
} else
if (split[4].includes("The landmine is triggered...")) {
traps[LANDMINE][0]++
traps[LANDMINE][1]++
update_file=true
} else
if (split[4].includes("obtains a pomander of ")) {
var pomander_name=split[4].substring(split[4].indexOf("obtains a pomander of ")+"obtains a pomander of ".length)
@ -193,9 +223,11 @@ function ParseString(str) {
pomander[pomander_slot][2]++
mimics[0]++
}
update_file=true
} else
if (split[4].includes("You sense the Accursed Hoard calling you...")) {
accursed_hoard_detected=true
update_file=true
} else
if (split[4].includes("You discover a piece of the Accursed Hoard!")) {
accursed_hoard_detected=false
@ -214,54 +246,84 @@ function ParseString(str) {
accursed_hoard[3][0]++
accursed_hoard[3][1]++
}
update_file=true
} else
if (split[4].includes("You are revived!")) {
death_count[0]++
death_count[1]++
update_file=true
} else
if (split[4].includes("An ancient enchantment stimulates your humours, increasing the speed with which you act.")) {
floor_effects[0][0]++
floor_effects[0][1]++
update_file=true
} else
if (split[4].includes("An ancient enchantment revitalizes your body and mind.")) {
floor_effects[1][0]++
floor_effects[1][1]++
update_file=true
} else
if (split[4].includes("The gathering gloom appears to invigorate the floor's denizens.")) {
floor_effects[2][0]++
floor_effects[2][1]++
update_file=true
} else
if (split[4].includes("An ancient enchantment clouds your eyes, making it difficult to discern your quarry.")) {
floor_effects[3][0]++
floor_effects[3][1]++
update_file=true
} else
if (split[4].includes("The items in your bag have temporarily transformed into worthless stone.")) {
floor_effects[4][0]++
floor_effects[4][1]++
update_file=true
} else
if (split[4].includes("An ancient enchantment clouds your mind, making it impossible to remember previously learned abilities.")) {
floor_effects[5][0]++
floor_effects[5][1]++
update_file=true
} else
if (split[4].includes("An ancient enchantment saps your health.")) {
floor_effects[6][0]++
floor_effects[6][1]++
update_file=true
} else
if (split[4].includes("An ancient enchantment saps your very strength, weakening your blows.")) {
floor_effects[7][0]++
floor_effects[7][1]++
update_file=true
} else
if (split[4].includes("Your body is fatigued and wounds refuse to heal on their own.")) {
floor_effects[8][0]++
floor_effects[8][1]++
update_file=true
} else
if (split[4].includes("Your entire body feels heavy.")) {
floor_effects[9][0]++
floor_effects[9][1]++
update_file=true
} else
if (split[4].includes("You find yourself short of breath, unable to sprint.")) {
floor_effects[10][0]++
floor_effects[10][1]++
update_file=true
}
if (update_file) {
update_file=false
var master_obj = {
pomander:pomander,
accursed_hoard:accursed_hoard,
mimics:mimics,
traps:traps,
floor_effects:floor_effects,
death_count:death_count,
floor:floor,
accursed_hoard_detected:accursed_hoard_detected,
previous_pomander:previous_pomander,
floor_storage:floor_storage,
}
fs.writeFileSync('./data.json', JSON.stringify(master_obj, null, 2) , 'utf-8');
}
}
}

@ -1,4 +1,5 @@
Tail = require('tail').Tail;
const fs = require('fs');
var pomander = [
[0,0,0],
@ -80,9 +81,26 @@ var options = {
var previous_pomander=""
var floor_storage={}
var update_file=false;
tail = new Tail(process.argv[2], options);
if (fs.existsSync('./data.json')) {
var master_obj = JSON.parse(fs.readFileSync('./data.json','utf-8'))
console.log("Loaded data from file...")
console.log(master_obj)
pomander=master_obj.pomander
accursed_hoard=master_obj.accursed_hoard
mimics=master_obj.mimics
traps=master_obj.traps
floor_effects=master_obj.floor_effects
death_count=master_obj.death_count
floor=master_obj.floor
accursed_hoard_detected=master_obj.accursed_hoard_detected
previous_pomander=master_obj.previous_pomander
floor_storage=master_obj.floor_storage
}
function GetPomanderSlot(str) {
for (var i=0;i<POMANDER_NAMES.length;i++) {
@ -100,12 +118,14 @@ function ParseString(str) {
//console.log(split[4])
if (split[4].includes("The coffer...bares its fangs!")) {
mimics[1]++
update_file=true
} else
if (split[4].includes("You use a pomander of ")) {
var pomander_name=split[4].substring("You use a pomander of ".length)
pomander_name=pomander_name.substring(0,pomander_name.length-1)
var pomander_slot = GetPomanderSlot(pomander_name)
pomander[pomander_slot][0]-=1
update_file=true
} else
if (split[4].includes("You cannot carry any more of that item.")) {
var pomander_name=split[4].substring("You return the pomander of ".length)
@ -117,9 +137,12 @@ function ParseString(str) {
} else {
floor_storage[pomander_name]=1
}
previous_pomander=pomander_name
pomander[pomander_slot][1]++
pomander[pomander_slot][2]++
mimics[0]++
}
update_file=true
} else
if (split[4].includes("Floor ")) {
var fl=split[4].substring("Floor ".length)
@ -127,6 +150,7 @@ function ParseString(str) {
previous_pomander=""
floor_storage={}
accursed_hoard_detected=false
update_file=true
} else
if (split[4].includes("0) has begun.")) {
var fl=split[4].substring("The Palace of the Dead (Floors ".length)
@ -135,6 +159,7 @@ function ParseString(str) {
previous_pomander=""
floor_storage={}
accursed_hoard_detected=false
update_file=true
} else
if (split[4].includes("0) has ended.")) {
var fl=split[4].substring("The Palace of the Dead (Floors ".length)
@ -159,26 +184,32 @@ function ParseString(str) {
floor_effects[i][0]=0
}
death_count[1]++
update_file=true
} else
if (split[4].includes("The enfeebling trap is triggered...")) {
traps[ENFEEBLING][0]++
traps[ENFEEBLING][1]++
update_file=true
} else
if (split[4].includes("The toading trap is triggered...")) {
traps[TOADING][0]++
traps[TOADING][1]++
update_file=true
} else
if (split[4].includes("The impeding trap is triggered...")) {
traps[IMPEDING][0]++
traps[IMPEDING][1]++
update_file=true
} else
if (split[4].includes("The luring trap is triggered...")) {
traps[LURING][0]++
traps[LURING][1]++
update_file=true
} else
if (split[4].includes("The landmine is triggered...")) {
traps[LANDMINE][0]++
traps[LANDMINE][1]++
update_file=true
} else
if (split[4].includes("obtains a pomander of ")) {
var pomander_name=split[4].substring(split[4].indexOf("obtains a pomander of ")+"obtains a pomander of ".length)
@ -190,10 +221,13 @@ function ParseString(str) {
} else {
pomander[pomander_slot][1]++
pomander[pomander_slot][2]++
mimics[0]++
}
update_file=true
} else
if (split[4].includes("You sense the Accursed Hoard calling you...")) {
accursed_hoard_detected=true
update_file=true
} else
if (split[4].includes("You discover a piece of the Accursed Hoard!")) {
accursed_hoard_detected=false
@ -212,54 +246,84 @@ function ParseString(str) {
accursed_hoard[3][0]++
accursed_hoard[3][1]++
}
update_file=true
} else
if (split[4].includes("You are revived!")) {
death_count[0]++
death_count[1]++
update_file=true
} else
if (split[4].includes("An ancient enchantment stimulates your humours, increasing the speed with which you act.")) {
floor_effects[0][0]++
floor_effects[0][1]++
update_file=true
} else
if (split[4].includes("An ancient enchantment revitalizes your body and mind.")) {
floor_effects[1][0]++
floor_effects[1][1]++
update_file=true
} else
if (split[4].includes("The gathering gloom appears to invigorate the floor's denizens.")) {
floor_effects[2][0]++
floor_effects[2][1]++
update_file=true
} else
if (split[4].includes("An ancient enchantment clouds your eyes, making it difficult to discern your quarry.")) {
floor_effects[3][0]++
floor_effects[3][1]++
update_file=true
} else
if (split[4].includes("The items in your bag have temporarily transformed into worthless stone.")) {
floor_effects[4][0]++
floor_effects[4][1]++
update_file=true
} else
if (split[4].includes("An ancient enchantment clouds your mind, making it impossible to remember previously learned abilities.")) {
floor_effects[5][0]++
floor_effects[5][1]++
update_file=true
} else
if (split[4].includes("An ancient enchantment saps your health.")) {
floor_effects[6][0]++
floor_effects[6][1]++
update_file=true
} else
if (split[4].includes("An ancient enchantment saps your very strength, weakening your blows.")) {
floor_effects[7][0]++
floor_effects[7][1]++
update_file=true
} else
if (split[4].includes("Your body is fatigued and wounds refuse to heal on their own.")) {
floor_effects[8][0]++
floor_effects[8][1]++
update_file=true
} else
if (split[4].includes("Your entire body feels heavy.")) {
floor_effects[9][0]++
floor_effects[9][1]++
update_file=true
} else
if (split[4].includes("You find yourself short of breath, unable to sprint.")) {
floor_effects[10][0]++
floor_effects[10][1]++
update_file=true
}
if (update_file) {
update_file=false
var master_obj = {
pomander:pomander,
accursed_hoard:accursed_hoard,
mimics:mimics,
traps:traps,
floor_effects:floor_effects,
death_count:death_count,
floor:floor,
accursed_hoard_detected:accursed_hoard_detected,
previous_pomander:previous_pomander,
floor_storage:floor_storage,
}
fs.writeFileSync('./data.json', JSON.stringify(master_obj, null, 2) , 'utf-8');
}
}
}

Loading…
Cancel
Save