animation handling, screens, vp changes

This commit is contained in:
2019-11-01 17:51:55 +03:00
parent c6c6b6254d
commit 1ac6ae4665
16 changed files with 297 additions and 110 deletions

View File

@ -60,8 +60,21 @@ type TileColorSet struct {
DarkBg ColorHolder
}
type GlyphHolder interface {
GetGlyph() string
}
type PlainGlyphHolder struct {
Glyph string
}
func (pch *PlainGlyphHolder) GetGlyph() string {
return pch.Glyph
}
type Appearance struct {
Char string `json:"char"`
Glyph GlyphHolder `json:"char"`
ColorSet *TileColorSet `json:"colorSet"`
}
@ -80,7 +93,7 @@ func FillColorRing(colorValue uint8, minGlow, maxGlow, step int) *cdeque {
color = crng.Range(1, step) + color
}
color = crng.Range(0, step+minGlow)
q = append(q, uint8(color))
q = append(q, colorValue)
//for uint8(color) < uint8(colorValue) {
// q = append(q, uint8(color))
// color = crng.Range(1, step+minGlow)

View File

@ -7,6 +7,7 @@ type GameState struct {
RawInput chan int
FovRecompute chan struct{}
Redraw chan struct{}
Player *Player
}
// do runs f on the main thread.

19
engine/types/mob.go Normal file
View File

@ -0,0 +1,19 @@
package types
type Mob struct {
*Appearance
Coords
BlocksPass bool
}
func (m *Mob) Walk(dx, dy int) {
}
func (m *Mob) Render() {
}
func (m *Mob) MoveToCoords(c Coords) {
}

5
engine/types/player.go Normal file
View File

@ -0,0 +1,5 @@
package types
type Player struct {
Mob
}

88
engine/types/screen.go Normal file
View File

@ -0,0 +1,88 @@
package types
import (
"lab.zaar.be/thefish/alchemyst-go/util"
)
type Screen interface {
Enter()
Exit()
Render()
HandleInput(input string)
UseEcs() bool
}
type ScreenManager struct {
ctx util.ClientCtx
Screens map[string]Screen
CurrentScreen Screen
PreviousScreen Screen
}
// NewScreenManager is a convenience/constructor method to properly initialize a new ScreenManager
func NewScreenManager(ctx util.ClientCtx) *ScreenManager {
manager := ScreenManager{
ctx:ctx,
Screens: make(map[string]Screen),
CurrentScreen: nil,
}
return &manager
}
func (sm *ScreenManager) AddScreen(screenName string, screen Screen) {
// Check to see if a screen with the given screenName has already been added
if _, ok := sm.Screens[screenName]; !ok {
// A screen with the given name does not yet exist on the ScreenManager, go ahead and add it
sm.Screens[screenName] = screen
} else {
sm.ctx.Logger().Warn().Msgf("A screen with name %v was already added to the ScreenManager %v!", screenName, sm)
}
}
// RemoveScreen will remove a screen from the ScreenManager. This can be useful when a temporary screen needs to be
// created, as it can be quickly added (rather than registering at game creation), and then removed when it is no
// longer needed
func (sm *ScreenManager) RemoveScreen(screenName string, screen Screen) {
// Check if the given screenName exists in the ScreenManager
if _, ok := sm.Screens[screenName]; ok {
delete(sm.Screens, screenName)
} else {
// A screen with the given name does not exist
sm.ctx.Logger().Warn().Msgf("A screen with name %v was not found on ScreenManager %v!", screenName, sm)
}
}
// SetScreen will set the current screen property of the screen manager to the provided screen
func (sm *ScreenManager) SetScreen(screen Screen) {
// Call the exit function of the currentScreen, and set the currentScreen as the previousScreen
// Only do this if there is a currentScreen
if sm.CurrentScreen != nil {
sm.CurrentScreen.Exit()
sm.PreviousScreen = sm.CurrentScreen
}
// Set the provided screen as the currentScreen, and call the enter() function of the new currentScreen
sm.CurrentScreen = screen
sm.CurrentScreen.Enter()
}
// SetScreenByName takes a string representing the screen desired to navigate to. It will then transition the
// ScreenManager to the specified screen, if one is found.
func (sm *ScreenManager) SetScreenByName(screenName string) {
// Check if the given screenName exists in the ScreenManager
if _, ok := sm.Screens[screenName]; ok {
// Call the exit function of the currentScreen, and set the currentScreen as the previousScreen
// Only do this if there is a currentScreen
if sm.CurrentScreen != nil {
sm.CurrentScreen.Exit()
sm.PreviousScreen = sm.CurrentScreen
}
// Set the provided screen as the currentScreen, and call the enter() function of the new currentScreen
sm.CurrentScreen = sm.Screens[screenName]
sm.CurrentScreen.Enter()
} else {
// A screen with the given name does not exist
sm.ctx.Logger().Warn().Msgf("A screen with name %v was not found on ScreenManager %v!", screenName, sm)
}
}