Integrate view-map into ordoor
Now we can view scenario maps from the main game interface. We can't cancel out of a scenario yet, though.
This commit is contained in:
@@ -3,11 +3,15 @@ package flow
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
|
||||
"code.ur.gs/lupine/ordoor/internal/assetstore"
|
||||
"code.ur.gs/lupine/ordoor/internal/config"
|
||||
"code.ur.gs/lupine/ordoor/internal/data"
|
||||
"code.ur.gs/lupine/ordoor/internal/scenario"
|
||||
"code.ur.gs/lupine/ordoor/internal/ship"
|
||||
"code.ur.gs/lupine/ordoor/internal/ui"
|
||||
)
|
||||
|
||||
@@ -19,6 +23,7 @@ type Flow struct {
|
||||
config *config.Config
|
||||
current *ui.Driver
|
||||
drivers map[driverName]*ui.Driver
|
||||
generic *data.Generic
|
||||
|
||||
// Some screens can be returned to from more than one place. Where this is
|
||||
// the case, instead of hardcoding it, we'll store an entry in here so we
|
||||
@@ -27,6 +32,11 @@ type Flow struct {
|
||||
// FIXME: this really suggests wiring everything up at the start is wrong.
|
||||
returns map[driverName]driverName
|
||||
|
||||
// If we're currently playing a scenario, it it placed here
|
||||
scenario *scenario.Scenario
|
||||
|
||||
ship *ship.Ship
|
||||
|
||||
exit error
|
||||
}
|
||||
|
||||
@@ -79,12 +89,19 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func New(assets *assetstore.AssetStore, config *config.Config) (*Flow, error) {
|
||||
func New(assets *assetstore.AssetStore, config *config.Config, ship *ship.Ship) (*Flow, error) {
|
||||
generic, err := assets.Generic()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to read generic data: %v", err)
|
||||
}
|
||||
|
||||
out := &Flow{
|
||||
assets: assets,
|
||||
config: config,
|
||||
generic: generic,
|
||||
drivers: make(map[driverName]*ui.Driver, len(driverNames)),
|
||||
returns: make(map[driverName]driverName),
|
||||
ship: ship,
|
||||
}
|
||||
|
||||
// Load all the drivers upfront
|
||||
@@ -127,7 +144,20 @@ func (f *Flow) Update(screenX, screenY int) error {
|
||||
return f.exit
|
||||
}
|
||||
|
||||
return f.current.Update(screenX, screenY)
|
||||
if f.scenario != nil {
|
||||
if err := f.scenario.Update(screenX, screenY); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if f.current != nil {
|
||||
if err := f.current.Update(screenX, screenY); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *Flow) Draw(screen *ebiten.Image) error {
|
||||
@@ -135,11 +165,29 @@ func (f *Flow) Draw(screen *ebiten.Image) error {
|
||||
return f.exit
|
||||
}
|
||||
|
||||
return f.current.Draw(screen)
|
||||
if f.scenario != nil {
|
||||
if err := f.scenario.Draw(screen); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if f.current != nil {
|
||||
if err := f.current.Draw(screen); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *Flow) Cursor() (*ebiten.Image, *ebiten.DrawImageOptions, error) {
|
||||
return f.current.Cursor()
|
||||
if f.current != nil {
|
||||
return f.current.Cursor()
|
||||
}
|
||||
|
||||
// FIXME: we should get a cursor from current all the time.
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
func (f *Flow) linkDrivers() {
|
||||
@@ -215,6 +263,23 @@ func (f *Flow) setReturningDriver(from, to driverName) func() {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Flow) playNextScenario() func() {
|
||||
return func() {
|
||||
log.Printf("Loading scenario: %v", f.ship.NextScenario)
|
||||
|
||||
// TODO: we *could* load scenario assets in a separate assetstore to
|
||||
// make it easier to chuck them away at the end?
|
||||
scenario, err := scenario.NewScenario(f.assets, f.ship.NextScenario)
|
||||
if err != nil {
|
||||
f.exit = err
|
||||
return
|
||||
}
|
||||
|
||||
f.current = nil // TODO: show the UI for a scenario
|
||||
f.scenario = scenario
|
||||
}
|
||||
}
|
||||
|
||||
// from is the child menu, to is the parent
|
||||
func (f *Flow) returnToLastDriverNow(from driverName) error {
|
||||
to, ok := f.returns[from]
|
||||
|
Reference in New Issue
Block a user