Documentation ¶
Overview ¶
Package d2interface defines interfaces for the OpenDiablo2 engine
Index ¶
- type Animation
- type Archive
- type AudioProvider
- type Cache
- type Cacher
- type Color
- type DataStream
- type HandlerEvent
- type InputEventHandler
- type InputManager
- type InputService
- type KeyCharsEvent
- type KeyCharsHandler
- type KeyDownHandler
- type KeyEvent
- type KeyRepeatHandler
- type KeyUpHandler
- type MapEntity
- type MouseButtonDownHandler
- type MouseButtonRepeatHandler
- type MouseButtonUpHandler
- type MouseEvent
- type MouseMoveEvent
- type MouseMoveHandler
- type Navigator
- type Palette
- type Renderer
- type SoundEffect
- type Surface
- type Terminal
- type TerminalLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Animation ¶
type Animation interface { BindRenderer(Renderer) Clone() Animation SetSubLoop(startFrame, EndFrame int) Advance(elapsed float64) error GetCurrentFrameSurface() Surface Render(target Surface) RenderFromOrigin(target Surface, shadow bool) RenderSection(sfc Surface, bound image.Rectangle) GetFrameSize(frameIndex int) (int, int, error) GetCurrentFrameSize() (int, int) GetFrameBounds() (int, int) GetCurrentFrame() int GetFrameCount() int IsOnFirstFrame() bool IsOnLastFrame() bool GetDirectionCount() int SetDirection(directionIndex int) error GetDirection() int SetCurrentFrame(frameIndex int) error Rewind() PlayForward() PlayBackward() Pause() SetPlayLoop(loop bool) SetPlaySpeed(playSpeed float64) SetPlayLength(playLength float64) SetColorMod(colorMod color.Color) GetPlayedCount() int ResetPlayedCount() SetEffect(effect d2enum.DrawEffect) SetShadow(shadow bool) }
Animation is an animation
type Archive ¶
type Archive interface { Path() string Contains(string) bool Size() uint32 Close() error ReadFile(fileName string) ([]byte, error) ReadFileStream(fileName string) (DataStream, error) ReadTextFile(fileName string) (string, error) Listfile() ([]string, error) }
Archive is an abstract representation of a game archive file For the original Diablo II, archives are always MPQ's, but OpenDiablo2 can handle any kind of archive file as long as it implements this interface
type AudioProvider ¶
type AudioProvider interface { PlayBGM(song string) LoadSound(sfx string, loop bool, bgm bool) (SoundEffect, error) SetVolumes(bgmVolume, sfxVolume float64) }
AudioProvider is something that can play music, load audio files managed by the asset manager, and set the game engine's volume levels
type Cache ¶
type Cache interface { SetVerbose(verbose bool) GetWeight() int GetBudget() int Insert(key string, value interface{}, weight int) error Retrieve(key string) (interface{}, bool) Clear() }
Cache stores arbitrary data for fast retrieval
type Cacher ¶
type Cacher interface { ClearCache() GetCache() Cache }
Cacher is something that has a cache
type Color ¶
type Color interface { R() uint8 G() uint8 B() uint8 A() uint8 RGBA() uint32 SetRGBA(uint32) BGRA() uint32 SetBGRA(uint32) }
Color represents a color
type DataStream ¶
type DataStream interface { Read(p []byte) (n int, err error) Seek(offset int64, whence int) (int64, error) Close() error }
DataStream is a data stream
type HandlerEvent ¶
type HandlerEvent interface { KeyMod() d2enum.KeyMod ButtonMod() d2enum.MouseButtonMod X() int Y() int }
HandlerEvent holds the qualifiers for a key or mouse event
type InputManager ¶
type InputManager interface { Advance(elapsedTime, currentTime float64) error BindHandlerWithPriority(InputEventHandler, d2enum.Priority) error BindHandler(h InputEventHandler) error UnbindHandler(handler InputEventHandler) error }
InputManager manages an InputService
type InputService ¶
type InputService interface { // CursorPosition returns a position of a mouse cursor relative to the game screen (window). CursorPosition() (x int, y int) // 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 d2enum.Key) bool // IsKeyJustPressed checks if the provided key is just transitioned from up to down. IsKeyJustPressed(key d2enum.Key) bool // IsKeyJustReleased checks if the provided key is just transitioned from down to up. IsKeyJustReleased(key d2enum.Key) bool // IsMouseButtonPressed checks if the provided mouse button is down. IsMouseButtonPressed(button d2enum.MouseButton) bool // IsMouseButtonJustPressed checks if the provided mouse button is just transitioned from up to down. IsMouseButtonJustPressed(button d2enum.MouseButton) bool // IsMouseButtonJustReleased checks if the provided mouse button is just transitioned from down to up. IsMouseButtonJustReleased(button d2enum.MouseButton) bool // KeyPressDuration returns how long the key is pressed in frames. KeyPressDuration(key d2enum.Key) int }
InputService represents an interface offering Keyboard and Mouse interactions.
type KeyCharsEvent ¶
type KeyCharsEvent interface { HandlerEvent Chars() []rune }
KeyCharsEvent represents an event associated with a keyboard character being pressed
type KeyCharsHandler ¶
type KeyCharsHandler interface {
OnKeyChars(event KeyCharsEvent) (preventPropagation bool)
}
KeyCharsHandler represents a handler associated with a keyboard character pressed event
type KeyDownHandler ¶
KeyDownHandler represents a handler for a keyboard key pressed event
type KeyEvent ¶
type KeyEvent interface { HandlerEvent Key() d2enum.Key // Duration represents the number of frames this key has been pressed for Duration() int }
KeyEvent represents an event associated with a keyboard key
type KeyRepeatHandler ¶
KeyRepeatHandler represents a handler for a keyboard key held-down event; between a pressed and released.
type KeyUpHandler ¶
KeyUpHandler represents a handler for a keyboard key release event
type MapEntity ¶
type MapEntity interface { ID() string Render(target Surface) Advance(tickTime float64) GetPosition() d2vector.Position GetVelocity() d2vector.Vector GetSize() (width, height int) GetLayer() int GetPositionF() (float64, float64) Label() string Selectable() bool Highlight() }
MapEntity is something that can be positioned on and rendered on the game map
type MouseButtonDownHandler ¶
type MouseButtonDownHandler interface {
OnMouseButtonDown(event MouseEvent) (preventPropagation bool)
}
MouseButtonDownHandler represents a handler for a mouse button pressed event
type MouseButtonRepeatHandler ¶
type MouseButtonRepeatHandler interface {
OnMouseButtonRepeat(event MouseEvent) (preventPropagation bool)
}
MouseButtonRepeatHandler represents a handler for a mouse button held-down event; between a pressed and released.
type MouseButtonUpHandler ¶
type MouseButtonUpHandler interface {
OnMouseButtonUp(event MouseEvent) (preventPropagation bool)
}
MouseButtonUpHandler represents a handler for a mouse button release event
type MouseEvent ¶
type MouseEvent interface { HandlerEvent Button() d2enum.MouseButton }
MouseEvent represents a mouse event
type MouseMoveEvent ¶
type MouseMoveEvent interface { HandlerEvent }
MouseMoveEvent represents a mouse movement event
type MouseMoveHandler ¶
type MouseMoveHandler interface {
OnMouseMove(event MouseMoveEvent) (preventPropagation bool)
}
MouseMoveHandler represents a handler for a mouse button release event
type Navigator ¶
type Navigator interface {}
Navigator is used for transitioning between game screens
type Palette ¶
type Palette interface { NumColors() int GetColors() [numColors]Color GetColor(idx int) (Color, error) }
Palette is a color palette
type Renderer ¶
type Renderer interface { GetRendererName() string SetWindowIcon(fileName string) Run(r renderCallback, u updateCallback, width, height int, title string) error IsDrawingSkipped() bool CreateSurface(surface Surface) (Surface, error) NewSurface(width, height int) Surface IsFullScreen() bool SetFullScreen(fullScreen bool) SetVSyncEnabled(vsync bool) GetVSyncEnabled() bool GetCursorPos() (int, int) CurrentFPS() float64 ShowPanicScreen(message string) Print(target interface{}, str string) error PrintAt(target interface{}, str string, x, y int) }
Renderer interface defines the functionality of a renderer
type SoundEffect ¶
type SoundEffect interface { Play() Stop() SetPan(pan float64) IsPlaying() bool SetVolume(volume float64) }
SoundEffect is something that that the AudioProvider can Play or Stop
type Surface ¶
type Surface interface { Renderer() Renderer Clear(color color.Color) DrawRect(width, height int, color color.Color) DrawLine(x, y int, color color.Color) DrawTextf(format string, params ...interface{}) GetSize() (width, height int) GetDepth() int Pop() PopN(n int) PushColor(color color.Color) PushEffect(effect d2enum.DrawEffect) PushFilter(filter d2enum.Filter) PushTranslation(x, y int) PushSkew(x, y float64) PushScale(x, y float64) PushBrightness(brightness float64) PushSaturation(saturation float64) Render(surface Surface) // Renders a section of the surface enclosed by bounds RenderSection(surface Surface, bound image.Rectangle) ReplacePixels(pixels []byte) Screenshot() *image.RGBA }
Surface represents a renderable surface.
type Terminal ¶
type Terminal interface { BindLogger() Advance(elapsed float64) error OnKeyDown(event KeyEvent) bool OnKeyChars(event KeyCharsEvent) bool Render(surface Surface) error Execute(command string) error Rawf(category d2enum.TermCategory, format string, params ...interface{}) Printf(format string, params ...interface{}) Infof(format string, params ...interface{}) Warningf(format string, params ...interface{}) Errorf(format string, params ...interface{}) Clear() Visible() bool Hide() Show() Bind(name, description string, arguments []string, fn func(args []string) error) error Unbind(name ...string) error }
Terminal is a drop-down terminal and shell It is used throughout the codebase, most parts of the engine will `bind` commands, which are available for use in the shell
type TerminalLogger ¶
TerminalLogger is used tomake the Terminal write out (eg. to the system shell or to a file)