openquell/util/ldtkhelpers.go
Thomas von Dein faf0fd99c2 Changes:
- use toggle tile for all toggling entities (transient, switch, door)
- get rod of hard coded sprites (exception: particle class, to be
  fixed later)
- changed switch sprite (rect instead of elipse)
2024-03-31 20:16:15 +02:00

49 lines
881 B
Go

package util
import (
"openquell/config"
"github.com/solarlune/ldtkgo"
)
type TileSetSubRect struct {
X, Y, W, H int
}
func Map2Subrect(raw map[string]any) *TileSetSubRect {
// we need to translate this map for less typing
return &TileSetSubRect{
W: int(raw["w"].(float64)),
H: int(raw["h"].(float64)),
X: int(raw["x"].(float64)),
Y: int(raw["y"].(float64)),
}
}
func GetPropertyRef(entity *ldtkgo.Entity) string {
ref := entity.PropertyByIdentifier(config.LDTK_Entity_Ref)
if ref != nil {
if ref.Value != nil {
refid := ref.Value.(map[string]interface{})
ref := refid["entityIid"].(string)
if ref != "" {
return ref
}
}
}
return ""
}
func GetPropertyToggleTile(entity *ldtkgo.Entity) *TileSetSubRect {
ref := entity.PropertyByIdentifier(config.LDTK_Toggle_Tile)
if ref != nil {
return Map2Subrect(ref.AsMap())
}
return nil
}