Documentation
¶
Index ¶
- Constants
- func Color256(u uint8) *color.Color
- func CreateWebView(opts dgclient.ViewOptions) (dgclient.View, error)
- func SaveTilesetConfig(tileset *TilesetConfig, path string) error
- type Cell
- type CellDiff
- type ColorConverter
- type Empty
- type GameInputParams
- type GamePollParams
- type GameService
- func (s *GameService) GetState(r *http.Request, args *Empty, reply *map[string]interface{}) error
- func (s *GameService) Poll(r *http.Request, args *GamePollParams, reply *map[string]interface{}) error
- func (s *GameService) SendInput(r *http.Request, args *GameInputParams, reply *map[string]interface{}) error
- type GameState
- type InputEvent
- type RPCError
- type RPCHandler
- type RPCRequest
- type RPCResponse
- type SessionService
- type SpecialTile
- type StateDiff
- type StateManager
- func (sm *StateManager) GetCurrentState() *GameState
- func (sm *StateManager) GetCurrentVersion() uint64
- func (sm *StateManager) PollChanges(clientVersion uint64, timeout time.Duration) (*StateDiff, error)
- func (sm *StateManager) PollChangesWithContext(pollCtx context.Context, version uint64) (*StateDiff, error)
- func (sm *StateManager) UpdateState(state *GameState)
- type TileMapping
- type TileRef
- type TilesetConfig
- type TilesetService
- type WebUI
- func (w *WebUI) GetTileset() *TilesetConfig
- func (w *WebUI) GetView() *WebView
- func (w *WebUI) ServeHTTP(rw http.ResponseWriter, r *http.Request)
- func (w *WebUI) SetView(view *WebView)
- func (w *WebUI) Start(addr string) error
- func (w *WebUI) StartWithContext(ctx context.Context, addr string) error
- func (w *WebUI) UpdateTileset(tileset *TilesetConfig) error
- type WebUIOptions
- type WebView
- func (v *WebView) Clear() error
- func (v *WebView) Close() error
- func (v *WebView) GetCurrentState() *GameState
- func (v *WebView) GetSize() (int, int)
- func (v *WebView) GetStateManager() *StateManager
- func (v *WebView) HandleInput() ([]byte, error)
- func (v *WebView) Init() error
- func (v *WebView) Render(data []byte) error
- func (v *WebView) SendInput(data []byte)
- func (v *WebView) SetSize(width, height int) error
- func (v *WebView) SetTileset(tileset *TilesetConfig)
- func (v *WebView) WaitForUpdate(timeout time.Duration) bool
Constants ¶
const ( ParseError = -32700 InvalidRequest = -32600 MethodNotFound = -32601 InvalidParams = -32602 InternalError = -32603 )
Standard JSON-RPC error codes
Variables ¶
This section is empty.
Functions ¶
func CreateWebView ¶
func CreateWebView(opts dgclient.ViewOptions) (dgclient.View, error)
CreateWebView creates a new WebView that implements dgclient.View
func SaveTilesetConfig ¶
func SaveTilesetConfig(tileset *TilesetConfig, path string) error
SaveTilesetConfig saves a tileset configuration to a YAML file
Types ¶
type Cell ¶
type Cell struct {
Char rune `json:"char"`
FgColor string `json:"fg_color"`
BgColor string `json:"bg_color"`
Bold bool `json:"bold"`
Inverse bool `json:"inverse"`
Blink bool `json:"blink"`
TileX int `json:"tile_x,omitempty"`
TileY int `json:"tile_y,omitempty"`
Changed bool `json:"-"`
}
Cell represents a single character cell with rendering attributes
type ColorConverter ¶
type ColorConverter struct{}
ColorConverter handles ANSI color parsing and conversion using fatih/color library
func NewColorConverter ¶
func NewColorConverter() *ColorConverter
NewColorConverter creates a new color converter with ANSI256 profile NewColorConverter creates a new color converter
func (*ColorConverter) ProcessSGRParams ¶
func (cc *ColorConverter) ProcessSGRParams(params []string) (fgColor, bgColor string, bold, inverse, blink bool)
ProcessSGRParams processes SGR (Select Graphic Rendition) parameters Returns foreground color, background color, and text attributes
type GameInputParams ¶
type GameInputParams struct {
Events []InputEvent `json:"events"`
}
type GamePollParams ¶
type GamePollParams struct {
Version uint64 `json:"version"`
Timeout int `json:"timeout,omitempty"`
}
Parameter types for RPC methods
type GameService ¶
type GameService struct {
// contains filtered or unexported fields
}
Service structs for Gorilla RPC
func (*GameService) Poll ¶
func (s *GameService) Poll(r *http.Request, args *GamePollParams, reply *map[string]interface{}) error
func (*GameService) SendInput ¶
func (s *GameService) SendInput(r *http.Request, args *GameInputParams, reply *map[string]interface{}) error
type GameState ¶
type GameState struct {
Buffer [][]Cell `json:"buffer"`
Width int `json:"width"`
Height int `json:"height"`
CursorX int `json:"cursor_x"`
CursorY int `json:"cursor_y"`
Version uint64 `json:"version"`
Timestamp int64 `json:"timestamp"`
}
GameState represents the current state of the game screen
type InputEvent ¶
type RPCHandler ¶
type RPCHandler struct {
// contains filtered or unexported fields
}
RPCHandler maintains compatibility with existing code
func NewRPCHandler ¶
func NewRPCHandler(webui *WebUI) *RPCHandler
NewRPCHandler creates a new RPC handler with Gorilla RPC integration
func (*RPCHandler) GetRPCServer ¶
func (h *RPCHandler) GetRPCServer() *rpc.Server
GetRPCServer returns the underlying Gorilla RPC server for HTTP integration
func (*RPCHandler) HandleRequest ¶
func (h *RPCHandler) HandleRequest(ctx context.Context, req *RPCRequest) *RPCResponse
HandleRequest preserves the original signature for compatibility
type RPCRequest ¶
type RPCRequest struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
ID interface{} `json:"id"`
}
Legacy types preserved for compatibility
type RPCResponse ¶
type SessionService ¶
type SessionService struct {
// contains filtered or unexported fields
}
type SpecialTile ¶
SpecialTile represents multi-tile entities
type StateDiff ¶
type StateDiff struct {
Version uint64 `json:"version"`
Changes []CellDiff `json:"changes"`
CursorX int `json:"cursor_x"`
CursorY int `json:"cursor_y"`
Timestamp int64 `json:"timestamp"`
}
StateDiff represents changes between game states
type StateManager ¶
type StateManager struct {
// contains filtered or unexported fields
}
StateManager manages game state versions and change tracking
func NewStateManager ¶
func NewStateManager() *StateManager
NewStateManager creates a new state manager
func (*StateManager) GetCurrentState ¶
func (sm *StateManager) GetCurrentState() *GameState
GetCurrentState returns the current state
func (*StateManager) GetCurrentVersion ¶
func (sm *StateManager) GetCurrentVersion() uint64
GetCurrentVersion returns the current version number
func (*StateManager) PollChanges ¶
func (sm *StateManager) PollChanges(clientVersion uint64, timeout time.Duration) (*StateDiff, error)
PollChanges waits for changes since the given client version
func (*StateManager) PollChangesWithContext ¶
func (sm *StateManager) PollChangesWithContext(pollCtx context.Context, version uint64) (*StateDiff, error)
PollChangesWithContext waits for changes with a context It is a context-aware version of PollChanges
func (*StateManager) UpdateState ¶
func (sm *StateManager) UpdateState(state *GameState)
UpdateState updates the current state and notifies waiters
type TileMapping ¶
type TileMapping struct {
Char string `yaml:"char"`
X int `yaml:"x"`
Y int `yaml:"y"`
FgColor string `yaml:"fg_color,omitempty"`
BgColor string `yaml:"bg_color,omitempty"`
// contains filtered or unexported fields
}
TileMapping maps characters to tile coordinates
type TilesetConfig ¶
type TilesetConfig struct {
Name string `yaml:"name"`
Version string `yaml:"version"`
TileWidth int `yaml:"tile_width"`
TileHeight int `yaml:"tile_height"`
SourceImage string `yaml:"source_image"`
Mappings []TileMapping `yaml:"mappings"`
SpecialTiles []SpecialTile `yaml:"special_tiles"`
// contains filtered or unexported fields
}
TilesetConfig represents a tileset configuration
func DefaultTilesetConfig ¶
func DefaultTilesetConfig() *TilesetConfig
DefaultTilesetConfig returns a basic ASCII tileset configuration
func LoadTilesetConfig ¶
func LoadTilesetConfig(path string) (*TilesetConfig, error)
LoadTilesetConfig loads a tileset from a YAML file
func (*TilesetConfig) Clone ¶
func (tc *TilesetConfig) Clone() *TilesetConfig
Clone creates a deep copy of the tileset configuration
func (*TilesetConfig) GetImageData ¶
func (tc *TilesetConfig) GetImageData() image.Image
GetImageData returns the loaded image data
func (*TilesetConfig) GetMapping ¶
func (tc *TilesetConfig) GetMapping(char rune) *TileMapping
GetMapping returns the tile mapping for a character
func (*TilesetConfig) GetTileCount ¶
func (tc *TilesetConfig) GetTileCount() (int, int)
GetTileCount returns the number of tiles in the tileset
func (*TilesetConfig) ToJSON ¶
func (tc *TilesetConfig) ToJSON() map[string]interface{}
ToJSON returns a JSON representation for client-side use
type TilesetService ¶
type TilesetService struct {
// contains filtered or unexported fields
}
func (*TilesetService) Update ¶
func (s *TilesetService) Update(r *http.Request, args *json.RawMessage, reply *map[string]interface{}) error
type WebUI ¶
type WebUI struct {
// contains filtered or unexported fields
}
WebUI provides a web-based interface for dgclient
func NewWebUI ¶
func NewWebUI(opts WebUIOptions) (*WebUI, error)
NewWebUI creates a new WebUI instance
func (*WebUI) GetTileset ¶
func (w *WebUI) GetTileset() *TilesetConfig
GetTileset returns the current tileset configuration
func (*WebUI) ServeHTTP ¶
func (w *WebUI) ServeHTTP(rw http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler
func (*WebUI) StartWithContext ¶
StartWithContext starts the WebUI server with context for graceful shutdown
func (*WebUI) UpdateTileset ¶
func (w *WebUI) UpdateTileset(tileset *TilesetConfig) error
UpdateTileset updates the tileset configuration
type WebUIOptions ¶
type WebUIOptions struct {
// View to use for rendering
View *WebView
// Tileset configuration
TilesetPath string
Tileset *TilesetConfig
// Server configuration
ListenAddr string
PollTimeout time.Duration
// CORS settings
AllowOrigins []string
// Static file serving
StaticPath string // Optional: override embedded files
}
WebUIOptions contains configuration for WebUI
type WebView ¶
type WebView struct {
// contains filtered or unexported fields
}
WebView implements dgclient.View for web browser rendering
func NewWebView ¶
func NewWebView(opts dgclient.ViewOptions) (*WebView, error)
NewWebView creates a new web-based view
func (*WebView) GetCurrentState ¶
GetCurrentState returns the current game state
func (*WebView) GetStateManager ¶
func (v *WebView) GetStateManager() *StateManager
GetStateManager returns the state manager for this view
func (*WebView) HandleInput ¶
HandleInput reads and returns user input
func (*WebView) SetTileset ¶
func (v *WebView) SetTileset(tileset *TilesetConfig)
SetTileset updates the tileset configuration