mirror of
https://gitlab.com/EternalWanderer/sheet-parser.git
synced 2024-11-28 21:13:51 +01:00
Spell list logic and reformat of JSON
This commit is contained in:
parent
09248c4e63
commit
d4162eab2b
56
example.json
56
example.json
|
@ -15,39 +15,39 @@
|
|||
"isKurthog": false
|
||||
},
|
||||
"stats":[
|
||||
{"statName":"strength", "score":20, "proficient":false, "saveProficient":false },
|
||||
{"statName":"dexterity", "score":1, "proficient":false, "saveProficient":false },
|
||||
{"statName":"constitution", "score":15, "proficient":false, "saveProficient":false },
|
||||
{"statName":"intelligence", "score":10, "proficient":false, "saveProficient":false },
|
||||
{"statName":"wisdom", "score":10, "proficient":false, "saveProficient":false },
|
||||
{"statName":"charisma", "score":10, "proficient":false, "saveProficient":false }
|
||||
{"name":"strength", "score":20, "proficient":false, "saveProficient":false },
|
||||
{"name":"dexterity", "score":1, "proficient":false, "saveProficient":false },
|
||||
{"name":"constitution", "score":15, "proficient":false, "saveProficient":false },
|
||||
{"name":"intelligence", "score":10, "proficient":false, "saveProficient":false },
|
||||
{"name":"wisdom", "score":10, "proficient":false, "saveProficient":false },
|
||||
{"name":"charisma", "score":10, "proficient":false, "saveProficient":false }
|
||||
],
|
||||
"skills":[
|
||||
{"skillName":"athletics", "proficient":true, "expertise":false, "baseStat":"strength"},
|
||||
{"skillName":"acrobatics", "proficient":false, "expertise":false, "baseStat":"dexterity"},
|
||||
{"skillName":"sleight_of_hand", "proficient":false, "expertise":false, "baseStat":"dexterity"},
|
||||
{"skillName":"stealth", "proficient":false, "expertise":false, "baseStat":"dexterity"},
|
||||
{"skillName":"arcana", "proficient":false, "expertise":false, "baseStat":"intelligence"},
|
||||
{"skillName":"history", "proficient":false, "expertise":false, "baseStat":"intelligence"},
|
||||
{"skillName":"investigation", "proficient":false, "expertise":false, "baseStat":"intelligence"},
|
||||
{"skillName":"nature", "proficient":false, "expertise":false, "baseStat":"intelligence"},
|
||||
{"skillName":"religion", "proficient":false, "expertise":false, "baseStat":"intelligence"},
|
||||
{"skillName":"animal_handling", "proficient":false, "expertise":false, "baseStat":"wisdom"},
|
||||
{"skillName":"insight", "proficient":false, "expertise":false, "baseStat":"wisdom"},
|
||||
{"skillName":"medicine", "proficient":false, "expertise":false, "baseStat":"wisdom"},
|
||||
{"skillName":"perception", "proficient":false, "expertise":false, "baseStat":"wisdom"},
|
||||
{"skillName":"survival", "proficient":false, "expertise":false, "baseStat":"wisdom"},
|
||||
{"skillName":"deception", "proficient":false, "expertise":false, "baseStat":"charisma"},
|
||||
{"skillName":"intimidation", "proficient":false, "expertise":true, "baseStat":"charisma"},
|
||||
{"skillName":"performance", "proficient":true, "expertise":false, "baseStat":"charisma"},
|
||||
{"skillName":"persuasion", "proficient":false, "expertise":false, "baseStat":"charisma"}
|
||||
{"name":"athletics", "proficient":true, "expertise":false, "baseStat":"strength"},
|
||||
{"name":"acrobatics", "proficient":false, "expertise":false, "baseStat":"dexterity"},
|
||||
{"name":"sleight_of_hand", "proficient":false, "expertise":false, "baseStat":"dexterity"},
|
||||
{"name":"stealth", "proficient":false, "expertise":false, "baseStat":"dexterity"},
|
||||
{"name":"arcana", "proficient":false, "expertise":false, "baseStat":"intelligence"},
|
||||
{"name":"history", "proficient":false, "expertise":false, "baseStat":"intelligence"},
|
||||
{"name":"investigation", "proficient":false, "expertise":false, "baseStat":"intelligence"},
|
||||
{"name":"nature", "proficient":false, "expertise":false, "baseStat":"intelligence"},
|
||||
{"name":"religion", "proficient":false, "expertise":false, "baseStat":"intelligence"},
|
||||
{"name":"animal_handling", "proficient":false, "expertise":false, "baseStat":"wisdom"},
|
||||
{"name":"insight", "proficient":false, "expertise":false, "baseStat":"wisdom"},
|
||||
{"name":"medicine", "proficient":false, "expertise":false, "baseStat":"wisdom"},
|
||||
{"name":"perception", "proficient":false, "expertise":false, "baseStat":"wisdom"},
|
||||
{"name":"survival", "proficient":false, "expertise":false, "baseStat":"wisdom"},
|
||||
{"name":"deception", "proficient":false, "expertise":false, "baseStat":"charisma"},
|
||||
{"name":"intimidation", "proficient":false, "expertise":true, "baseStat":"charisma"},
|
||||
{"name":"performance", "proficient":true, "expertise":false, "baseStat":"charisma"},
|
||||
{"name":"persuasion", "proficient":false, "expertise":false, "baseStat":"charisma"}
|
||||
],
|
||||
"spells":[
|
||||
{"spellName":"Eldritch Blast", "level":0, "castingTime":"1 Action", "range": 120, "components":"v,s", "duration":"Instantaneous","attack_save":"Ranged", "damage_effect":"Force"},
|
||||
{"spellName":"Eldritch Blast", "castingTime":"1 Action", "range": 120, "components":"v,s", "duration":"Instantaneous","attack_save":"Ranged", "damage_effect":"Force"}
|
||||
{"name":"Eldritch Blast", "level":0, "castingTime":"1 Action", "range": 120, "components":"v,s", "duration":"Instantaneous","attack_save":"Ranged", "damage_effect":"Force", "school":"Evocation", "description":"A beam of crackling energy streaks toward a creature within range. Make a ranged spell attack against the target. On a hit, the target takes 1d10 force damage."},
|
||||
{"name":"Absorb Elements", "level":1, "castingTime":"1 Reaction", "range": 0, "components":"s", "duration":"1 Round","attack_save":"None", "damage_effect":"The Absorbed effect", "school":"Abjuration", "description":"The spell captures some of the incoming energy, lessening its effect on you and storing it for your next melee attack. You have resistance to the triggering damage type until the start of your next turn. Also, the first time you hit with a melee attack on your next turn, the target takes an extra 1d6 damage of the triggering type, and the spell ends."}
|
||||
],
|
||||
"feats":[
|
||||
{"featName":"Boring", "featDescription":"Due to being excessivly generic, Bob gains... something"},
|
||||
{"featName":"Test Dummy", "featDescription":"As the test dummy for this project, you gain the ability to use things from other classes willy nilly."}
|
||||
{"name":"Boring", "description":"Due to being excessivly generic, Bob gains... something"},
|
||||
{"name":"Test Dummy", "description":"As the test dummy for this project, you gain the ability to use things from other classes willy nilly."}
|
||||
]
|
||||
}
|
||||
|
|
66
main.go
66
main.go
|
@ -16,13 +16,13 @@ import (
|
|||
const exampleFile string = "/etc/sheet-parser/example.json"
|
||||
|
||||
var (
|
||||
path, pathFlag, skillString, saveString, statString string
|
||||
modifier, diceThrows, surfaces int
|
||||
X, Y int
|
||||
char Character
|
||||
skillMap = make(map[string]int)
|
||||
statMap = make(map[string]int)
|
||||
advantage, disadvantage, stat_list, skill_list, verbose, trivia, feats bool
|
||||
path, pathFlag, skillString, saveString, statString string
|
||||
modifier, diceThrows, surfaces int
|
||||
X, Y int
|
||||
char Character
|
||||
skillMap = make(map[string]int)
|
||||
statMap = make(map[string]int)
|
||||
advantage, disadvantage, stat_list, skill_list, verbose, trivia, spells, feats bool
|
||||
)
|
||||
|
||||
func parseFlags() {
|
||||
|
@ -43,6 +43,8 @@ func parseFlags() {
|
|||
flag.BoolVar(&trivia, "t", false, "Print character name, level and proficiency")
|
||||
flag.BoolVar(&trivia, "trivia", false, "Print character name, level and proficiency")
|
||||
|
||||
flag.BoolVar(&spells, "spells", false, "Print spells")
|
||||
|
||||
flag.BoolVar(&feats, "feats", false, "Print character feats")
|
||||
|
||||
flag.Parse()
|
||||
|
@ -80,11 +82,11 @@ func readJson() {
|
|||
|
||||
func initMaps() {
|
||||
for i := 0; i < len(char.Skills); i++ {
|
||||
skillMap[char.Skills[i].SkillName] = i
|
||||
skillMap[char.Skills[i].Name] = i
|
||||
}
|
||||
|
||||
for i := 0; i < len(char.Stats); i++ {
|
||||
statMap[char.Stats[i].StatName] = i
|
||||
statMap[char.Stats[i].Name] = i
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,7 +103,7 @@ func main() {
|
|||
|
||||
fmt.Printf("\n")
|
||||
|
||||
fmt.Printf("Personality trait: %s\n", char.Misc.PersonalityTrait)
|
||||
fmt.Printf("Personality traits: %s\n", char.Misc.PersonalityTrait)
|
||||
fmt.Printf("Ideals: %s\n", char.Misc.Ideals)
|
||||
fmt.Printf("Bonds: %s\n", char.Misc.Bonds)
|
||||
fmt.Printf("Flaws: %s\n", char.Misc.Flaws)
|
||||
|
@ -115,6 +117,9 @@ func main() {
|
|||
case feats:
|
||||
listFeats()
|
||||
|
||||
case spells:
|
||||
listSpells(verbose)
|
||||
|
||||
case stat_list && skill_list:
|
||||
printStatList(verbose)
|
||||
printSkillList(verbose)
|
||||
|
@ -257,7 +262,7 @@ func badCheck(errorMessage string, err error) {
|
|||
|
||||
func statErrorCheck() error {
|
||||
for i := 0; i < len(char.Stats); i++ {
|
||||
if statString == char.Stats[i].StatName || saveString == char.Stats[i].StatName {
|
||||
if statString == char.Stats[i].Name || saveString == char.Stats[i].Name {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -266,7 +271,7 @@ func statErrorCheck() error {
|
|||
|
||||
func skillErrorCheck() error {
|
||||
for i := 0; i < len(char.Skills); i++ {
|
||||
if skillString == char.Skills[i].SkillName {
|
||||
if skillString == char.Skills[i].Name {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -335,7 +340,7 @@ func printStatList(verbose bool) {
|
|||
if verbose {
|
||||
var proficiency string
|
||||
for i := 0; i < len(char.Stats); i++ {
|
||||
name := char.Stats[i].StatName
|
||||
name := char.Stats[i].Name
|
||||
isProficient := char.Stats[i].Proficient
|
||||
if isProficient {
|
||||
proficiency = "Proficient"
|
||||
|
@ -347,7 +352,7 @@ func printStatList(verbose bool) {
|
|||
}
|
||||
} else {
|
||||
for i := 0; i < len(char.Stats); i++ {
|
||||
fmt.Println(char.Stats[i].StatName)
|
||||
fmt.Println(char.Stats[i].Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -358,7 +363,7 @@ func printSkillList(verbose bool) {
|
|||
var expertise string
|
||||
if verbose {
|
||||
for i := 0; i < len(char.Skills); i++ {
|
||||
name := char.Skills[i].SkillName
|
||||
name := char.Skills[i].Name
|
||||
localModifier := GetModifier(GetStat(char.Skills[i].BaseStat))
|
||||
if char.Skills[i].Proficient {
|
||||
proficiency = "Proficient"
|
||||
|
@ -376,7 +381,7 @@ func printSkillList(verbose bool) {
|
|||
}
|
||||
} else {
|
||||
for i := 0; i < len(char.Skills); i++ {
|
||||
fmt.Println(char.Skills[i].SkillName)
|
||||
fmt.Println(char.Skills[i].Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -384,6 +389,33 @@ func printSkillList(verbose bool) {
|
|||
func listFeats() {
|
||||
color.Magenta("Listing feats...")
|
||||
for i := 0; i < len(char.Feats); i++ {
|
||||
fmt.Printf("%25s\t%s\n", char.Feats[i].FeatName, char.Feats[i].FeatDescription)
|
||||
fmt.Printf("%25s\t%s\n", char.Feats[i].Name, char.Feats[i].Description)
|
||||
}
|
||||
}
|
||||
|
||||
func listSpells(verbose bool) {
|
||||
color.Magenta("Listing spells...")
|
||||
for i := 0; i < len(char.Spells); i++ {
|
||||
fmt.Printf("Name: %s\t%s\n", char.Spells[i].Name, spellLevel(char.Spells[i].Level))
|
||||
fmt.Printf("Casting Time: %s\tRange: %dft\n", char.Spells[i].CastingTime, char.Spells[i].Range)
|
||||
fmt.Printf("Components: %s\t\tDuration: %s\n", char.Spells[i].Components, char.Spells[i].Duration)
|
||||
fmt.Printf("Attack/Save: %s\tDamage/Effect: %s\n", char.Spells[i].Attack_Save, char.Spells[i].Damage_Effect)
|
||||
|
||||
if verbose {
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("%s\n", char.Spells[i].Description)
|
||||
}
|
||||
// hack for string formatting
|
||||
if len(char.Spells) != (i + 1) {
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func spellLevel(spellLevel int) string {
|
||||
if spellLevel == 0 {
|
||||
return "Cantrip"
|
||||
} else {
|
||||
return fmt.Sprintf("Level: %d", spellLevel)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ type Character struct {
|
|||
Misc Misc `json:"misc"`
|
||||
Stats []Stat `json:"stats"`
|
||||
Skills []Skill `json:"skills"`
|
||||
Spells []Spell `json:"spells"`
|
||||
Feats []Feat `json:"feats"`
|
||||
}
|
||||
|
||||
|
@ -25,21 +26,21 @@ type Misc struct {
|
|||
}
|
||||
|
||||
type Skill struct {
|
||||
SkillName string `json:"skillName"`
|
||||
Name string `json:"name"`
|
||||
Proficient bool `json:"proficient"`
|
||||
Expertise bool `json:"expertise"`
|
||||
BaseStat string `json:"baseStat"`
|
||||
}
|
||||
|
||||
type Stat struct {
|
||||
StatName string `json:"statName"`
|
||||
Name string `json:"name"`
|
||||
Score int `json:"score"`
|
||||
Proficient bool `json:"proficient"`
|
||||
SaveProficient bool `json:"saveProficient"`
|
||||
}
|
||||
|
||||
type Spell struct {
|
||||
SpellName string `json:"spellName"`
|
||||
Name string `json:"name"`
|
||||
Level int `json:"level"`
|
||||
CastingTime string `json:"castingTime"`
|
||||
Range int `json:"range"`
|
||||
|
@ -47,9 +48,10 @@ type Spell struct {
|
|||
Duration string `json:"duration"`
|
||||
Attack_Save string `json:"attack_save"`
|
||||
Damage_Effect string `json:"damage_effect"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
type Feat struct {
|
||||
FeatName string `json:"featName"`
|
||||
FeatDescription string `json:"featDescription"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue