commit 579dfc40d9b829048f5ccfc6670fa21511c2c646 Author: Marty Sluijtman Date: Fri Aug 19 18:09:05 2022 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d826fce --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +sheet-parser diff --git a/README.md b/README.md new file mode 100644 index 0000000..4dde18b --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Sheet Parser + +An attempt at creating a system for (at the monent) parsing JSON D&D character sheets. diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..4557712 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module gitlab.com/EternalWanderer/sheet-parser/v2 + +go 1.19 + +require gitlab.com/EternalWanderer/dice-roller v0.0.0-20220819131953-2d560c42a087 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..ab9da5a --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +gitlab.com/EternalWanderer/dice-roller v0.0.0-20220819100404-bed2f3df016e h1:pPt+f195MjWCtUITpZ65rNB/X+M9S3UiP8A1jCSwiXQ= +gitlab.com/EternalWanderer/dice-roller v0.0.0-20220819100404-bed2f3df016e/go.mod h1:SNEEOhMarhxX2gBUZ4RIDgEvlKaZorPKfhaqpD09/bs= +gitlab.com/EternalWanderer/dice-roller v0.0.0-20220819131953-2d560c42a087 h1:0UCn74xm94G26W+6/LNb+Zc2dFFHKVgCVhVgam4zw/A= +gitlab.com/EternalWanderer/dice-roller v0.0.0-20220819131953-2d560c42a087/go.mod h1:SNEEOhMarhxX2gBUZ4RIDgEvlKaZorPKfhaqpD09/bs= diff --git a/main.go b/main.go new file mode 100644 index 0000000..1a42ff4 --- /dev/null +++ b/main.go @@ -0,0 +1,67 @@ +package main + +import ( + "encoding/json" + "flag" + "fmt" + "io/ioutil" + "math/rand" + "os" + "time" + + "gitlab.com/EternalWanderer/dice-roller/Dice" +) + +var ( + path string + modifier, diceThrows, surfaces int + char Character +) + +func isError(err error) bool { + if err != nil { + fmt.Println(err.Error()) + } + return (err != nil) +} +func parseFlags() { + flag.StringVar(&path, "file", "stats.json", "fock me") + flag.Parse() +} + +func readJson() { + fmt.Println("Opening file...", path) + var file, err = os.Open(path) + if isError(err) { + return + } + defer file.Close() + + byteValue, _ := ioutil.ReadAll(file) + json.Unmarshal(byteValue, &char) +} + +func main() { + rand.Seed(time.Now().Unix()) + parseFlags() + readJson() + + Dice.SimpleCast() + charismaChecks() +} + +func charismaChecks() { + die := Dice.SimpleCast() + proficiencyScore := char.Misc.Proficiency + expertiseScore := char.Misc.Proficiency * 2 + fmt.Println("proficiencyScore:", proficiencyScore) + fmt.Println("expertiseScore:", expertiseScore) + fmt.Println("die:", die) + if char.Skills.Charisma.Intimidation.Expertise { + fmt.Printf("%s's Intimidation check results in %d\n", char.Misc.Name, die+char.Skills.Charisma.Intimidation.Modifier+expertiseScore) + fmt.Printf("After all, %s has expertise in intimidation\n", char.Misc.Name) + } else if char.Skills.Charisma.Intimidation.Proficient { + fmt.Printf("%s's Intimidation check results in %d\n", char.Misc.Name, die+char.Skills.Charisma.Intimidation.Modifier+proficiencyScore) + fmt.Printf("After all, %s is proficient with intimidation\n", char.Misc.Name) + } +} diff --git a/sheetContent.go b/sheetContent.go new file mode 100644 index 0000000..ab139f4 --- /dev/null +++ b/sheetContent.go @@ -0,0 +1,160 @@ +package main + +type Acrobatics struct { + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Expertise bool `json:"expertise"` +} +type Animal_handling struct { + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Expertise bool `json:"expertise"` +} +type Arcana struct { + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Expertise bool `json:"expertise"` +} +type Athletics struct { + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Expertise bool `json:"expertise"` +} +type Character struct { + Misc Misc `json:"misc"` + Stats Stats `json:"stats"` + Skills Skills `json:"skills"` +} +type Charisma struct { + Score int `json:"score"` + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Deception Deception `json:"deception"` + Intimidation Intimidation `json:"intimidation"` + Performance Performance `json:"performance"` + Persuasion Persuasion `json:"persuasion"` +} +type Constitution struct { + Score int `json:"score"` + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` +} +type Deception struct { + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Expertise bool `json:"expertise"` +} +type Dexterity struct { + Score int `json:"score"` + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Acrobatics Acrobatics `json:"acrobatics"` + Sleight_of_hand Sleight_of_hand `json:"sleight_of_hand"` + Stealth Stealth `json:"stealth"` +} +type History struct { + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Expertise bool `json:"expertise"` +} +type Insight struct { + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Expertise bool `json:"expertise"` +} +type Intelligence struct { + Score int `json:"score"` + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Arcana Arcana `json:"arcana"` + History History `json:"history"` + Investigation Investigation `json:"investigation"` + Nature Nature `json:"nature"` + Religion Religion `json:"religion"` +} +type Intimidation struct { + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Expertise bool `json:"expertise"` +} +type Investigation struct { + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Expertise bool `json:"expertise"` +} +type Medicine struct { + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Expertise bool `json:"expertise"` +} +type Misc struct { + Proficiency int `json:"proficiency"` + Inspiration int `json:"inspiration"` + Level int `json:"level"` + Name string `json:"name"` +} +type Nature struct { + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Expertise bool `json:"expertise"` +} +type Performance struct { + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Expertise bool `json:"expertise"` +} +type Persuasion struct { + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Expertise bool `json:"expertise"` +} +type Religion struct { + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Expertise bool `json:"expertise"` +} +type Skills struct { + Strength Strength `json:"strength"` + Dexterity Dexterity `json:"dexterity"` + Intelligence Intelligence `json:"intelligence"` + Wisdom Wisdom `json:"wisdom"` + Charisma Charisma `json:"charisma"` +} +type Sleight_of_hand struct { + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Expertise bool `json:"expertise"` +} +type Stats struct { + Strength Strength `json:"strength"` + Dexterity Dexterity `json:"dexterity"` + Constitution Constitution `json:"constitution"` + Intelligence Intelligence `json:"intelligence"` + Wisdom Wisdom `json:"wisdom"` + Charisma Charisma `json:"charisma"` +} +type Stealth struct { + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Expertise bool `json:"expertise"` +} +type Strength struct { + Score int `json:"score"` + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Athletics Athletics `json:"athletics"` +} +type Survival struct { + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Expertise bool `json:"expertise"` +} +type Wisdom struct { + Score int `json:"score"` + Modifier int `json:"modifier"` + Proficient bool `json:"proficient"` + Animal_handling Animal_handling `json:"animal_handling"` + Insight Insight `json:"insight"` + Medicine Medicine `json:"medicine"` + Survival Survival `json:"survival"` +} diff --git a/stats.json b/stats.json new file mode 100644 index 0000000..3fbf8f4 --- /dev/null +++ b/stats.json @@ -0,0 +1,45 @@ +{ + "misc":{ + "proficiency": 3, + "inspiration": 0, + "level": 0, + "name": "Bob" + }, + "stats":{ + "strength": { "score":10, "modifier":0, "proficient":false }, + "dexterity": { "score":10, "modifier":0, "proficient":false }, + "constitution": { "score":10, "modifier":0, "proficient":false }, + "intelligence": { "score":10, "modifier":0, "proficient":false }, + "wisdom": { "score":10, "modifier":0, "proficient":false }, + "charisma": { "score":10, "modifier":0, "proficient":false } + }, + "skills":{ + "strength":{ + "athletics": {"modifier":123, "proficient":false, "expertise":false } + }, + "dexterity":{ + "acrobatics": {"modifier":0, "proficient":false, "expertise":false }, + "sleight-of-hand": {"modifier":0, "proficient":false, "expertise":false }, + "stealth": {"modifier":0, "proficient":false, "expertise":false } + }, + "intelligence":{ + "arcana": {"modifier":0, "proficient":false, "expertise":false }, + "history": {"modifier":0, "proficient":false, "expertise":false }, + "investigation": {"modifier":0, "proficient":false, "expertise":false }, + "nature": {"modifier":0, "proficient":false, "expertise":false }, + "religion": {"modifier":0, "proficient":false, "expertise":false } + }, + "wisdom":{ + "animal-handling": {"modifier":0, "proficient":false, "expertise":false }, + "insight": {"modifier":0, "proficient":false, "expertise":false }, + "medicine": {"modifier":0, "proficient":false, "expertise":false }, + "survival": {"modifier":0, "proficient":false, "expertise":false } + }, + "charisma":{ + "deception": {"modifier":0, "proficient":false, "expertise":false }, + "intimidation": {"modifier":0, "proficient":false, "expertise":true }, + "performance": {"modifier":0, "proficient":true, "expertise":false }, + "persuasion": {"modifier":0, "proficient":false, "expertise":false } + } + } +}