Build a simple animation viewer
This commit is contained in:
78
internal/assetstore/ani.go
Normal file
78
internal/assetstore/ani.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package assetstore
|
||||
|
||||
import (
|
||||
"code.ur.gs/lupine/ordoor/internal/idx"
|
||||
)
|
||||
|
||||
type Animation struct {
|
||||
Frames []*Sprite
|
||||
}
|
||||
|
||||
func (a *AssetStore) AnimationsIndex() (*idx.Idx, error) {
|
||||
if a.idx != nil {
|
||||
return a.idx, nil
|
||||
}
|
||||
|
||||
filename, err := a.lookup("WarHammer", "idx", "Idx")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
idx, err := idx.Load(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
a.idx = idx
|
||||
return idx, nil
|
||||
}
|
||||
|
||||
func (a *AssetStore) AnimationsObject() (*Object, error) {
|
||||
if a.aniObj != nil {
|
||||
return a.aniObj, nil
|
||||
}
|
||||
|
||||
filename, err := a.lookup("WarHammer", "ani", "Anim")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
obj, err := a.ObjectByPath(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
a.aniObj = obj
|
||||
return obj, nil
|
||||
}
|
||||
|
||||
func (a *AssetStore) Animation(groupIdx, recIdx int) (*Animation, error) {
|
||||
idx, err := a.AnimationsIndex()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
obj, err := a.AnimationsObject()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
group := idx.Groups[groupIdx]
|
||||
if group.Spec.Count == 0 {
|
||||
return &Animation{}, nil
|
||||
}
|
||||
|
||||
// rec := group.Records[recIdx]
|
||||
det := group.Details[recIdx]
|
||||
|
||||
first := int(group.Spec.SpriteIdx) + int(det.FirstSprite)
|
||||
last := int(group.Spec.SpriteIdx) + int(det.LastSprite)
|
||||
count := last - first + 1
|
||||
|
||||
sprites, err := obj.Sprites(first, count)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Animation{Frames: sprites}, nil
|
||||
}
|
@@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"code.ur.gs/lupine/ordoor/internal/data"
|
||||
"code.ur.gs/lupine/ordoor/internal/idx"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -34,17 +35,18 @@ type AssetStore struct {
|
||||
entries entryMap
|
||||
|
||||
// These members are used to store things we've already loaded
|
||||
aniObj *Object
|
||||
cursorObj *Object
|
||||
|
||||
cursors map[CursorName]*Cursor
|
||||
fonts map[string]*Font
|
||||
generic *data.Generic
|
||||
maps map[string]*Map
|
||||
menus map[string]*Menu
|
||||
objs map[string]*Object
|
||||
sets map[string]*Set
|
||||
sounds map[string]*Sound
|
||||
strings *data.I18n
|
||||
cursors map[CursorName]*Cursor
|
||||
fonts map[string]*Font
|
||||
generic *data.Generic
|
||||
idx *idx.Idx
|
||||
maps map[string]*Map
|
||||
menus map[string]*Menu
|
||||
objs map[string]*Object
|
||||
sets map[string]*Set
|
||||
sounds map[string]*Sound
|
||||
strings *data.I18n
|
||||
}
|
||||
|
||||
// New returns a new AssetStore
|
||||
@@ -88,10 +90,12 @@ func (a *AssetStore) Refresh() error {
|
||||
}
|
||||
|
||||
// Refresh
|
||||
a.aniObj = nil
|
||||
a.cursorObj = nil
|
||||
a.cursors = make(map[CursorName]*Cursor)
|
||||
a.entries = newEntryMap
|
||||
a.fonts = make(map[string]*Font)
|
||||
a.idx = nil
|
||||
a.maps = make(map[string]*Map)
|
||||
a.menus = make(map[string]*Menu)
|
||||
a.objs = make(map[string]*Object)
|
||||
|
@@ -41,18 +41,7 @@ func (m *Menu) Images(objIdx, start, count int) ([]*ebiten.Image, error) {
|
||||
}
|
||||
|
||||
func (m *Menu) Sprites(objIdx, start, count int) ([]*Sprite, error) {
|
||||
out := make([]*Sprite, count)
|
||||
|
||||
for i := start; i < start+count; i++ {
|
||||
sprite, err := m.Sprite(objIdx, i)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out[i-start] = sprite
|
||||
}
|
||||
|
||||
return out, nil
|
||||
return m.objects[objIdx].Sprites(start, count)
|
||||
}
|
||||
|
||||
func (m *Menu) Sprite(objIdx, idx int) (*Sprite, error) {
|
||||
|
@@ -90,6 +90,21 @@ func (o *Object) LoadSprites() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Object) Sprites(start, count int) ([]*Sprite, error) {
|
||||
out := make([]*Sprite, count)
|
||||
|
||||
for i := start; i < start+count; i++ {
|
||||
sprite, err := o.Sprite(i)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out[i-start] = sprite
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (o *Object) Sprite(idx int) (*Sprite, error) {
|
||||
if sprite := o.sprites[idx]; sprite != nil {
|
||||
return sprite, nil
|
||||
|
Reference in New Issue
Block a user