From 60e6fcb7acaad9bece901da0a66b1676f6a79f1b Mon Sep 17 00:00:00 2001 From: dk Date: Mon, 6 Jul 2020 18:26:08 -0700 Subject: [PATCH] moving enumerations out of d2interface (#552) * moved filter constants back to d2enum * moving key and mouse button enums into d2enum * moving render type enum into d2enum * moving input even priority enums into d2enum * moving terminal enums into d2enum --- d2common/{d2interface => d2enum}/filter.go | 2 +- .../{d2interface => d2enum}/input_button.go | 2 +- d2common/{d2interface => d2enum}/input_key.go | 2 +- .../{d2interface => d2enum}/input_priority.go | 2 +- .../{d2interface => d2enum}/render_type.go | 2 +- d2common/d2enum/terminal_category.go | 12 + d2common/d2interface/input_events.go | 10 +- d2common/d2interface/input_manager.go | 4 +- d2common/d2interface/input_service.go | 16 +- d2common/d2interface/renderer.go | 4 +- d2common/d2interface/surface.go | 2 +- d2common/d2interface/terminal.go | 13 +- d2core/d2asset/dc6_animation.go | 3 +- d2core/d2asset/dcc_animation.go | 3 +- d2core/d2gui/button.go | 3 +- d2core/d2gui/label.go | 3 +- d2core/d2input/d2input.go | 5 +- d2core/d2input/ebiten/ebiten_input.go | 226 +++++++++--------- d2core/d2input/input_events.go | 26 +- d2core/d2input/input_manager.go | 55 ++--- d2core/d2map/d2maprenderer/tile_cache.go | 7 +- d2core/d2render/ebiten/ebiten_renderer.go | 3 +- d2core/d2render/ebiten/ebiten_surface.go | 2 +- d2core/d2render/ebiten/filter_helper.go | 20 +- d2core/d2term/d2term.go | 3 +- d2core/d2term/terminal.go | 57 ++--- d2core/d2ui/button.go | 12 +- d2core/d2ui/checkbox.go | 6 +- d2core/d2ui/d2ui.go | 7 +- d2core/d2ui/label.go | 4 +- d2core/d2ui/textbox.go | 3 +- d2game/d2gamescreen/character_select.go | 3 +- d2game/d2gamescreen/escape_menu.go | 9 +- d2game/d2gamescreen/main_menu.go | 3 +- d2game/d2gamescreen/map_engine_testing.go | 24 +- d2game/d2player/game_controls.go | 26 +- d2game/d2player/hero_stats_panel.go | 2 +- 37 files changed, 305 insertions(+), 281 deletions(-) rename d2common/{d2interface => d2enum}/filter.go (94%) rename d2common/{d2interface => d2enum}/input_button.go (97%) rename d2common/{d2interface => d2enum}/input_key.go (99%) rename d2common/{d2interface => d2enum}/input_priority.go (94%) rename d2common/{d2interface => d2enum}/render_type.go (88%) create mode 100644 d2common/d2enum/terminal_category.go diff --git a/d2common/d2interface/filter.go b/d2common/d2enum/filter.go similarity index 94% rename from d2common/d2interface/filter.go rename to d2common/d2enum/filter.go index bb2467c4..8cce5581 100644 --- a/d2common/d2interface/filter.go +++ b/d2common/d2enum/filter.go @@ -1,4 +1,4 @@ -package d2interface +package d2enum // Filter represents the type of texture filter to be used when an image is magnified or minified. type Filter int diff --git a/d2common/d2interface/input_button.go b/d2common/d2enum/input_button.go similarity index 97% rename from d2common/d2interface/input_button.go rename to d2common/d2enum/input_button.go index 1dd89578..f934e68d 100644 --- a/d2common/d2interface/input_button.go +++ b/d2common/d2enum/input_button.go @@ -1,4 +1,4 @@ -package d2interface +package d2enum // MouseButton represents a traditional 3-button mouse type MouseButton int diff --git a/d2common/d2interface/input_key.go b/d2common/d2enum/input_key.go similarity index 99% rename from d2common/d2interface/input_key.go rename to d2common/d2enum/input_key.go index ebc04cda..b90bf07c 100644 --- a/d2common/d2interface/input_key.go +++ b/d2common/d2enum/input_key.go @@ -1,4 +1,4 @@ -package d2interface +package d2enum // Key represents button on a traditional keyboard. type Key int diff --git a/d2common/d2interface/input_priority.go b/d2common/d2enum/input_priority.go similarity index 94% rename from d2common/d2interface/input_priority.go rename to d2common/d2enum/input_priority.go index bb352517..379e72ac 100644 --- a/d2common/d2interface/input_priority.go +++ b/d2common/d2enum/input_priority.go @@ -1,4 +1,4 @@ -package d2interface +package d2enum // Priority of the event handler type Priority int diff --git a/d2common/d2interface/render_type.go b/d2common/d2enum/render_type.go similarity index 88% rename from d2common/d2interface/render_type.go rename to d2common/d2enum/render_type.go index acaf5796..96a444b4 100644 --- a/d2common/d2interface/render_type.go +++ b/d2common/d2enum/render_type.go @@ -1,4 +1,4 @@ -package d2interface +package d2enum // RenderType defines the type of rendering engine to use type RenderType int diff --git a/d2common/d2enum/terminal_category.go b/d2common/d2enum/terminal_category.go new file mode 100644 index 00000000..efeafd3b --- /dev/null +++ b/d2common/d2enum/terminal_category.go @@ -0,0 +1,12 @@ +package d2enum + +// TermCategory applies styles to the lines in the Terminal +type TermCategory int + +// Terminal Category types +const ( + TermCategoryNone TermCategory = iota + TermCategoryInfo + TermCategoryWarning + TermCategoryError +) diff --git a/d2common/d2interface/input_events.go b/d2common/d2interface/input_events.go index 67f0007b..2fedba3e 100644 --- a/d2common/d2interface/input_events.go +++ b/d2common/d2interface/input_events.go @@ -1,9 +1,11 @@ package d2interface +import "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" + // HandlerEvent holds the qualifiers for a key or mouse event type HandlerEvent interface { - KeyMod() KeyMod - ButtonMod() MouseButtonMod + KeyMod() d2enum.KeyMod + ButtonMod() d2enum.MouseButtonMod X() int Y() int } @@ -11,7 +13,7 @@ type HandlerEvent interface { // KeyEvent represents an event associated with a keyboard key type KeyEvent interface { HandlerEvent - Key() Key + Key() d2enum.Key // Duration represents the number of frames this key has been pressed for Duration() int } @@ -25,7 +27,7 @@ type KeyCharsEvent interface { // MouseEvent represents a mouse event type MouseEvent interface { HandlerEvent - Button() MouseButton + Button() d2enum.MouseButton } // MouseMoveEvent represents a mouse movement event diff --git a/d2common/d2interface/input_manager.go b/d2common/d2interface/input_manager.go index 328a1ea6..43544370 100644 --- a/d2common/d2interface/input_manager.go +++ b/d2common/d2interface/input_manager.go @@ -1,9 +1,11 @@ package d2interface +import "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" + // InputManager manages an InputService type InputManager interface { Advance(elapsedTime, currentTime float64) error - BindHandlerWithPriority(InputEventHandler, Priority) error + BindHandlerWithPriority(InputEventHandler, d2enum.Priority) error BindHandler(h InputEventHandler) error UnbindHandler(handler InputEventHandler) error } diff --git a/d2common/d2interface/input_service.go b/d2common/d2interface/input_service.go index 9381c755..d77a4bc5 100644 --- a/d2common/d2interface/input_service.go +++ b/d2common/d2interface/input_service.go @@ -1,5 +1,7 @@ package d2interface +import "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" + // InputService represents an interface offering Keyboard and Mouse interactions. type InputService interface { // CursorPosition returns a position of a mouse cursor relative to the game screen (window). @@ -7,17 +9,17 @@ type InputService interface { // InputChars return "printable" runes read from the keyboard at the time update is called. InputChars() []rune // IsKeyPressed checks if the provided key is down. - IsKeyPressed(key Key) bool + IsKeyPressed(key d2enum.Key) bool // IsKeyJustPressed checks if the provided key is just transitioned from up to down. - IsKeyJustPressed(key Key) bool + IsKeyJustPressed(key d2enum.Key) bool // IsKeyJustReleased checks if the provided key is just transitioned from down to up. - IsKeyJustReleased(key Key) bool + IsKeyJustReleased(key d2enum.Key) bool // IsMouseButtonPressed checks if the provided mouse button is down. - IsMouseButtonPressed(button MouseButton) bool + IsMouseButtonPressed(button d2enum.MouseButton) bool // IsMouseButtonJustPressed checks if the provided mouse button is just transitioned from up to down. - IsMouseButtonJustPressed(button MouseButton) bool + IsMouseButtonJustPressed(button d2enum.MouseButton) bool // IsMouseButtonJustReleased checks if the provided mouse button is just transitioned from down to up. - IsMouseButtonJustReleased(button MouseButton) bool + IsMouseButtonJustReleased(button d2enum.MouseButton) bool // KeyPressDuration returns how long the key is pressed in frames. - KeyPressDuration(key Key) int + KeyPressDuration(key d2enum.Key) int } diff --git a/d2common/d2interface/renderer.go b/d2common/d2interface/renderer.go index e2f8391f..7ee4a974 100644 --- a/d2common/d2interface/renderer.go +++ b/d2common/d2interface/renderer.go @@ -1,5 +1,7 @@ package d2interface +import "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" + // Renderer interface defines the functionality of a renderer type Renderer interface { GetRendererName() string @@ -7,7 +9,7 @@ type Renderer interface { Run(f func(Surface) error, width, height int, title string) error IsDrawingSkipped() bool CreateSurface(surface Surface) (Surface, error) - NewSurface(width, height int, filter Filter) (Surface, error) + NewSurface(width, height int, filter d2enum.Filter) (Surface, error) IsFullScreen() bool SetFullScreen(fullScreen bool) SetVSyncEnabled(vsync bool) diff --git a/d2common/d2interface/surface.go b/d2common/d2interface/surface.go index eeb6db9e..37e4ef62 100644 --- a/d2common/d2interface/surface.go +++ b/d2common/d2interface/surface.go @@ -19,7 +19,7 @@ type Surface interface { PopN(n int) PushColor(color color.Color) PushCompositeMode(mode d2enum.CompositeMode) - PushFilter(filter Filter) + PushFilter(filter d2enum.Filter) PushTranslation(x, y int) PushBrightness(brightness float64) Render(surface Surface) error diff --git a/d2common/d2interface/terminal.go b/d2common/d2interface/terminal.go index f5f02ed1..c6496437 100644 --- a/d2common/d2interface/terminal.go +++ b/d2common/d2interface/terminal.go @@ -1,15 +1,6 @@ package d2interface -// TermCategory applies styles to the lines in the Terminal -type TermCategory int - -// Terminal Category types -const ( - TermCategoryNone TermCategory = iota - TermCategoryInfo - TermCategoryWarning - TermCategoryError -) +import "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" // Terminal is a drop-down terminal and shell // It is used throughout the codebase, most parts of the engine will @@ -22,7 +13,7 @@ type Terminal interface { OnKeyChars(event KeyCharsEvent) bool Render(surface Surface) error Execute(command string) error - OutputRaw(text string, category TermCategory) + OutputRaw(text string, category d2enum.TermCategory) Outputf(format string, params ...interface{}) OutputInfof(format string, params ...interface{}) OutputWarningf(format string, params ...interface{}) diff --git a/d2core/d2asset/dc6_animation.go b/d2core/d2asset/dc6_animation.go index 98d10a02..25111afc 100644 --- a/d2core/d2asset/dc6_animation.go +++ b/d2core/d2asset/dc6_animation.go @@ -2,6 +2,7 @@ package d2asset import ( "errors" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dcc" d2iface "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" @@ -75,7 +76,7 @@ func (a *DC6Animation) decodeDirection(directionIndex int) error { dc6Frame := dc6.Frames[startFrame+i] sfc, err := a.renderer.NewSurface(int(dc6Frame.Width), int(dc6Frame.Height), - d2iface.FilterNearest) + d2enum.FilterNearest) if err != nil { return err } diff --git a/d2core/d2asset/dcc_animation.go b/d2core/d2asset/dcc_animation.go index f40fae64..f513b7ca 100644 --- a/d2core/d2asset/dcc_animation.go +++ b/d2core/d2asset/dcc_animation.go @@ -2,6 +2,7 @@ package d2asset import ( "errors" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "math" "github.com/OpenDiablo2/OpenDiablo2/d2common" @@ -118,7 +119,7 @@ func (a *DCCAnimation) decodeDirection(directionIndex int) error { } } - sfc, err := a.renderer.NewSurface(frameWidth, frameHeight, d2iface.FilterNearest) + sfc, err := a.renderer.NewSurface(frameWidth, frameHeight, d2enum.FilterNearest) if err != nil { return err } diff --git a/d2core/d2gui/button.go b/d2core/d2gui/button.go index a25f8ba0..47c40327 100644 --- a/d2core/d2gui/button.go +++ b/d2core/d2gui/button.go @@ -2,6 +2,7 @@ package d2gui import ( "errors" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "image/color" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" @@ -71,7 +72,7 @@ func createButton(renderer d2interface.Renderer, text string, buttonStyle Button surfaceCount := animation.GetFrameCount() / (config.segmentsX * config.segmentsY) surfaces := make([]d2interface.Surface, surfaceCount) for i := 0; i < surfaceCount; i++ { - surface, err := renderer.NewSurface(buttonWidth, buttonHeight, d2interface.FilterNearest) + surface, err := renderer.NewSurface(buttonWidth, buttonHeight, d2enum.FilterNearest) if err != nil { return nil, err } diff --git a/d2core/d2gui/label.go b/d2core/d2gui/label.go index 94951849..bf6e9f0a 100644 --- a/d2core/d2gui/label.go +++ b/d2core/d2gui/label.go @@ -1,6 +1,7 @@ package d2gui import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" ) @@ -51,7 +52,7 @@ func (l *Label) SetText(text string) error { func (l *Label) setText(text string) error { width, height := l.font.GetTextMetrics(text) - surface, err := l.renderer.NewSurface(width, height, d2interface.FilterNearest) + surface, err := l.renderer.NewSurface(width, height, d2enum.FilterNearest) if err != nil { return err } diff --git a/d2core/d2input/d2input.go b/d2core/d2input/d2input.go index c3d8050a..90151ee0 100644 --- a/d2core/d2input/d2input.go +++ b/d2core/d2input/d2input.go @@ -2,6 +2,7 @@ package d2input import ( "errors" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" @@ -32,13 +33,13 @@ func Advance(elapsed, current float64) error { } // BindHandlerWithPriority adds an event handler with a specific call priority -func BindHandlerWithPriority(handler d2interface.InputEventHandler, priority d2interface.Priority) error { +func BindHandlerWithPriority(handler d2interface.InputEventHandler, priority d2enum.Priority) error { return singleton.BindHandlerWithPriority(handler, priority) } // BindHandler adds an event handler func BindHandler(handler d2interface.InputEventHandler) error { - return BindHandlerWithPriority(handler, d2interface.PriorityDefault) + return BindHandlerWithPriority(handler, d2enum.PriorityDefault) } // UnbindHandler removes a previously bound event handler diff --git a/d2core/d2input/ebiten/ebiten_input.go b/d2core/d2input/ebiten/ebiten_input.go index 633a3372..94a040de 100644 --- a/d2core/d2input/ebiten/ebiten_input.go +++ b/d2core/d2input/ebiten/ebiten_input.go @@ -2,120 +2,120 @@ package ebiten import ( - "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten/inpututil" ) var ( //nolint:gochecknoglobals This is a constant in all but by name, no constant map in go - keyToEbiten = map[d2interface.Key]ebiten.Key{ - d2interface.Key0: ebiten.Key0, - d2interface.Key1: ebiten.Key1, - d2interface.Key2: ebiten.Key2, - d2interface.Key3: ebiten.Key3, - d2interface.Key4: ebiten.Key4, - d2interface.Key5: ebiten.Key5, - d2interface.Key6: ebiten.Key6, - d2interface.Key7: ebiten.Key7, - d2interface.Key8: ebiten.Key8, - d2interface.Key9: ebiten.Key9, - d2interface.KeyA: ebiten.KeyA, - d2interface.KeyB: ebiten.KeyB, - d2interface.KeyC: ebiten.KeyC, - d2interface.KeyD: ebiten.KeyD, - d2interface.KeyE: ebiten.KeyE, - d2interface.KeyF: ebiten.KeyF, - d2interface.KeyG: ebiten.KeyG, - d2interface.KeyH: ebiten.KeyH, - d2interface.KeyI: ebiten.KeyI, - d2interface.KeyJ: ebiten.KeyJ, - d2interface.KeyK: ebiten.KeyK, - d2interface.KeyL: ebiten.KeyL, - d2interface.KeyM: ebiten.KeyM, - d2interface.KeyN: ebiten.KeyN, - d2interface.KeyO: ebiten.KeyO, - d2interface.KeyP: ebiten.KeyP, - d2interface.KeyQ: ebiten.KeyQ, - d2interface.KeyR: ebiten.KeyR, - d2interface.KeyS: ebiten.KeyS, - d2interface.KeyT: ebiten.KeyT, - d2interface.KeyU: ebiten.KeyU, - d2interface.KeyV: ebiten.KeyV, - d2interface.KeyW: ebiten.KeyW, - d2interface.KeyX: ebiten.KeyX, - d2interface.KeyY: ebiten.KeyY, - d2interface.KeyZ: ebiten.KeyZ, - d2interface.KeyApostrophe: ebiten.KeyApostrophe, - d2interface.KeyBackslash: ebiten.KeyBackslash, - d2interface.KeyBackspace: ebiten.KeyBackspace, - d2interface.KeyCapsLock: ebiten.KeyCapsLock, - d2interface.KeyComma: ebiten.KeyComma, - d2interface.KeyDelete: ebiten.KeyDelete, - d2interface.KeyDown: ebiten.KeyDown, - d2interface.KeyEnd: ebiten.KeyEnd, - d2interface.KeyEnter: ebiten.KeyEnter, - d2interface.KeyEqual: ebiten.KeyEqual, - d2interface.KeyEscape: ebiten.KeyEscape, - d2interface.KeyF1: ebiten.KeyF1, - d2interface.KeyF2: ebiten.KeyF2, - d2interface.KeyF3: ebiten.KeyF3, - d2interface.KeyF4: ebiten.KeyF4, - d2interface.KeyF5: ebiten.KeyF5, - d2interface.KeyF6: ebiten.KeyF6, - d2interface.KeyF7: ebiten.KeyF7, - d2interface.KeyF8: ebiten.KeyF8, - d2interface.KeyF9: ebiten.KeyF9, - d2interface.KeyF10: ebiten.KeyF10, - d2interface.KeyF11: ebiten.KeyF11, - d2interface.KeyF12: ebiten.KeyF12, - d2interface.KeyGraveAccent: ebiten.KeyGraveAccent, - d2interface.KeyHome: ebiten.KeyHome, - d2interface.KeyInsert: ebiten.KeyInsert, - d2interface.KeyKP0: ebiten.KeyKP0, - d2interface.KeyKP1: ebiten.KeyKP1, - d2interface.KeyKP2: ebiten.KeyKP2, - d2interface.KeyKP3: ebiten.KeyKP3, - d2interface.KeyKP4: ebiten.KeyKP4, - d2interface.KeyKP5: ebiten.KeyKP5, - d2interface.KeyKP6: ebiten.KeyKP6, - d2interface.KeyKP7: ebiten.KeyKP7, - d2interface.KeyKP8: ebiten.KeyKP8, - d2interface.KeyKP9: ebiten.KeyKP9, - d2interface.KeyKPAdd: ebiten.KeyKPAdd, - d2interface.KeyKPDecimal: ebiten.KeyKPDecimal, - d2interface.KeyKPDivide: ebiten.KeyKPDivide, - d2interface.KeyKPEnter: ebiten.KeyKPEnter, - d2interface.KeyKPEqual: ebiten.KeyKPEqual, - d2interface.KeyKPMultiply: ebiten.KeyKPMultiply, - d2interface.KeyKPSubtract: ebiten.KeyKPSubtract, - d2interface.KeyLeft: ebiten.KeyLeft, - d2interface.KeyLeftBracket: ebiten.KeyLeftBracket, - d2interface.KeyMenu: ebiten.KeyMenu, - d2interface.KeyMinus: ebiten.KeyMinus, - d2interface.KeyNumLock: ebiten.KeyNumLock, - d2interface.KeyPageDown: ebiten.KeyPageDown, - d2interface.KeyPageUp: ebiten.KeyPageUp, - d2interface.KeyPause: ebiten.KeyPause, - d2interface.KeyPeriod: ebiten.KeyPeriod, - d2interface.KeyPrintScreen: ebiten.KeyPrintScreen, - d2interface.KeyRight: ebiten.KeyRight, - d2interface.KeyRightBracket: ebiten.KeyRightBracket, - d2interface.KeyScrollLock: ebiten.KeyScrollLock, - d2interface.KeySemicolon: ebiten.KeySemicolon, - d2interface.KeySlash: ebiten.KeySlash, - d2interface.KeySpace: ebiten.KeySpace, - d2interface.KeyTab: ebiten.KeyTab, - d2interface.KeyUp: ebiten.KeyUp, - d2interface.KeyAlt: ebiten.KeyAlt, - d2interface.KeyControl: ebiten.KeyControl, - d2interface.KeyShift: ebiten.KeyShift, + keyToEbiten = map[d2enum.Key]ebiten.Key{ + d2enum.Key0: ebiten.Key0, + d2enum.Key1: ebiten.Key1, + d2enum.Key2: ebiten.Key2, + d2enum.Key3: ebiten.Key3, + d2enum.Key4: ebiten.Key4, + d2enum.Key5: ebiten.Key5, + d2enum.Key6: ebiten.Key6, + d2enum.Key7: ebiten.Key7, + d2enum.Key8: ebiten.Key8, + d2enum.Key9: ebiten.Key9, + d2enum.KeyA: ebiten.KeyA, + d2enum.KeyB: ebiten.KeyB, + d2enum.KeyC: ebiten.KeyC, + d2enum.KeyD: ebiten.KeyD, + d2enum.KeyE: ebiten.KeyE, + d2enum.KeyF: ebiten.KeyF, + d2enum.KeyG: ebiten.KeyG, + d2enum.KeyH: ebiten.KeyH, + d2enum.KeyI: ebiten.KeyI, + d2enum.KeyJ: ebiten.KeyJ, + d2enum.KeyK: ebiten.KeyK, + d2enum.KeyL: ebiten.KeyL, + d2enum.KeyM: ebiten.KeyM, + d2enum.KeyN: ebiten.KeyN, + d2enum.KeyO: ebiten.KeyO, + d2enum.KeyP: ebiten.KeyP, + d2enum.KeyQ: ebiten.KeyQ, + d2enum.KeyR: ebiten.KeyR, + d2enum.KeyS: ebiten.KeyS, + d2enum.KeyT: ebiten.KeyT, + d2enum.KeyU: ebiten.KeyU, + d2enum.KeyV: ebiten.KeyV, + d2enum.KeyW: ebiten.KeyW, + d2enum.KeyX: ebiten.KeyX, + d2enum.KeyY: ebiten.KeyY, + d2enum.KeyZ: ebiten.KeyZ, + d2enum.KeyApostrophe: ebiten.KeyApostrophe, + d2enum.KeyBackslash: ebiten.KeyBackslash, + d2enum.KeyBackspace: ebiten.KeyBackspace, + d2enum.KeyCapsLock: ebiten.KeyCapsLock, + d2enum.KeyComma: ebiten.KeyComma, + d2enum.KeyDelete: ebiten.KeyDelete, + d2enum.KeyDown: ebiten.KeyDown, + d2enum.KeyEnd: ebiten.KeyEnd, + d2enum.KeyEnter: ebiten.KeyEnter, + d2enum.KeyEqual: ebiten.KeyEqual, + d2enum.KeyEscape: ebiten.KeyEscape, + d2enum.KeyF1: ebiten.KeyF1, + d2enum.KeyF2: ebiten.KeyF2, + d2enum.KeyF3: ebiten.KeyF3, + d2enum.KeyF4: ebiten.KeyF4, + d2enum.KeyF5: ebiten.KeyF5, + d2enum.KeyF6: ebiten.KeyF6, + d2enum.KeyF7: ebiten.KeyF7, + d2enum.KeyF8: ebiten.KeyF8, + d2enum.KeyF9: ebiten.KeyF9, + d2enum.KeyF10: ebiten.KeyF10, + d2enum.KeyF11: ebiten.KeyF11, + d2enum.KeyF12: ebiten.KeyF12, + d2enum.KeyGraveAccent: ebiten.KeyGraveAccent, + d2enum.KeyHome: ebiten.KeyHome, + d2enum.KeyInsert: ebiten.KeyInsert, + d2enum.KeyKP0: ebiten.KeyKP0, + d2enum.KeyKP1: ebiten.KeyKP1, + d2enum.KeyKP2: ebiten.KeyKP2, + d2enum.KeyKP3: ebiten.KeyKP3, + d2enum.KeyKP4: ebiten.KeyKP4, + d2enum.KeyKP5: ebiten.KeyKP5, + d2enum.KeyKP6: ebiten.KeyKP6, + d2enum.KeyKP7: ebiten.KeyKP7, + d2enum.KeyKP8: ebiten.KeyKP8, + d2enum.KeyKP9: ebiten.KeyKP9, + d2enum.KeyKPAdd: ebiten.KeyKPAdd, + d2enum.KeyKPDecimal: ebiten.KeyKPDecimal, + d2enum.KeyKPDivide: ebiten.KeyKPDivide, + d2enum.KeyKPEnter: ebiten.KeyKPEnter, + d2enum.KeyKPEqual: ebiten.KeyKPEqual, + d2enum.KeyKPMultiply: ebiten.KeyKPMultiply, + d2enum.KeyKPSubtract: ebiten.KeyKPSubtract, + d2enum.KeyLeft: ebiten.KeyLeft, + d2enum.KeyLeftBracket: ebiten.KeyLeftBracket, + d2enum.KeyMenu: ebiten.KeyMenu, + d2enum.KeyMinus: ebiten.KeyMinus, + d2enum.KeyNumLock: ebiten.KeyNumLock, + d2enum.KeyPageDown: ebiten.KeyPageDown, + d2enum.KeyPageUp: ebiten.KeyPageUp, + d2enum.KeyPause: ebiten.KeyPause, + d2enum.KeyPeriod: ebiten.KeyPeriod, + d2enum.KeyPrintScreen: ebiten.KeyPrintScreen, + d2enum.KeyRight: ebiten.KeyRight, + d2enum.KeyRightBracket: ebiten.KeyRightBracket, + d2enum.KeyScrollLock: ebiten.KeyScrollLock, + d2enum.KeySemicolon: ebiten.KeySemicolon, + d2enum.KeySlash: ebiten.KeySlash, + d2enum.KeySpace: ebiten.KeySpace, + d2enum.KeyTab: ebiten.KeyTab, + d2enum.KeyUp: ebiten.KeyUp, + d2enum.KeyAlt: ebiten.KeyAlt, + d2enum.KeyControl: ebiten.KeyControl, + d2enum.KeyShift: ebiten.KeyShift, } //nolint:gochecknoglobals This is a constant in all but by name, no constant map in go - mouseButtonToEbiten = map[d2interface.MouseButton]ebiten.MouseButton{ - d2interface.MouseButtonLeft: ebiten.MouseButtonLeft, - d2interface.MouseButtonMiddle: ebiten.MouseButtonMiddle, - d2interface.MouseButtonRight: ebiten.MouseButtonRight, + mouseButtonToEbiten = map[d2enum.MouseButton]ebiten.MouseButton{ + d2enum.MouseButtonLeft: ebiten.MouseButtonLeft, + d2enum.MouseButtonMiddle: ebiten.MouseButtonMiddle, + d2enum.MouseButtonRight: ebiten.MouseButtonRight, } ) @@ -133,36 +133,36 @@ func (is InputService) InputChars() []rune { } // IsKeyPressed checks if the provided key is down. -func (is InputService) IsKeyPressed(key d2interface.Key) bool { +func (is InputService) IsKeyPressed(key d2enum.Key) bool { return ebiten.IsKeyPressed(keyToEbiten[key]) } // IsKeyJustPressed checks if the provided key is just transitioned from up to down. -func (is InputService) IsKeyJustPressed(key d2interface.Key) bool { +func (is InputService) IsKeyJustPressed(key d2enum.Key) bool { return inpututil.IsKeyJustPressed(keyToEbiten[key]) } // IsKeyJustReleased checks if the provided key is just transitioned from down to up. -func (is InputService) IsKeyJustReleased(key d2interface.Key) bool { +func (is InputService) IsKeyJustReleased(key d2enum.Key) bool { return inpututil.IsKeyJustReleased(keyToEbiten[key]) } // IsMouseButtonPressed checks if the provided mouse button is down. -func (is InputService) IsMouseButtonPressed(button d2interface.MouseButton) bool { +func (is InputService) IsMouseButtonPressed(button d2enum.MouseButton) bool { return ebiten.IsMouseButtonPressed(mouseButtonToEbiten[button]) } // IsMouseButtonJustPressed checks if the provided mouse button is just transitioned from up to down. -func (is InputService) IsMouseButtonJustPressed(button d2interface.MouseButton) bool { +func (is InputService) IsMouseButtonJustPressed(button d2enum.MouseButton) bool { return inpututil.IsMouseButtonJustPressed(mouseButtonToEbiten[button]) } // IsMouseButtonJustReleased checks if the provided mouse button is just transitioned from down to up. -func (is InputService) IsMouseButtonJustReleased(button d2interface.MouseButton) bool { +func (is InputService) IsMouseButtonJustReleased(button d2enum.MouseButton) bool { return inpututil.IsMouseButtonJustReleased(mouseButtonToEbiten[button]) } // KeyPressDuration returns how long the key is pressed in frames. -func (is InputService) KeyPressDuration(key d2interface.Key) int { +func (is InputService) KeyPressDuration(key d2enum.Key) int { return inpututil.KeyPressDuration(keyToEbiten[key]) } diff --git a/d2core/d2input/input_events.go b/d2core/d2input/input_events.go index b4e6bc6a..9e4ffc70 100644 --- a/d2core/d2input/input_events.go +++ b/d2core/d2input/input_events.go @@ -1,24 +1,24 @@ package d2input import ( - "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" ) // HandlerEvent is an event that EventHandlers will process and respond to type HandlerEvent struct { - keyMod d2interface.KeyMod - buttonMod d2interface.MouseButtonMod + keyMod d2enum.KeyMod + buttonMod d2enum.MouseButtonMod x int y int } // KeyMod yields the modifier for a key action -func (e *HandlerEvent) KeyMod() d2interface.KeyMod { +func (e *HandlerEvent) KeyMod() d2enum.KeyMod { return e.keyMod } // ButtonMod yields the modifier for a button action -func (e *HandlerEvent) ButtonMod() d2interface.MouseButtonMod { +func (e *HandlerEvent) ButtonMod() d2enum.MouseButtonMod { return e.buttonMod } @@ -43,12 +43,12 @@ func (e *KeyCharsEvent) Chars() []rune { type KeyEvent struct { HandlerEvent - key d2interface.Key + key d2enum.Key // Duration represents the number of frames this key has been pressed for duration int } -func (e *KeyEvent) Key() d2interface.Key { +func (e *KeyEvent) Key() d2enum.Key { return e.key } func (e *KeyEvent) Duration() int { @@ -57,14 +57,14 @@ func (e *KeyEvent) Duration() int { type MouseEvent struct { HandlerEvent - mouseButton d2interface.MouseButton + mouseButton d2enum.MouseButton } -func (e *MouseEvent) KeyMod() d2interface.KeyMod { +func (e *MouseEvent) KeyMod() d2enum.KeyMod { return e.HandlerEvent.keyMod } -func (e *MouseEvent) ButtonMod() d2interface.MouseButtonMod { +func (e *MouseEvent) ButtonMod() d2enum.MouseButtonMod { return e.HandlerEvent.buttonMod } @@ -76,7 +76,7 @@ func (e *MouseEvent) Y() int { return e.HandlerEvent.y } -func (e *MouseEvent) Button() d2interface.MouseButton { +func (e *MouseEvent) Button() d2enum.MouseButton { return e.mouseButton } @@ -84,11 +84,11 @@ type MouseMoveEvent struct { HandlerEvent } -func (e *MouseMoveEvent) KeyMod() d2interface.KeyMod { +func (e *MouseMoveEvent) KeyMod() d2enum.KeyMod { return e.HandlerEvent.keyMod } -func (e *MouseMoveEvent) ButtonMod() d2interface.MouseButtonMod { +func (e *MouseMoveEvent) ButtonMod() d2enum.MouseButtonMod { return e.HandlerEvent.buttonMod } diff --git a/d2core/d2input/input_manager.go b/d2core/d2input/input_manager.go index 0c05fb44..f07af887 100644 --- a/d2core/d2input/input_manager.go +++ b/d2core/d2input/input_manager.go @@ -1,6 +1,7 @@ package d2input import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "sort" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" @@ -11,8 +12,8 @@ type inputManager struct { cursorX int cursorY int - buttonMod d2interface.MouseButtonMod - keyMod d2interface.KeyMod + buttonMod d2enum.MouseButtonMod + keyMod d2enum.KeyMod entries handlerEntryList } @@ -30,7 +31,7 @@ func (im *inputManager) Advance(_, _ float64) error { cursorY, } - for key := d2interface.KeyMin; key <= d2interface.KeyMax; key++ { + for key := d2enum.KeyMin; key <= d2enum.KeyMax; key++ { im.updateJustPressedKey(key, eventBase) im.updateJustReleasedKey(key, eventBase) im.updatePressedKey(key, eventBase) @@ -38,7 +39,7 @@ func (im *inputManager) Advance(_, _ float64) error { im.updateInputChars(eventBase) - for button := d2interface.MouseButtonMin; button <= d2interface.MouseButtonMax; button++ { + for button := d2enum.MouseButtonMin; button <= d2enum.MouseButtonMax; button++ { im.updateJustPressedButton(button, eventBase) im.updateJustReleasedButton(button, eventBase) im.updatePressedButton(button, eventBase) @@ -51,35 +52,35 @@ func (im *inputManager) Advance(_, _ float64) error { func (im *inputManager) updateKeyMod() { im.keyMod = 0 - if im.inputService.IsKeyPressed(d2interface.KeyAlt) { - im.keyMod |= d2interface.KeyModAlt + if im.inputService.IsKeyPressed(d2enum.KeyAlt) { + im.keyMod |= d2enum.KeyModAlt } - if im.inputService.IsKeyPressed(d2interface.KeyControl) { - im.keyMod |= d2interface.KeyModControl + if im.inputService.IsKeyPressed(d2enum.KeyControl) { + im.keyMod |= d2enum.KeyModControl } - if im.inputService.IsKeyPressed(d2interface.KeyShift) { - im.keyMod |= d2interface.KeyModShift + if im.inputService.IsKeyPressed(d2enum.KeyShift) { + im.keyMod |= d2enum.KeyModShift } } func (im *inputManager) updateButtonMod() { im.buttonMod = 0 - if im.inputService.IsMouseButtonPressed(d2interface.MouseButtonLeft) { - im.buttonMod |= d2interface.MouseButtonModLeft + if im.inputService.IsMouseButtonPressed(d2enum.MouseButtonLeft) { + im.buttonMod |= d2enum.MouseButtonModLeft } - if im.inputService.IsMouseButtonPressed(d2interface.MouseButtonMiddle) { - im.buttonMod |= d2interface.MouseButtonModMiddle + if im.inputService.IsMouseButtonPressed(d2enum.MouseButtonMiddle) { + im.buttonMod |= d2enum.MouseButtonModMiddle } - if im.inputService.IsMouseButtonPressed(d2interface.MouseButtonRight) { - im.buttonMod |= d2interface.MouseButtonModRight + if im.inputService.IsMouseButtonPressed(d2enum.MouseButtonRight) { + im.buttonMod |= d2enum.MouseButtonModRight } } -func (im *inputManager) updateJustPressedKey(k d2interface.Key, e HandlerEvent) { +func (im *inputManager) updateJustPressedKey(k d2enum.Key, e HandlerEvent) { if im.inputService.IsKeyJustPressed(k) { event := KeyEvent{HandlerEvent: e, key: k} @@ -95,7 +96,7 @@ func (im *inputManager) updateJustPressedKey(k d2interface.Key, e HandlerEvent) } } -func (im *inputManager) updateJustReleasedKey(k d2interface.Key, e HandlerEvent) { +func (im *inputManager) updateJustReleasedKey(k d2enum.Key, e HandlerEvent) { if im.inputService.IsKeyJustReleased(k) { event := KeyEvent{HandlerEvent: e, key: k} @@ -110,7 +111,7 @@ func (im *inputManager) updateJustReleasedKey(k d2interface.Key, e HandlerEvent) } } -func (im *inputManager) updatePressedKey(k d2interface.Key, e HandlerEvent) { +func (im *inputManager) updatePressedKey(k d2enum.Key, e HandlerEvent) { if im.inputService.IsKeyPressed(k) { event := KeyEvent{ HandlerEvent: e, @@ -144,7 +145,7 @@ func (im *inputManager) updateInputChars(eventBase HandlerEvent) { } } -func (im *inputManager) updateJustPressedButton(b d2interface.MouseButton, e HandlerEvent) { +func (im *inputManager) updateJustPressedButton(b d2enum.MouseButton, e HandlerEvent) { if im.inputService.IsMouseButtonJustPressed(b) { event := MouseEvent{e, b} @@ -159,7 +160,7 @@ func (im *inputManager) updateJustPressedButton(b d2interface.MouseButton, e Han } } -func (im *inputManager) updateJustReleasedButton(b d2interface.MouseButton, e HandlerEvent) { +func (im *inputManager) updateJustReleasedButton(b d2enum.MouseButton, e HandlerEvent) { if im.inputService.IsMouseButtonJustReleased(b) { event := MouseEvent{e, b} @@ -174,7 +175,7 @@ func (im *inputManager) updateJustReleasedButton(b d2interface.MouseButton, e Ha } } -func (im *inputManager) updatePressedButton(b d2interface.MouseButton, e HandlerEvent) { +func (im *inputManager) updatePressedButton(b d2enum.MouseButton, e HandlerEvent) { if im.inputService.IsMouseButtonPressed(b) { event := MouseEvent{e, b} @@ -209,17 +210,17 @@ func (im *inputManager) updateCursor(cursorX, cursorY int, e HandlerEvent) { // BindHandlerWithPriority adds an event handler with a specific call priority func (im *inputManager) BindHandlerWithPriority( h d2interface.InputEventHandler, - p d2interface.Priority) error { + p d2enum.Priority) error { return singleton.bindHandler(h, p) } // BindHandler adds an event handler func (im *inputManager) BindHandler(h d2interface.InputEventHandler) error { - return im.bindHandler(h, d2interface.PriorityDefault) + return im.bindHandler(h, d2enum.PriorityDefault) } // BindHandler adds an event handler -func (im *inputManager) bindHandler(h d2interface.InputEventHandler, p d2interface.Priority) error { +func (im *inputManager) bindHandler(h d2interface.InputEventHandler, p d2enum.Priority) error { for _, entry := range im.entries { if entry.handler == h { return ErrHasReg @@ -248,7 +249,7 @@ func (im *inputManager) UnbindHandler(handler d2interface.InputEventHandler) err } func (im *inputManager) propagate(callback func(d2interface.InputEventHandler) bool) { - var priority d2interface.Priority + var priority d2enum.Priority var handled bool @@ -267,7 +268,7 @@ func (im *inputManager) propagate(callback func(d2interface.InputEventHandler) b type handlerEntry struct { handler d2interface.InputEventHandler - priority d2interface.Priority + priority d2enum.Priority } type handlerEntryList []handlerEntry diff --git a/d2core/d2map/d2maprenderer/tile_cache.go b/d2core/d2map/d2maprenderer/tile_cache.go index b09490d9..8680a8dc 100644 --- a/d2core/d2map/d2maprenderer/tile_cache.go +++ b/d2core/d2map/d2maprenderer/tile_cache.go @@ -7,7 +7,6 @@ import ( "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2ds1" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dt1" - "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" ) func (mr *MapRenderer) generateTileCache() { @@ -73,7 +72,7 @@ func (mr *MapRenderer) generateFloorCache(tile *d2ds1.FloorShadowRecord, tileX, } tileYOffset := d2common.AbsInt32(tileYMinimum) tileHeight := d2common.AbsInt32(tileData[i].Height) - image, _ := mr.renderer.NewSurface(int(tileData[i].Width), int(tileHeight), d2interface.FilterNearest) + image, _ := mr.renderer.NewSurface(int(tileData[i].Width), int(tileHeight), d2enum.FilterNearest) pixels := make([]byte, 4*tileData[i].Width*tileHeight) mr.decodeTileGfxData(tileData[i].Blocks, &pixels, tileYOffset, tileData[i].Width) _ = image.ReplacePixels(pixels) @@ -112,7 +111,7 @@ func (mr *MapRenderer) generateShadowCache(tile *d2ds1.FloorShadowRecord, tileX, return } - image, _ := mr.renderer.NewSurface(int(tileData.Width), tileHeight, d2interface.FilterNearest) + image, _ := mr.renderer.NewSurface(int(tileData.Width), tileHeight, d2enum.FilterNearest) pixels := make([]byte, 4*tileData.Width*int32(tileHeight)) mr.decodeTileGfxData(tileData.Blocks, &pixels, tileYOffset, tileData.Width) _ = image.ReplacePixels(pixels) @@ -173,7 +172,7 @@ func (mr *MapRenderer) generateWallCache(tile *d2ds1.WallRecord, tileX, tileY in return } - image, _ := mr.renderer.NewSurface(160, int(realHeight), d2interface.FilterNearest) + image, _ := mr.renderer.NewSurface(160, int(realHeight), d2enum.FilterNearest) pixels := make([]byte, 4*160*realHeight) mr.decodeTileGfxData(tileData.Blocks, &pixels, tileYOffset, 160) diff --git a/d2core/d2render/ebiten/ebiten_renderer.go b/d2core/d2render/ebiten/ebiten_renderer.go index 624bb0b5..77462186 100644 --- a/d2core/d2render/ebiten/ebiten_renderer.go +++ b/d2core/d2render/ebiten/ebiten_renderer.go @@ -1,6 +1,7 @@ package ebiten import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "image" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" @@ -75,7 +76,7 @@ func (r *Renderer) CreateSurface(surface d2interface.Surface) (d2interface.Surfa return result, nil } -func (r *Renderer) NewSurface(width, height int, filter d2interface.Filter) (d2interface.Surface, error) { +func (r *Renderer) NewSurface(width, height int, filter d2enum.Filter) (d2interface.Surface, error) { ebitenFilter := d2ToEbitenFilter(filter) img, err := ebiten.NewImage(width, height, ebitenFilter) if err != nil { diff --git a/d2core/d2render/ebiten/ebiten_surface.go b/d2core/d2render/ebiten/ebiten_surface.go index 6aeb0b3c..ae812409 100644 --- a/d2core/d2render/ebiten/ebiten_surface.go +++ b/d2core/d2render/ebiten/ebiten_surface.go @@ -30,7 +30,7 @@ func (s *ebitenSurface) PushCompositeMode(mode d2enum.CompositeMode) { s.stateCurrent.mode = d2ToEbitenCompositeMode(mode) } -func (s *ebitenSurface) PushFilter(filter d2interface.Filter) { +func (s *ebitenSurface) PushFilter(filter d2enum.Filter) { s.stateStack = append(s.stateStack, s.stateCurrent) s.stateCurrent.filter = d2ToEbitenFilter(filter) } diff --git a/d2core/d2render/ebiten/filter_helper.go b/d2core/d2render/ebiten/filter_helper.go index 74fe4090..130a48a5 100644 --- a/d2core/d2render/ebiten/filter_helper.go +++ b/d2core/d2render/ebiten/filter_helper.go @@ -1,32 +1,32 @@ package ebiten import ( - "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/hajimehoshi/ebiten" ) -func d2ToEbitenFilter(filter d2interface.Filter) ebiten.Filter { +func d2ToEbitenFilter(filter d2enum.Filter) ebiten.Filter { switch filter { - case d2interface.FilterDefault: + case d2enum.FilterDefault: return ebiten.FilterDefault - case d2interface.FilterLinear: + case d2enum.FilterLinear: return ebiten.FilterLinear - case d2interface.FilterNearest: + case d2enum.FilterNearest: return ebiten.FilterNearest } return ebiten.FilterDefault } -func ebitenToD2Filter(filter ebiten.Filter) d2interface.Filter { +func ebitenToD2Filter(filter ebiten.Filter) d2enum.Filter { switch filter { case ebiten.FilterDefault: - return d2interface.FilterDefault + return d2enum.FilterDefault case ebiten.FilterLinear: - return d2interface.FilterLinear + return d2enum.FilterLinear case ebiten.FilterNearest: - return d2interface.FilterNearest + return d2enum.FilterNearest } - return d2interface.FilterDefault + return d2enum.FilterDefault } diff --git a/d2core/d2term/d2term.go b/d2core/d2term/d2term.go index 3b956a6d..bc48d6ee 100644 --- a/d2core/d2term/d2term.go +++ b/d2core/d2term/d2term.go @@ -1,6 +1,7 @@ package d2term import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2input" ) @@ -12,7 +13,7 @@ func Initialize() (d2interface.Terminal, error) { return nil, err } - if err := d2input.BindHandlerWithPriority(term, d2interface.PriorityHigh); err != nil { + if err := d2input.BindHandlerWithPriority(term, d2enum.PriorityHigh); err != nil { return nil, err } diff --git a/d2core/d2term/terminal.go b/d2core/d2term/terminal.go index 3bef3226..5fd1fdf5 100644 --- a/d2core/d2term/terminal.go +++ b/d2core/d2term/terminal.go @@ -3,6 +3,7 @@ package d2term import ( "errors" "fmt" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "image/color" "log" "math" @@ -17,14 +18,14 @@ import ( ) // TermCategory applies styles to the lines in the Terminal -type TermCategory d2interface.TermCategory +type TermCategory d2enum.TermCategory // Terminal Category types const ( - TermCategoryNone = TermCategory(d2interface.TermCategoryNone) - TermCategoryInfo = TermCategory(d2interface.TermCategoryInfo) - TermCategoryWarning = TermCategory(d2interface.TermCategoryWarning) - TermCategoryError = TermCategory(d2interface.TermCategoryError) + TermCategoryNone = TermCategory(d2enum.TermCategoryNone) + TermCategoryInfo = TermCategory(d2enum.TermCategoryInfo) + TermCategoryWarning = TermCategory(d2enum.TermCategoryWarning) + TermCategoryError = TermCategory(d2enum.TermCategoryError) ) const ( termCharWidth = 6 @@ -51,7 +52,7 @@ const ( type termHistoryEntry struct { text string - category d2interface.TermCategory + category d2enum.TermCategory } type termActionEntry struct { @@ -102,7 +103,7 @@ func (t *terminal) Advance(elapsed float64) error { } func (t *terminal) OnKeyDown(event d2interface.KeyEvent) bool { - if event.Key() == d2interface.KeyGraveAccent { + if event.Key() == d2enum.KeyGraveAccent { t.toggleTerminal() } @@ -111,26 +112,26 @@ func (t *terminal) OnKeyDown(event d2interface.KeyEvent) bool { } switch event.Key() { - case d2interface.KeyEscape: + case d2enum.KeyEscape: t.command = "" - case d2interface.KeyEnd: + case d2enum.KeyEnd: t.outputIndex = 0 - case d2interface.KeyHome: + case d2enum.KeyHome: t.outputIndex = d2common.MaxInt(0, len(t.outputHistory)-t.lineCount) - case d2interface.KeyPageUp: + case d2enum.KeyPageUp: maxOutputIndex := d2common.MaxInt(0, len(t.outputHistory)-t.lineCount) if t.outputIndex += t.lineCount; t.outputIndex >= maxOutputIndex { t.outputIndex = maxOutputIndex } - case d2interface.KeyPageDown: + case d2enum.KeyPageDown: if t.outputIndex -= t.lineCount; t.outputIndex < 0 { t.outputIndex = 0 } - case d2interface.KeyUp, d2interface.KeyDown: + case d2enum.KeyUp, d2enum.KeyDown: t.handleControlKey(event.Key(), event.KeyMod()) - case d2interface.KeyEnter: + case d2enum.KeyEnter: t.processCommand() - case d2interface.KeyBackspace: + case d2enum.KeyBackspace: if len(t.command) > 0 { t.command = t.command[:len(t.command)-1] } @@ -166,10 +167,10 @@ func (t *terminal) processCommand() { t.command = "" } -func (t *terminal) handleControlKey(eventKey d2interface.Key, keyMod d2interface.KeyMod) { +func (t *terminal) handleControlKey(eventKey d2enum.Key, keyMod d2enum.KeyMod) { switch eventKey { - case d2interface.KeyUp: - if keyMod == d2interface.KeyModControl { + case d2enum.KeyUp: + if keyMod == d2enum.KeyModControl { t.lineCount = d2common.MaxInt(0, t.lineCount-1) } else if len(t.commandHistory) > 0 { t.command = t.commandHistory[t.commandIndex] @@ -179,8 +180,8 @@ func (t *terminal) handleControlKey(eventKey d2interface.Key, keyMod d2interface t.commandIndex-- } } - case d2interface.KeyDown: - if keyMod == d2interface.KeyModControl { + case d2enum.KeyDown: + if keyMod == d2enum.KeyModControl { t.lineCount = d2common.MinInt(t.lineCount+1, termRowCountMax) } } @@ -238,11 +239,11 @@ func (t *terminal) Render(surface d2interface.Surface) error { surface.PushTranslation(-termCharWidth*2, 0) switch historyEntry.category { - case d2interface.TermCategoryInfo: + case d2enum.TermCategoryInfo: surface.DrawRect(termCharWidth, termCharHeight, t.infoColor) - case d2interface.TermCategoryWarning: + case d2enum.TermCategoryWarning: surface.DrawRect(termCharWidth, termCharHeight, t.warningColor) - case d2interface.TermCategoryError: + case d2enum.TermCategoryError: surface.DrawRect(termCharWidth, termCharHeight, t.errorColor) } @@ -347,7 +348,7 @@ func parseActionParams(actionType reflect.Type, actionParams []string) ([]reflec return paramValues, nil } -func (t *terminal) OutputRaw(text string, category d2interface.TermCategory) { +func (t *terminal) OutputRaw(text string, category d2enum.TermCategory) { var line string for _, word := range strings.Split(text, " ") { @@ -370,19 +371,19 @@ func (t *terminal) OutputRaw(text string, category d2interface.TermCategory) { } func (t *terminal) Outputf(format string, params ...interface{}) { - t.OutputRaw(fmt.Sprintf(format, params...), d2interface.TermCategoryNone) + t.OutputRaw(fmt.Sprintf(format, params...), d2enum.TermCategoryNone) } func (t *terminal) OutputInfof(format string, params ...interface{}) { - t.OutputRaw(fmt.Sprintf(format, params...), d2interface.TermCategoryInfo) + t.OutputRaw(fmt.Sprintf(format, params...), d2enum.TermCategoryInfo) } func (t *terminal) OutputWarningf(format string, params ...interface{}) { - t.OutputRaw(fmt.Sprintf(format, params...), d2interface.TermCategoryWarning) + t.OutputRaw(fmt.Sprintf(format, params...), d2enum.TermCategoryWarning) } func (t *terminal) OutputErrorf(format string, params ...interface{}) { - t.OutputRaw(fmt.Sprintf(format, params...), d2interface.TermCategoryError) + t.OutputRaw(fmt.Sprintf(format, params...), d2enum.TermCategoryError) } func (t *terminal) OutputClear() { diff --git a/d2core/d2ui/button.go b/d2core/d2ui/button.go index 68c3b2ab..32ccc69b 100644 --- a/d2core/d2ui/button.go +++ b/d2core/d2ui/button.go @@ -126,7 +126,7 @@ func CreateButton(renderer d2interface.Renderer, buttonType ButtonType, text str result.height += h } - result.normalSurface, _ = renderer.NewSurface(result.width, result.height, d2interface.FilterNearest) + result.normalSurface, _ = renderer.NewSurface(result.width, result.height, d2enum.FilterNearest) _, fontHeight := font.GetTextMetrics(text) textY := (result.height / 2) - (fontHeight / 2) + buttonLayout.TextOffset @@ -136,22 +136,22 @@ func CreateButton(renderer d2interface.Renderer, buttonType ButtonType, text str font.Render(0, textY, text, color.RGBA{R: 100, G: 100, B: 100, A: 255}, result.normalSurface) if buttonLayout.AllowFrameChange { if totalButtonTypes > 1 { - result.pressedSurface, _ = renderer.NewSurface(result.width, result.height, d2interface.FilterNearest) + result.pressedSurface, _ = renderer.NewSurface(result.width, result.height, d2enum.FilterNearest) buttonSprite.RenderSegmented(result.pressedSurface, buttonLayout.XSegments, buttonLayout.YSegments, buttonLayout.BaseFrame+1) font.Render(-2, textY+2, text, color.RGBA{R: 100, G: 100, B: 100, A: 255}, result.pressedSurface) } if totalButtonTypes > 2 { - result.toggledSurface, _ = renderer.NewSurface(result.width, result.height, d2interface.FilterNearest) + result.toggledSurface, _ = renderer.NewSurface(result.width, result.height, d2enum.FilterNearest) buttonSprite.RenderSegmented(result.toggledSurface, buttonLayout.XSegments, buttonLayout.YSegments, buttonLayout.BaseFrame+2) font.Render(0, textY, text, color.RGBA{R: 100, G: 100, B: 100, A: 255}, result.toggledSurface) } if totalButtonTypes > 3 { - result.pressedToggledSurface, _ = renderer.NewSurface(result.width, result.height, d2interface.FilterNearest) + result.pressedToggledSurface, _ = renderer.NewSurface(result.width, result.height, d2enum.FilterNearest) buttonSprite.RenderSegmented(result.pressedToggledSurface, buttonLayout.XSegments, buttonLayout.YSegments, buttonLayout.BaseFrame+3) font.Render(0, textY, text, color.RGBA{R: 100, G: 100, B: 100, A: 255}, result.pressedToggledSurface) } if buttonLayout.DisabledFrame != -1 { - result.disabledSurface, _ = renderer.NewSurface(result.width, result.height, d2interface.FilterNearest) + result.disabledSurface, _ = renderer.NewSurface(result.width, result.height, d2enum.FilterNearest) buttonSprite.RenderSegmented(result.disabledSurface, buttonLayout.XSegments, buttonLayout.YSegments, buttonLayout.DisabledFrame) font.Render(0, textY, text, color.RGBA{R: 100, G: 100, B: 100, A: 255}, result.disabledSurface) } @@ -175,7 +175,7 @@ func (v *Button) Activate() { // Render renders the button func (v *Button) Render(target d2interface.Surface) { target.PushCompositeMode(d2enum.CompositeModeSourceAtop) - target.PushFilter(d2interface.FilterNearest) + target.PushFilter(d2enum.FilterNearest) target.PushTranslation(v.x, v.y) defer target.PopN(3) diff --git a/d2core/d2ui/checkbox.go b/d2core/d2ui/checkbox.go index 1c6326a3..bda00aab 100644 --- a/d2core/d2ui/checkbox.go +++ b/d2core/d2ui/checkbox.go @@ -32,11 +32,11 @@ func CreateCheckbox(renderer d2interface.Renderer, checkState bool) Checkbox { result.width, result.height, _ = checkboxSprite.GetFrameSize(0) checkboxSprite.SetPosition(0, 0) - result.Image, _ = renderer.NewSurface(result.width, result.height, d2interface.FilterNearest) + result.Image, _ = renderer.NewSurface(result.width, result.height, d2enum.FilterNearest) _ = checkboxSprite.RenderSegmented(result.Image, 1, 1, 0) - result.checkedImage, _ = renderer.NewSurface(result.width, result.height, d2interface.FilterNearest) + result.checkedImage, _ = renderer.NewSurface(result.width, result.height, d2enum.FilterNearest) _ = checkboxSprite.RenderSegmented(result.checkedImage, 1, 1, 1) return result @@ -45,7 +45,7 @@ func CreateCheckbox(renderer d2interface.Renderer, checkState bool) Checkbox { func (v *Checkbox) Render(target d2interface.Surface) { target.PushCompositeMode(d2enum.CompositeModeSourceAtop) target.PushTranslation(v.x, v.y) - target.PushFilter(d2interface.FilterNearest) + target.PushFilter(d2enum.FilterNearest) defer target.PopN(3) if v.checkState { diff --git a/d2core/d2ui/d2ui.go b/d2core/d2ui/d2ui.go index d46e0cb7..2a0ac5e4 100644 --- a/d2core/d2ui/d2ui.go +++ b/d2core/d2ui/d2ui.go @@ -1,6 +1,7 @@ package d2ui import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "log" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" @@ -54,7 +55,7 @@ func AddWidget(widget Widget) { func (u *UI) OnMouseButtonUp(event d2interface.MouseEvent) bool { singleton.CursorX, singleton.CursorY = event.X(), event.Y() - if event.Button() == d2interface.MouseButtonLeft { + if event.Button() == d2enum.MouseButtonLeft { singleton.cursorButtons |= CursorButtonLeft // activate previously pressed widget if cursor is still hovering w := singleton.pressedWidget @@ -71,7 +72,7 @@ func (u *UI) OnMouseButtonUp(event d2interface.MouseEvent) bool { func (u *UI) OnMouseButtonDown(event d2interface.MouseEvent) bool { singleton.CursorX, singleton.CursorY = event.X(), event.Y() - if event.Button() == d2interface.MouseButtonLeft { + if event.Button() == d2enum.MouseButtonLeft { // find and press a widget on screen singleton.pressedWidget = nil for _, w := range singleton.widgets { @@ -83,7 +84,7 @@ func (u *UI) OnMouseButtonDown(event d2interface.MouseEvent) bool { } } } - if event.Button() == d2interface.MouseButtonRight { + if event.Button() == d2enum.MouseButtonRight { singleton.cursorButtons |= CursorButtonRight } return false diff --git a/d2core/d2ui/label.go b/d2core/d2ui/label.go index 8b513961..1568fc52 100644 --- a/d2core/d2ui/label.go +++ b/d2core/d2ui/label.go @@ -60,7 +60,7 @@ func (v *Label) Render(target d2interface.Surface) { x, y = v.X-v.Width, v.Y } - target.PushFilter(d2interface.FilterNearest) + target.PushFilter(d2enum.FilterNearest) target.PushCompositeMode(d2enum.CompositeModeSourceAtop) target.PushTranslation(x, y) defer target.PopN(3) @@ -85,7 +85,7 @@ func (v *Label) cacheImage() { width, height := v.font.GetTextMetrics(v.text) v.Width = width v.Height = height - v.imageData[v.text], _ = v.renderer.NewSurface(width, height, d2interface.FilterNearest) + v.imageData[v.text], _ = v.renderer.NewSurface(width, height, d2enum.FilterNearest) surface, _ := v.renderer.CreateSurface(v.imageData[v.text]) v.font.Render(0, 0, v.text, v.Color, surface) } diff --git a/d2core/d2ui/textbox.go b/d2core/d2ui/textbox.go index 4f7e9d79..93dd7810 100644 --- a/d2core/d2ui/textbox.go +++ b/d2core/d2ui/textbox.go @@ -1,6 +1,7 @@ package d2ui import ( + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "strings" "time" @@ -71,7 +72,7 @@ func (v *TextBox) OnKeyChars(event d2interface.KeyCharsEvent) bool { } func (v *TextBox) OnKeyRepeat(event d2interface.KeyEvent) bool { - if event.Key() == d2interface.KeyBackspace && debounceEvents(event.Duration()) { + if event.Key() == d2enum.KeyBackspace && debounceEvents(event.Duration()) { if len(v.text) >= 1 { v.text = v.text[:len(v.text)-1] } diff --git a/d2game/d2gamescreen/character_select.go b/d2game/d2gamescreen/character_select.go index f8609b3e..ee5b98d6 100644 --- a/d2game/d2gamescreen/character_select.go +++ b/d2game/d2gamescreen/character_select.go @@ -2,6 +2,7 @@ package d2gamescreen import ( "fmt" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "image/color" "math" "os" @@ -282,7 +283,7 @@ func (v *CharacterSelect) moveSelectionBox() { // OnMouseButtonDown is called when a mouse button is clicked func (v *CharacterSelect) OnMouseButtonDown(event d2interface.MouseEvent) bool { if !v.showDeleteConfirmation { - if event.Button() == d2interface.MouseButtonLeft { + if event.Button() == d2enum.MouseButtonLeft { mx, my := event.X(), event.Y() bw := 272 bh := 92 diff --git a/d2game/d2gamescreen/escape_menu.go b/d2game/d2gamescreen/escape_menu.go index b8ab0050..67e237a6 100644 --- a/d2game/d2gamescreen/escape_menu.go +++ b/d2game/d2gamescreen/escape_menu.go @@ -2,6 +2,7 @@ package d2gamescreen import ( "fmt" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" @@ -435,13 +436,13 @@ func (m *EscapeMenu) onEnterKey() { // OnKeyDown defines the actions of the Escape Menu when a key is pressed func (m *EscapeMenu) OnKeyDown(event d2interface.KeyEvent) bool { switch event.Key() { - case d2interface.KeyEscape: + case d2enum.KeyEscape: m.onEscKey() - case d2interface.KeyUp: + case d2enum.KeyUp: m.onUpKey() - case d2interface.KeyDown: + case d2enum.KeyDown: m.onDownKey() - case d2interface.KeyEnter: + case d2enum.KeyEnter: m.onEnterKey() default: return false diff --git a/d2game/d2gamescreen/main_menu.go b/d2game/d2gamescreen/main_menu.go index b929a3e9..c3e93f03 100644 --- a/d2game/d2gamescreen/main_menu.go +++ b/d2game/d2gamescreen/main_menu.go @@ -3,6 +3,7 @@ package d2gamescreen import ( "fmt" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "image/color" "log" "os" @@ -431,7 +432,7 @@ func (v *MainMenu) Advance(tickTime float64) error { // OnMouseButtonDown is called when a mouse button is clicked func (v *MainMenu) OnMouseButtonDown(event d2interface.MouseEvent) bool { - if v.screenMode == screenModeTrademark && event.Button() == d2interface.MouseButtonLeft { + if v.screenMode == screenModeTrademark && event.Button() == d2enum.MouseButtonLeft { v.setScreenMode(screenModeMainMenu) return true } diff --git a/d2game/d2gamescreen/map_engine_testing.go b/d2game/d2gamescreen/map_engine_testing.go index 7ca504f6..d84a3eab 100644 --- a/d2game/d2gamescreen/map_engine_testing.go +++ b/d2game/d2gamescreen/map_engine_testing.go @@ -296,26 +296,26 @@ func (met *MapEngineTest) Advance(tickTime float64) error { // OnKeyRepeat is called to handle repeated key presses func (met *MapEngineTest) OnKeyRepeat(event d2interface.KeyEvent) bool { var moveSpeed float64 = 8 - if event.KeyMod() == d2interface.KeyModShift { + if event.KeyMod() == d2enum.KeyModShift { moveSpeed *= 2 } - if event.Key() == d2interface.KeyDown { + if event.Key() == d2enum.KeyDown { met.mapRenderer.MoveCameraBy(0, moveSpeed) return true } - if event.Key() == d2interface.KeyUp { + if event.Key() == d2enum.KeyUp { met.mapRenderer.MoveCameraBy(0, -moveSpeed) return true } - if event.Key() == d2interface.KeyRight { + if event.Key() == d2enum.KeyRight { met.mapRenderer.MoveCameraBy(moveSpeed, 0) return true } - if event.Key() == d2interface.KeyLeft { + if event.Key() == d2enum.KeyLeft { met.mapRenderer.MoveCameraBy(-moveSpeed, 0) return true } @@ -325,17 +325,17 @@ func (met *MapEngineTest) OnKeyRepeat(event d2interface.KeyEvent) bool { // OnKeyDown defines the actions of the Map Engine Test screen when a key is pressed func (met *MapEngineTest) OnKeyDown(event d2interface.KeyEvent) bool { - if event.Key() == d2interface.KeyEscape { + if event.Key() == d2enum.KeyEscape { os.Exit(0) return true } - if event.Key() == d2interface.KeyN { + if event.Key() == d2enum.KeyN { switch event.KeyMod() { - case d2interface.KeyModControl: + case d2enum.KeyModControl: met.fileIndex++ d2screen.SetNextScreen(met) - case d2interface.KeyModShift: + case d2enum.KeyModShift: met.levelPreset = increment(met.levelPreset, met.regionSpec.startPresetIndex, met.regionSpec.endPresetIndex) d2screen.SetNextScreen(met) default: @@ -346,12 +346,12 @@ func (met *MapEngineTest) OnKeyDown(event d2interface.KeyEvent) bool { return true } - if event.Key() == d2interface.KeyP { + if event.Key() == d2enum.KeyP { switch event.KeyMod() { - case d2interface.KeyModControl: + case d2enum.KeyModControl: met.fileIndex-- d2screen.SetNextScreen(met) - case d2interface.KeyModShift: + case d2enum.KeyModShift: met.levelPreset = decrement(met.levelPreset, met.regionSpec.startPresetIndex, met.regionSpec.endPresetIndex) d2screen.SetNextScreen(met) default: diff --git a/d2game/d2player/game_controls.go b/d2game/d2player/game_controls.go index b7e33bb8..09d4f081 100644 --- a/d2game/d2player/game_controls.go +++ b/d2game/d2player/game_controls.go @@ -127,26 +127,26 @@ func NewGameControls(renderer d2interface.Renderer, hero *d2mapentity.Player, ma func (g *GameControls) OnKeyRepeat(event d2interface.KeyEvent) bool { if g.FreeCam { var moveSpeed float64 = 8 - if event.KeyMod() == d2interface.KeyModShift { + if event.KeyMod() == d2enum.KeyModShift { moveSpeed *= 2 } - if event.Key() == d2interface.KeyDown { + if event.Key() == d2enum.KeyDown { g.mapRenderer.MoveCameraBy(0, moveSpeed) return true } - if event.Key() == d2interface.KeyUp { + if event.Key() == d2enum.KeyUp { g.mapRenderer.MoveCameraBy(0, -moveSpeed) return true } - if event.Key() == d2interface.KeyRight { + if event.Key() == d2enum.KeyRight { g.mapRenderer.MoveCameraBy(moveSpeed, 0) return true } - if event.Key() == d2interface.KeyLeft { + if event.Key() == d2enum.KeyLeft { g.mapRenderer.MoveCameraBy(-moveSpeed, 0) return true } @@ -157,20 +157,20 @@ func (g *GameControls) OnKeyRepeat(event d2interface.KeyEvent) bool { func (g *GameControls) OnKeyDown(event d2interface.KeyEvent) bool { switch event.Key() { - case d2interface.KeyEscape: + case d2enum.KeyEscape: if g.inventory.IsOpen() || g.heroStatsPanel.IsOpen() { g.inventory.Close() g.heroStatsPanel.Close() g.updateLayout() break } - case d2interface.KeyI: + case d2enum.KeyI: g.inventory.Toggle() g.updateLayout() - case d2interface.KeyC: + case d2enum.KeyC: g.heroStatsPanel.Toggle() g.updateLayout() - case d2interface.KeyR: + case d2enum.KeyR: g.onToggleRunButton() default: return false @@ -189,8 +189,8 @@ func (g *GameControls) OnMouseButtonRepeat(event d2interface.MouseEvent) bool { now := d2common.Now() button := event.Button() - isLeft := button == d2interface.MouseButtonLeft - isRight := button == d2interface.MouseButtonRight + isLeft := button == d2enum.MouseButtonLeft + isRight := button == d2enum.MouseButtonRight lastLeft:= now-lastLeftBtnActionTime lastRight:= now-lastRightBtnActionTime inRect := !g.isInActiveMenusRect(event.X(), event.Y()) @@ -241,13 +241,13 @@ func (g *GameControls) OnMouseButtonDown(event d2interface.MouseEvent) bool { px = float64(int(px*10)) / 10.0 py = float64(int(py*10)) / 10.0 - if event.Button() == d2interface.MouseButtonLeft && !g.isInActiveMenusRect(mx, my) { + if event.Button() == d2enum.MouseButtonLeft && !g.isInActiveMenusRect(mx, my) { lastLeftBtnActionTime = d2common.Now() g.inputListener.OnPlayerMove(px, py) return true } - if event.Button() == d2interface.MouseButtonRight && !g.isInActiveMenusRect(mx, my) { + if event.Button() == d2enum.MouseButtonRight && !g.isInActiveMenusRect(mx, my) { lastRightBtnActionTime = d2common.Now() g.inputListener.OnPlayerCast(missileID, px, py) return true diff --git a/d2game/d2player/hero_stats_panel.go b/d2game/d2player/hero_stats_panel.go index 4d68605b..07f695dc 100644 --- a/d2game/d2player/hero_stats_panel.go +++ b/d2game/d2player/hero_stats_panel.go @@ -130,7 +130,7 @@ func (s *HeroStatsPanel) Render(target d2interface.Surface) { if s.staticMenuImageCache == nil { frameWidth, frameHeight := s.frame.GetFrameBounds() framesCount := s.frame.GetFrameCount() - surface, err := s.renderer.NewSurface(frameWidth*framesCount, frameHeight*framesCount, d2interface.FilterNearest) + surface, err := s.renderer.NewSurface(frameWidth*framesCount, frameHeight*framesCount, d2enum.FilterNearest) if err != nil { return