I feel like fixing this, gonna take a few days.

This commit is contained in:
Elliott Pardee 2015-06-05 23:07:18 -04:00
parent 42cce3824c
commit 3eb0d72ede

View File

@ -2,14 +2,59 @@
package main package main
import ( import (
"github.com/antonholmquist/jason" "encoding/json"
"io/ioutil" "io/ioutil"
"os" "os"
"strconv" "strconv"
"strings" "strings"
) )
var charmap map[string]*jason.Object type Character struct {
irc string
personal PersonalData
equipment EquipmentData
stats StatData
wealth WealthData
}
type PersonalData struct {
name string
lvl int
race string
xp int
height int
alignment string
classes []string
weight int
sex string
hp int
ac int
age int
}
type EquipmentData struct {
armour []string
weapons []string
items []string
missiles []string
}
type StatData struct {
con int
str int
intl int
cha int
wis int
dex int
}
type WealthData struct {
coins int
other []string
gems []string
}
var charmap map[string]*Character
func importChar(nick string) bool { func importChar(nick string) bool {
file, err := ioutil.ReadFile("json/" + nick + ".json") file, err := ioutil.ReadFile("json/" + nick + ".json")
@ -18,10 +63,12 @@ func importChar(nick string) bool {
return false return false
} }
char, _ := jason.NewObjectFromBytes(file) var char Character
json.Unmarshal(file, char)
charmap = map[string]*jason.Object{ charmap = map[string]*jason.Object{
nick: char, char.irc: char,
} }
return true return true
@ -31,19 +78,33 @@ func printChar(nick string, cat string, scat string, item string) string {
if _, err := os.Stat("json/" + nick + ".json"); os.IsNotExist(err) { if _, err := os.Stat("json/" + nick + ".json"); os.IsNotExist(err) {
return "does not exist" return "does not exist"
} }
var fixedCat string
switch (cat) {
case "personal":
fixedCat = "PersonalData"
break
case "equipment":
fixedCat = "EquipmentData"
break
case "stats":
fixedCat = "StatData"
break
case "wealth":
fixedCat = "WealthData"
break
case "nil":
fixedCat = "nil"
break
default:
return "invalid category"
}
if scat == "nil" { if scat == "nil" {
test, _ := charmap[nick].GetString(cat, item) return charmap[nick].fixedCat.
if len(test) == 0 {
val, _ := charmap[nick].GetInt64(cat, item)
return strconv.FormatInt(val, 10)
} else {
val, _ := charmap[nick].GetString(cat, item)
return val
}
return "does not exist"
} else { } else {
test, _ := charmap[nick].GetString(cat, scat, item) test, _ := charmap[nick].GetString(cat, scat, item)