Browse Source

initial

master
stryan 2 months ago
parent
commit
f99c7118e1
  1. 9
      card_config.go
  2. 166
      cards.json
  3. 12
      go.mod
  4. 12
      go.sum
  5. 79
      main.go

9
card_config.go

@ -0,0 +1,9 @@
package main
type CardConfig struct {
CodeName string `json:"codename"`
Name string `json:"name,omitempty"`
Rank int `json:'rank'`
ImageURI string `json:"image_uri"`
Flavour string `json:"flavour"`
}

166
cards.json

@ -0,0 +1,166 @@
[
{
"codename":"Valk",
"name":"Valkyrie",
"rank":1,
"image_uri":"https://static.wikia.nocookie.net/namco/images/e/e6/Valkyrie_-_PXZ2.png/revision/latest/scale-to-width-down/1000?cb=20200325214913",
"flavour":"Even the gods may die"
},
{
"codename":"Speedster",
"rank":1,
"image_uri":"https://pm1.narvii.com/6802/6f2224f6cc51736c356a23cf478f8f113c0939c1v2_hq.jpg",
"flavour":"He's one speedy boy"
},
{
"codename":"Commander",
"rank":2,
"image_uri":"https://static.wikia.nocookie.net/tower-defense-sim/images/9/9f/GalacticCommanderIcon.png/revision/latest/scale-to-width-down/300?cb=20210710195229",
"flavour":"Compassion is a rarity on the battlefield"
},
{
"codename":"Paladin",
"rank":3,
"image_uri":"www.oocities.org/war3squad/images/human/heroes/paladin.jpg",
"flavour":"His faith will be his allies shield"
},
{
"codename":"Scholar",
"rank":4,
"image_uri":"http://4.bp.blogspot.com/-MARzt9MIdyw/Un41mM4IX7I/AAAAAAAADzI/dMx68OMcIRY/s1600/godfrey-kneller-a-scholar-in-his-study.jpg",
"flavour":"Her wisdom is envied by all"
},
{
"codename":"Warrior",
"rank":5,
"image_uri":"http://2.bp.blogspot.com/-q9NXuKWMxIE/UVIbfWKEiAI/AAAAAAAAAFo/K6YXuM_5Dbg/s1600/Knight+lady+white+battler.png",
"flavour":"A stalwart friend in times of need"
},
{
"codename":"Fighter",
"rank":6,
"image_uri":"https://www.arcadequartermaster.com/capcom/sfa2/sfa2_ryu1.gif",
"flavour":"From the deepest pits he climbed to victory"
},
{
"codename":"Seven",
"name":"Seven",
"rank":7,
"image_uri":"https://botw-pd.s3.amazonaws.com/styles/logo-thumbnail/s3/052018/untitled-1_135.png?v63ecHVYxcp6E2nfD8iaDqZpsnUaKoEP&itok=0Ayzi_J2",
"flavour":"Seven"
},
{
"codename":"ShieldWall",
"rank":8,
"image_uri":"https://i.imgflip.com/2/1ii9tn.jpg",
"flavour":"Together we stand"
},
{
"codename":"HealthPotion",
"rank":1,
"image_uri":"https://bloodstainedritualofthenight.wiki.fextralife.com/file/Bloodstained-Ritual-of-The-Night/high-potion-bloodstained-ritual-of-the-night-wiki-guide.png",
"flavour":"Bottoms up!"
},
{
"codename":"Tree",
"rank":1,
"image_uri":"https://static.wikia.nocookie.net/dota2_gamepedia/images/3/3f/Treant_Protector_icon.png/revision/latest/scale-to-width-down/256?cb=20160411210417",
"flavour":"Trees can be ferocious if provoked"
},
{
"codename":"Goblin",
"rank":1,
"image_uri":"https://dmdave.com/wp-content/uploads/2020/02/shadow-goblin.png",
"flavour":"Nasty, filthy little buggers"
},
{
"codename":"Chupacabra",
"rank":1,
"image_uri":"https://c1.scryfall.com/file/scryfall-cards/art_crop/front/f/4/f4846664-4463-4521-bb3f-3a4d00fa418d.jpg",
"flavour":"Opening the crypt unleashed more horrors than just the her"
},
{
"codename":"Ally",
"rank":2,
"image_uri":"https://media-5.eldoradofurniture.com/images/products/marketing/2018-12/DRESSER%2DALLY%2DWHITE%2DEL%2DDORADO%2DFURNITURE%2D15%2D300723010%2D012%5FMEDIUM%2EJPG",
"flavour":"A helping hand"
},
{
"codename":"Enemy",
"rank":2,
"image_uri":"https://ms.yugipedia.com/e/ea/EOJ-BoosterEN.png",
"flavour":"A hurtful foot"
},
{
"codename":"Duelist",
"rank":3,
"image_uri":"https://vignette.wikia.nocookie.net/aura-kingdom/images/2/22/JPAK_Duelist.png/revision/latest/scale-to-width-down/147?cb=20170518191446",
"flavour":"Haha, riposte!"
},
{
"codename":"Bureaucrat",
"rank":3,
"image_uri":"http://static1.wikia.nocookie.net/__cb20090720232813/en.futurama/images/d/d6/Bureaucrats.jpg",
"flavour":"Sign here, initial here, and we'll get you the next document in oh, six to eight weeks."
},
{
"codename":"Vanguard",
"rank":4,
"image_uri":"https://static2.mtgarena.pro/mtg/pict/adanto-vanguard-art-mtga.png",
"flavour":"In the name of the queen!"
},
{
"codename":"Student",
"rank":4,
"image_uri":"http://images.clipartpanda.com/grade-clipart-TN_student-showing-his-good-grade.jpg",
"flavour":"Just pour the coffee into my eyes, thanks"
},
{
"codename":"Librarian",
"rank":4,
"image_uri":"http://cdn.xl.thumbs.canstockphoto.com/canstock43150378.jpg",
"flavour":"Shh!"
},
{
"codename":"Elephant",
"rank":5,
"image_uri":"http://images6.fanpop.com/image/photos/33600000/Double-icon-skullgirls-33648932-160-160.png",
"flavour":"We are rich and we're not going to take it anymore"
},
{
"codename":"Mesmerist",
"rank":6,
"image_uri":"https://www.chessvariants.com/mvopponent.dir/mesmerist.gif",
"flavour":"He'll let you see the world"
},
{
"codename":"Diviner",
"rank":6,
"image_uri":"https://static1.cards-capital.com/64786-product/diviner-of-the-herald.jpg",
"flavour":"She'll take whatever you've got to see the future"
},
{
"codename":"Hologram",
"rank":8,
"image_uri":"https://rimstar.org/science_electronics_projects/hologram_pyramid_diy_homemade/princess_leia_hologram_side_3.jpg",
"flavour":"Sometimes you just need to buy some time"
},
{
"codename":"GoblinSpawn",
"rank":0,
"image_uri":"https://photos.gograph.com/thumbs/CSP/CSP040/k23877435.jpg",
"flavour":"And there's always more of them"
},
{
"codename":"Dud",
"rank":0,
"image_uri":"http://img.tfd.com/wn/35/66720-dud.png",
"flavour":":("
},
{
"codename":"Clog",
"rank":0,
"image_uri":"http://sr.photos1.fotosearch.com/bthumb/CSP/CSP990/k10380680.jpg",
"flavour":"And sign here"
}
]

12
go.mod

@ -0,0 +1,12 @@
module git.saintnet.tech/tomecraft/library
go 1.17
require (
git.saintnet.tech/tomecraft/tome_lib v0.1.3
github.com/gorilla/mux v1.8.0
)
require github.com/google/uuid v1.3.0 // indirect
replace git.saintnet.tech/tomecraft/tome_lib => ../tome_lib

12
go.sum

@ -0,0 +1,12 @@
github.com/alvaroloes/enumer v1.1.2/go.mod h1:FxrjvuXoDAx9isTJrv4c+T410zFi0DtXIT0m65DJ+Wo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/pascaldekloe/name v0.0.0-20180628100202-0fd16699aae1/go.mod h1:eD5JxqMiuNYyFNmyY9rkJ/slN8y59oEu4Ei7F8OoKWQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190524210228-3d17549cdc6b/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=

79
main.go

@ -0,0 +1,79 @@
package main
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
"strconv"
"git.saintnet.tech/tomecraft/tome_lib"
"github.com/gorilla/mux"
)
type CardDB map[tome_lib.CardType]*tome_lib.CardView
func main() {
db := LoadCards("cards.json")
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/", homePage).Methods("GET")
router.HandleFunc("/card/{id}", db.lookupCard).Methods("GET")
log.Fatal(http.ListenAndServe(":7637", router))
}
func homePage(res http.ResponseWriter, req *http.Request) {
json.NewEncoder(res).Encode(nil)
}
func (c *CardDB) lookupCard(res http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
id, err := strconv.Atoi(vars["id"])
if err != nil {
log.Printf("Error: tryied to look up a non int:%v", err)
http.Error(res, "Bad request - need to lookup an int", 400)
return
}
card, ok := (*c)[tome_lib.CardType(id)]
if !ok {
http.Error(res, "Bad request - no such card", 404)
return
}
json.NewEncoder(res).Encode(card)
}
func LoadCards(file string) CardDB {
content, err := ioutil.ReadFile(file) // the file is inside the local directory
if err != nil {
log.Println("couldn't load file")
log.Fatal(err)
}
var cardConfs []*CardConfig
err = json.Unmarshal([]byte(content), &cardConfs)
if err != nil {
log.Println("Couldn't load json")
log.Fatal(err)
}
cardDB := make(CardDB)
for _, v := range cardConfs {
t, err := tome_lib.CardTypeString(v.CodeName)
if err != nil {
log.Println("Invalid card imported")
log.Fatal(err)
}
cardDB[t] = &tome_lib.CardView{
Name: "",
Type: int(t),
Rank: v.Rank,
ImageURI: v.ImageURI,
Flavour: v.Flavour,
}
if v.Name == "" {
cardDB[t].Name = v.CodeName
}
}
return cardDB
}
Loading…
Cancel
Save