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:
2020-04-11 00:13:28 +01:00
parent 0025daf8dd
commit 5f8606377a
10 changed files with 289 additions and 233 deletions

View File

@@ -1,12 +1,13 @@
package flow
func (f *Flow) linkBridge() {
// FIXME: sometimes these doors are frozen, depending on game state
// FIXME: sometimes these doors are frozen, depending on ship state, but we
// don't implement that yet.
f.onClick(bridge, "2.1", f.setDriver(briefing)) // TODO: Mission briefing clickable
f.onClick(bridge, "2.1", f.setDriver(briefing)) // Mission briefing clickable
f.onClick(bridge, "2.2", f.setDriver(choices)) // Options door hotspot
f.setFreeze(bridge, "2.4", false) // FIXME: Enter combat door hotspot (!!!)
f.setFreeze(bridge, "2.6", false) // FIXME: Vehicle configure door hotspot
f.onClick(bridge, "2.4", f.playNextScenario()) // Enter combat door hotspot
f.setFreeze(bridge, "2.6", true) // TODO: Vehicle configure door hotspot
f.onClick(bridge, "2.8", f.setDriver(arrange)) // Squads configure door hotspot
// link children

View File

@@ -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]

View File

@@ -29,7 +29,10 @@ func (f *Flow) linkLevelPly() {
// FIXME: we should select a savegame if Mighty Hero is selected here
// FIXME: we should show a movie here. Need an internal SMK player first
// FIXME: we should set up new game state here!
f.onClick(levelPly, "2.7", f.setDriver(bridge)) // Select button
f.onClick(levelPly, "2.7", func() { // Select button
f.ship.NextScenario = f.generic.CampaignMaps[0]
f.setDriverNow(bridge)
})
// Link children
f.linkBridge()