Start loading .fnt files. No display yet
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"ur.gs/ordoor/internal/data"
|
||||
"ur.gs/ordoor/internal/fonts"
|
||||
"ur.gs/ordoor/internal/maps"
|
||||
"ur.gs/ordoor/internal/menus"
|
||||
"ur.gs/ordoor/internal/sets"
|
||||
@@ -31,6 +32,7 @@ func main() {
|
||||
loadMapsFrom("MultiMaps")
|
||||
loadSets()
|
||||
loadMenus()
|
||||
loadFonts()
|
||||
}
|
||||
|
||||
func loadData() {
|
||||
@@ -38,6 +40,7 @@ func loadData() {
|
||||
accountingPath := filepath.Join(dataPath, "Accounting.dat")
|
||||
genericDataPath := filepath.Join(dataPath, "GenericData.dat")
|
||||
aniObDefPath := filepath.Join(dataPath, "AniObDef.dat")
|
||||
i18nPath := filepath.Join(dataPath, data.I18nFile)
|
||||
|
||||
log.Printf("Loading %s...", accountingPath)
|
||||
accounting, err := data.LoadAccounting(accountingPath)
|
||||
@@ -62,6 +65,14 @@ func loadData() {
|
||||
}
|
||||
|
||||
log.Printf("%s: %+v", genericDataPath, genericData)
|
||||
|
||||
log.Printf("Loading %s...", i18nPath)
|
||||
i18n, err := data.LoadI18n(i18nPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to parse %s: %s", i18nPath, err)
|
||||
}
|
||||
|
||||
log.Printf("%s: len=%v", i18nPath, i18n.Len())
|
||||
}
|
||||
|
||||
func loadObj() {
|
||||
@@ -165,3 +176,16 @@ func displayRecord(record *menus.Record, depth int) {
|
||||
displayRecord(child, depth+1)
|
||||
}
|
||||
}
|
||||
|
||||
func loadFonts() {
|
||||
fontsPath := filepath.Join(*gamePath, "Fonts")
|
||||
|
||||
fonts, err := fonts.LoadFonts(fontsPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to parse %s/*.fnt as fonts: %v", fontsPath, err)
|
||||
}
|
||||
|
||||
for _, font := range fonts {
|
||||
fmt.Printf(" * `%s`: obj=%v entries=%v\n", font.Name, font.ObjectFile, font.Entries())
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"ur.gs/ordoor/internal/conv"
|
||||
"ur.gs/ordoor/internal/data"
|
||||
"ur.gs/ordoor/internal/fonts"
|
||||
"ur.gs/ordoor/internal/menus"
|
||||
"ur.gs/ordoor/internal/ui"
|
||||
)
|
||||
@@ -25,6 +26,10 @@ type env struct {
|
||||
menu *menus.Menu
|
||||
objects []*conv.Object
|
||||
batch *pixel.Batch
|
||||
|
||||
fonts []*fonts.Font
|
||||
fontObjs []*conv.Object
|
||||
fontBatch *pixel.Batch
|
||||
}
|
||||
|
||||
type state struct {
|
||||
@@ -36,6 +41,26 @@ type state struct {
|
||||
winBounds pixel.Rect
|
||||
}
|
||||
|
||||
func loadObjects(names ...string) ([]*conv.Object, *pixel.Batch) {
|
||||
var raw []*data.Object
|
||||
|
||||
for _, name := range names {
|
||||
objFile := filepath.Join(filepath.Dir(*menuFile), name)
|
||||
obj, err := data.LoadObject(objFile)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load %s: %v", name, err)
|
||||
}
|
||||
obj.Name = name
|
||||
|
||||
raw = append(raw, obj)
|
||||
}
|
||||
|
||||
objects, spritesheet := conv.ConvertObjects(raw)
|
||||
batch := pixel.NewBatch(&pixel.TrianglesData{}, spritesheet)
|
||||
|
||||
return objects, batch
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
@@ -49,22 +74,27 @@ func main() {
|
||||
log.Fatalf("Couldn't load menu file %s: %v", *menuFile, err)
|
||||
}
|
||||
|
||||
rawObjs := []*data.Object{}
|
||||
for _, name := range menu.ObjectFiles {
|
||||
objFile := filepath.Join(filepath.Dir(*menuFile), name)
|
||||
obj, err := data.LoadObject(objFile)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load %s: %v", name, err)
|
||||
}
|
||||
obj.Name = name
|
||||
|
||||
rawObjs = append(rawObjs, obj)
|
||||
if i18n, err := data.LoadI18n(filepath.Join(*gamePath, "Data", data.I18nFile)); err != nil {
|
||||
log.Printf("Failed to load i18n data, skipping internationalization: %v", err)
|
||||
} else {
|
||||
menu.Internationalize(i18n)
|
||||
}
|
||||
|
||||
objects, spritesheet := conv.ConvertObjects(rawObjs)
|
||||
batch := pixel.NewBatch(&pixel.TrianglesData{}, spritesheet)
|
||||
var loadedFonts []*fonts.Font
|
||||
for _, name := range menu.FontNames {
|
||||
font, err := fonts.LoadFont(filepath.Join(*gamePath, "Fonts", name+".fnt"))
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load font %v: %v", name, err)
|
||||
}
|
||||
loadedFonts = append(loadedFonts, font)
|
||||
}
|
||||
|
||||
env := &env{objects: objects, menu: menu, batch: batch}
|
||||
menuObjs, menuBatch := loadObjects(menu.ObjectFiles...)
|
||||
|
||||
env := &env{
|
||||
menu: menu, objects: menuObjs, batch: menuBatch,
|
||||
fonts: loadedFonts, // TODO: load the objects and start displaying text
|
||||
}
|
||||
|
||||
// The main thread now belongs to pixelgl
|
||||
pixelgl.Run(env.run)
|
||||
@@ -131,10 +161,6 @@ func (s *state) present(pWin *pixelgl.Window) {
|
||||
}
|
||||
|
||||
func (s *state) drawRecord(record *menus.Record, target pixel.Target) {
|
||||
if !record.Active {
|
||||
return
|
||||
}
|
||||
|
||||
// Draw this record if it's valid to do so. FIXME: lots to learn
|
||||
if record.SpriteId >= 0 {
|
||||
x := float64(record.X)
|
||||
@@ -149,8 +175,8 @@ func (s *state) drawRecord(record *menus.Record, target pixel.Target) {
|
||||
}
|
||||
|
||||
log.Printf(
|
||||
"Drawing id=%v type=%v spriteid=%v x=%v y=%v",
|
||||
record.Id, record.Type, record.SpriteId, x, y,
|
||||
"Drawing id=%v type=%v spriteid=%v x=%v y=%v desc=%q parent=%p",
|
||||
record.Id, record.Type, record.SpriteId, record.X, record.Y, record.Desc, record.Parent,
|
||||
)
|
||||
|
||||
// FIXME: Need to handle multiple objects
|
||||
|
Reference in New Issue
Block a user