Source the palette name from data
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"image/color"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
"code.ur.gs/lupine/ordoor/internal/idx"
|
||||
"code.ur.gs/lupine/ordoor/internal/maps"
|
||||
"code.ur.gs/lupine/ordoor/internal/menus"
|
||||
"code.ur.gs/lupine/ordoor/internal/palettes"
|
||||
"code.ur.gs/lupine/ordoor/internal/sets"
|
||||
)
|
||||
|
||||
@@ -33,6 +35,10 @@ func main() {
|
||||
}
|
||||
engine := cfg.DefaultEngine()
|
||||
gamePath := engine.DataDir
|
||||
palette, ok := palettes.Get(engine.Palette)
|
||||
if !ok {
|
||||
log.Fatalf("Unknown palette name: %v", engine.Palette)
|
||||
}
|
||||
|
||||
loadData(filepath.Join(gamePath, "Data"))
|
||||
|
||||
@@ -43,7 +49,7 @@ func main() {
|
||||
loadMapsFrom(filepath.Join(gamePath, "Maps"))
|
||||
loadMapsFrom(filepath.Join(gamePath, "MultiMaps"))
|
||||
loadSets(filepath.Join(gamePath, "Sets"))
|
||||
loadMenus(filepath.Join(gamePath, "Menu"))
|
||||
loadMenus(filepath.Join(gamePath, "Menu"), palette)
|
||||
loadFonts(filepath.Join(gamePath, "Fonts"))
|
||||
loadIdx(filepath.Join(gamePath, "Idx", "WarHammer.idx"))
|
||||
}
|
||||
@@ -163,10 +169,10 @@ func loadSets(setsPath string) {
|
||||
}
|
||||
}
|
||||
|
||||
func loadMenus(menusPath string) {
|
||||
func loadMenus(menusPath string, palette color.Palette) {
|
||||
log.Printf("Loading menus from %s", menusPath)
|
||||
|
||||
menus, err := menus.LoadMenus(menusPath)
|
||||
menus, err := menus.LoadMenus(menusPath, palette)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to parse %s/*.mnu as menus: %v", menusPath, err)
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ default_engine = "ordoor"
|
||||
|
||||
[engines.geas] # Wages of War -> Gifts of Peace -> Geas
|
||||
data_dir = "./WoW"
|
||||
palette = "WagesOfWar"
|
||||
|
||||
[engines.ordoor] # Chaos Gate -> Order Door -> Ordoor
|
||||
data_dir = "./CG"
|
||||
|
@@ -2,6 +2,7 @@ package assetstore
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
"code.ur.gs/lupine/ordoor/internal/config"
|
||||
"code.ur.gs/lupine/ordoor/internal/data"
|
||||
"code.ur.gs/lupine/ordoor/internal/idx"
|
||||
"code.ur.gs/lupine/ordoor/internal/palettes"
|
||||
)
|
||||
|
||||
type entryMap map[string]map[string]string
|
||||
@@ -29,7 +31,7 @@ type entryMap map[string]map[string]string
|
||||
// or instantiate two separate asset stores.
|
||||
type AssetStore struct {
|
||||
RootDir string
|
||||
// Palette
|
||||
Palette color.Palette
|
||||
|
||||
// Case-insensitive file lookup.
|
||||
// {"":{"anim":"Anim", "obj":"Obj", ...}, "anim":{ "warhammer.ani":"WarHammer.ani" }, ...}
|
||||
@@ -56,8 +58,14 @@ func New(engine *config.Engine) (*AssetStore, error) {
|
||||
return nil, fmt.Errorf("Unconfigured engine passed to assetstore")
|
||||
}
|
||||
|
||||
palette, ok := palettes.Get(engine.Palette)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Couldn't find palette %q for engine", engine.Palette)
|
||||
}
|
||||
|
||||
store := &AssetStore{
|
||||
RootDir: engine.DataDir,
|
||||
Palette: palette,
|
||||
}
|
||||
|
||||
// fill entryMap
|
||||
|
@@ -62,7 +62,7 @@ func (a *AssetStore) Menu(name string) (*Menu, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
raw, err := menus.LoadMenu(filename)
|
||||
raw, err := menus.LoadMenu(filename, a.Palette)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -117,7 +117,7 @@ func (o *Object) Sprite(idx int) (*Sprite, error) {
|
||||
}
|
||||
|
||||
raw := o.raw.Sprites[idx]
|
||||
img, err := ebiten.NewImageFromImage(raw.ToImage(), ebiten.FilterDefault)
|
||||
img, err := ebiten.NewImageFromImage(raw.ToImage(o.assets.Palette), ebiten.FilterDefault)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
@@ -12,7 +13,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"code.ur.gs/lupine/ordoor/internal/data/rle"
|
||||
"code.ur.gs/lupine/ordoor/internal/palettes"
|
||||
)
|
||||
|
||||
type SpriteHeader struct {
|
||||
@@ -53,12 +53,12 @@ type Sprite struct {
|
||||
Data []byte
|
||||
}
|
||||
|
||||
func (s *Sprite) ToImage() *image.Paletted {
|
||||
func (s *Sprite) ToImage(palette color.Palette) *image.Paletted {
|
||||
return &image.Paletted{
|
||||
Pix: s.Data,
|
||||
Stride: int(s.Width),
|
||||
Rect: image.Rect(0, 0, int(s.Width), int(s.Height)),
|
||||
Palette: palettes.DefaultPalette(),
|
||||
Palette: palette,
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,6 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"code.ur.gs/lupine/ordoor/internal/palettes"
|
||||
"code.ur.gs/lupine/ordoor/internal/util/asciiscan"
|
||||
)
|
||||
|
||||
@@ -143,7 +142,7 @@ func (p *Properties) Point() image.Point {
|
||||
return image.Point{}
|
||||
}
|
||||
|
||||
func LoadMenu(filename string) (*Menu, error) {
|
||||
func LoadMenu(filename string, palette color.Palette) (*Menu, error) {
|
||||
name := filepath.Base(filename)
|
||||
name = strings.TrimSuffix(name, filepath.Ext(name))
|
||||
name = strings.ToLower(name)
|
||||
@@ -163,7 +162,7 @@ func LoadMenu(filename string) (*Menu, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := loadProperties(out, scanner); err != nil {
|
||||
if err := loadProperties(out, scanner, palette); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -189,7 +188,7 @@ func loadObjects(menu *Menu, scanner *asciiscan.Scanner) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadProperties(menu *Menu, scanner *asciiscan.Scanner) error {
|
||||
func loadProperties(menu *Menu, scanner *asciiscan.Scanner, palette color.Palette) error {
|
||||
for {
|
||||
ok, err := scanner.PeekProperty()
|
||||
|
||||
@@ -218,9 +217,9 @@ func loadProperties(menu *Menu, scanner *asciiscan.Scanner) error {
|
||||
|
||||
switch strings.ToUpper(k) {
|
||||
case "BACKGROUND COLOR":
|
||||
menu.BackgroundColor = palettes.DefaultPalette()[vInt]
|
||||
menu.BackgroundColor = palette[vInt]
|
||||
case "HYPERTEXT COLOR":
|
||||
menu.HypertextColor = palettes.DefaultPalette()[vInt]
|
||||
menu.HypertextColor = palette[vInt]
|
||||
case "FONT TYPE":
|
||||
menu.FontType = vInt
|
||||
default:
|
||||
@@ -319,7 +318,7 @@ func loadRecords(baseDir string, menu *Menu, scanner *asciiscan.Scanner) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func LoadMenus(dir string) (map[string]*Menu, error) {
|
||||
func LoadMenus(dir string, palette color.Palette) (map[string]*Menu, error) {
|
||||
fis, err := ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -337,7 +336,7 @@ func LoadMenus(dir string) (map[string]*Menu, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
built, err := LoadMenu(filepath.Join(dir, relname))
|
||||
built, err := LoadMenu(filepath.Join(dir, relname), palette)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %v", filepath.Join(dir, relname), err)
|
||||
}
|
||||
|
@@ -5,9 +5,6 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Override this to change the palette globally
|
||||
const DefaultPaletteName = "ChaosGate"
|
||||
|
||||
var (
|
||||
Transparent = color.RGBA{R: 0, G: 0, B: 0, A: 0}
|
||||
|
||||
@@ -16,6 +13,8 @@ var (
|
||||
initPalettes = sync.Once{}
|
||||
)
|
||||
|
||||
func DefaultPalette() color.Palette {
|
||||
return Palettes[DefaultPaletteName]
|
||||
func Get(name string) (color.Palette, bool) {
|
||||
p, ok := Palettes[name]
|
||||
|
||||
return p, ok
|
||||
}
|
||||
|
Reference in New Issue
Block a user