Skip to content

Commit

Permalink
feat: embed all images
Browse files Browse the repository at this point in the history
  • Loading branch information
zwindler committed Jul 31, 2023
1 parent e21e659 commit 71d2e6f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions maps/tiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package maps

import (
"fmt"
"gocastle/utils"
"image"
"image/draw"
_ "image/jpeg" // Import image/jpeg to support JPEG images
_ "image/png" // Import image/png to support PNG images
"os"
)

type TileInfo struct {
Expand Down Expand Up @@ -45,7 +45,7 @@ var (

// extractTileFromTileset extracts a subimage from coordinates on a tileset
func extractTileFromTileset(x, y int, filePath string) (image.Image, error) {
file, err := os.Open(filePath)
file, err := utils.EmbeddedImages.Open(filePath)
if err != nil {
fmt.Println("Error opening image:", err)
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion model/avatar.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package model

import (
"gocastle/utils"
"math"

"fyne.io/fyne/v2"
Expand All @@ -25,7 +26,7 @@ type Avatar struct {
// CreateAvatar create a copy of an Avatar on given x,y coordinates
func CreateAvatar(avatar Avatar, x, y int) Avatar {
return Avatar{
CanvasImage: canvas.NewImageFromFile(avatar.CanvasPath),
CanvasImage: canvas.NewImageFromImage(utils.GetImageFromEmbed(avatar.CanvasPath)),
PosX: x,
PosY: y,
}
Expand Down
8 changes: 4 additions & 4 deletions model/npc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type NPCsOnCurrentMap struct {

var (
FemaleFarmerAvatar = Avatar{
CanvasPath: "./static/female-farmer.png",
CanvasPath: "static/female-farmer.png",
}
FemaleFarmer = NPCStats{
Name: "Farmer",
Expand All @@ -38,7 +38,7 @@ var (
}

FemaleMageAvatar = Avatar{
CanvasPath: "./static/woman-mage.png",
CanvasPath: "static/woman-mage.png",
}
FemaleMage = NPCStats{
Name: "Mage",
Expand All @@ -52,7 +52,7 @@ var (
}

WolfAvatar = Avatar{
CanvasPath: "./static/wolf.png",
CanvasPath: "static/wolf.png",
}
Wolf = NPCStats{
Name: "Wolf",
Expand All @@ -66,7 +66,7 @@ var (
}

OgreAvatar = Avatar{
CanvasPath: "./static/ogre.png",
CanvasPath: "static/ogre.png",
}
Ogre = NPCStats{
Name: "Ogre",
Expand Down
3 changes: 2 additions & 1 deletion screens/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"gocastle/maps"
"gocastle/model"
"gocastle/utils"
"log"

"fyne.io/fyne/v2"
Expand Down Expand Up @@ -81,7 +82,7 @@ func createMapArea(mapContainer *fyne.Container) fyne.CanvasObject {
}

// create a transparent filler to trick scrollable containers
limits := canvas.NewImageFromFile("static/transparent_tile.png")
limits := canvas.NewImageFromImage(utils.GetImageFromEmbed("static/transparent_tile.png"))
limits.FillMode = canvas.ImageFillStretch
limits.SetMinSize(fyne.NewSize(float32(mapColumns)*16, float32(mapRows)*16))

Expand Down
3 changes: 2 additions & 1 deletion screens/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package screens
import (
"fmt"
"gocastle/model"
"gocastle/utils"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
Expand All @@ -23,7 +24,7 @@ var (
// ShowInventoryScreen is the main function of the inventory screen
func ShowInventoryScreen(window fyne.Window) {
// Load the background image
backgroundImage := canvas.NewImageFromFile("static/inventory.png")
backgroundImage := canvas.NewImageFromImage(utils.GetImageFromEmbed("static/inventory.png"))
backgroundImage.FillMode = canvas.ImageFillContain

// Create a container to hold the dropdown lists for each category
Expand Down
3 changes: 2 additions & 1 deletion screens/newgame.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package screens
import (
"gocastle/maps"
"gocastle/model"
"gocastle/utils"
"log"
"strconv"

Expand Down Expand Up @@ -160,7 +161,7 @@ func ShowNewGameScreen(window fyne.Window) {
for column := 0; column < 3; column++ {
characterAspectTable = append(characterAspectTable, container.NewWithoutLayout())
for row := 0; row < 6; row++ {
image := canvas.NewImageFromFile(aspect_icon_path[column][row])
image := canvas.NewImageFromImage(utils.GetImageFromEmbed(aspect_icon_path[column][row]))
image.FillMode = canvas.ImageFillOriginal
image.Resize(fyneTileSize)
currentPos := fyne.NewPos(0, float32(row)*38)
Expand Down

0 comments on commit 71d2e6f

Please sign in to comment.