diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-01-24 00:27:50 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-01-27 16:43:44 +0100 |
| commit | 73d40903aecad3efcf7c6055c133f0db86558203 (patch) | |
| tree | e9c8f00fb186e270da92f273f570579f2d0b0d95 /go/assets | |
| parent | fbba48698d8f8b83dfd7d914b0e37338e0d4e2ef (diff) | |
| download | muhqs-game-73d40903aecad3efcf7c6055c133f0db86558203.tar.gz muhqs-game-73d40903aecad3efcf7c6055c133f0db86558203.zip | |
intermediate commit
Diffstat (limited to 'go/assets')
| -rw-r--r-- | go/assets/retrieve.go | 21 |
1 files changed, 19 insertions, 2 deletions
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 +} |
