From 73d40903aecad3efcf7c6055c133f0db86558203 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Tue, 24 Jan 2023 00:27:50 +0100 Subject: intermediate commit --- go/assets/retrieve.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'go/assets') diff --git a/go/assets/retrieve.go b/go/assets/retrieve.go index 492a983d..cb062196 100644 --- a/go/assets/retrieve.go +++ b/go/assets/retrieve.go @@ -1,6 +1,7 @@ package assets import ( + "image/color" "image/png" "log" "net/http" @@ -8,6 +9,9 @@ import ( "strings" "github.com/hajimehoshi/ebiten/v2" + "github.com/hajimehoshi/ebiten/v2/text" + + "muhq.space/muhqs-game/go/font" ) const ( @@ -15,7 +19,7 @@ const ( BASE_URL string = "localhost:8000/" IMAGE_URL_PART string = "html/build/latex-build" TILE_URL_PART string = "assets/tiles" - SYMBOL_URL_PART string = "assets/symbols" + SYMBOL_URL_PART string = "assets/symbols/40x40" ) func retrieveAsset(path string) *ebiten.Image { @@ -25,9 +29,12 @@ func retrieveAsset(path string) *ebiten.Image { log.Println(err) return nil } - defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + return nil + } + img, err := png.Decode(resp.Body) if err != nil { log.Fatal("decoding ", err) @@ -81,3 +88,13 @@ func GetSymbol(symbol string) *ebiten.Image { } return img } + +func GetGenericSymbol(symbol string) *ebiten.Image { + img, found := symbols[symbol] + if !found { + genericBase := GetSymbol("generic_base") + img = ebiten.NewImageFromImage(genericBase) + text.Draw(img, symbol, font.Font, 5, 27, color.Black) + } + return img +} -- cgit v1.2.3