Documentation
¶
Index ¶
- Constants
- Variables
- func ChangeScreen(to Screen) tea.Cmd
- func ToDefaultCharacterStyle(r rune) lipgloss.Style
- type AdventureGameState
- type Character
- type Characters
- type GameSave
- type GameState
- type HighScore
- type Level
- type LifetimeStats
- type Player
- type PlayerMovement
- type Position
- type SavedLevel
- type Screen
- type ScreenTransitionMsg
- type Section
- type SetLevelMsg
- type SetPlayerMsg
- type Stats
- type Style
- type Target
- type TargetBehavior
- type UpdateLoadButtonMsg
Constants ¶
const PlayerNameMaxLength = 20
const StatsFormat = "Keystrokes: %d Time: %d s"
StatsFormat is the format string for displaying stats
Variables ¶
var BramTribute = style.Styles.Display.SpecialText.Render(tributeText)
BramTribute contains a tribute to Bram Moolenaar, the creator of Vim
var CheatsheetSection = []Section{
{
Title: "Vim Modes",
Content: `Vim operates in several modes, each with a specific purpose:
- **Normal Mode**: The default mode for navigation and running commands.
- Press **ESC** to return to Normal Mode from any other mode.
- **Insert Mode**: For inserting and editing text.
- Enter Insert Mode with **i** (insert before cursor), **a** (append after cursor), or **o** (open a new line).
- **Visual Mode**: For selecting and manipulating text.
- Enter Visual Mode with **v** (character-wise selection), **V** (line-wise selection), or **Ctrl-v** (block selection).
- **Command Mode**: For executing advanced commands like saving, quitting, or searching.
- Enter Command Mode with **:** (colon), then type commands like **:w** (save) or **:q** (quit).`,
},
{
Title: "Basic Motions",
Content: `- **h**: Move left by one character.
- **l**: Move right by one character.
- **j**: Move down one line.
- **k**: Move up one line.`,
},
{
Title: "Advanced Motions",
Content: `- **w**: Jump to the start of the next word.
- **e**: Jump to the end of the current/next word.
- **b**: Jump to the start of the previous word.`,
},
{
Title: "Combining Motions with Numbers",
Content: `- **[number][motion]**: Repeat a motion multiple times.
- **2w**: Jump forward two words.
- **3e**: Jump to the end of the next three words.
- **4j**: Move down four lines.`,
},
{
Title: "Using Motions with Commands",
Content: `Motions can be combined with commands to perform actions:
- **d[motion]**: Delete up to the motion (e.g., **dw** deletes the current word).
- **y[motion]**: Copy (yank) up to the motion (e.g., **y2w** copies the next two words).
- **c[motion]**: Change (delete and switch to insert mode) up to the motion (e.g., **c3j** changes the next three lines).`,
},
{
Title: "Essential Commands",
Content: `- **:w**: Save the current file.
- **:q**: Quit Vim.
- **:wq**: Save and quit.
- **:q!**: Quit without saving changes.
- **ZZ**: Save and quit (shortcut).`,
},
}
CheatsheetSection contains the sections of information to be displayed on the Vim Cheatsheet screen
var DefaultCharacters = Characters{ Player: struct { Cursor Character Trail Character }{ Cursor: Character{'$', "$"}, Trail: Character{'·', "·"}, }, Target: struct { Active Character Inactive Character Reached Character }{ Active: Character{'X', "X"}, Inactive: Character{'x', "x"}, Reached: Character{'✓', "✓"}, }, Wall: Character{'#', "#"}, }
DefaultCharacters represents the default characters in the app
var VimInfoSections = []Section{
{
Title: "What is Vim?",
Content: `Vim (Vi IMproved) is a powerful and efficient text editor, originally derived from the Vi editor in 1991.
It is widely used for its speed and ability to handle tasks with minimal effort,
making it a favorite tool for developers and system administrators.`,
},
{
Title: "Why Use Vim?",
Content: `Vim offers unmatched efficiency and productivity, making it a favorite among developers and system administrators.
Key features include:
- **Speed**: Optimized for keyboard-driven workflows, enabling faster text editing.
- **Modal Editing**: Switch between modes for navigation, editing, and selection, making it powerful and efficient.
- **Platform Independence**: Available on almost all systems, including POSIX and Unix-based platforms.
- **Customizability**: Personalize Vim with plugins, keybindings, and themes to suit your workflow.
- **Performance**: Designed to work in any environment, from lightweight terminals to advanced setups.
- **Availability**: Pre-installed on most Unix-based systems, ensuring it's accessible almost anywhere.`,
},
{
Title: "Key Vim Motions",
Content: `Vim motions are essential for navigating text efficiently. Here are some of the most important ones:
- **h**: Move left by one character.
- **l**: Move right by one character.
- **j**: Move down one line.
- **k**: Move up one line.
- **w**: Jump to the beginning of the next word.
- **b**: Jump to the beginning of the previous word.
Mastering these motions is the first step toward becoming proficient in Vim.`,
},
{
Title: "The Philosophy of Vim:",
Content: `Vim embraces the philosophy of efficiency through practice. It has a learning curve, but as you grow familiar
with its commands and capabilities, it becomes a tool that adapts to your needs, making your workflow faster
and more seamless.`,
},
{
Title: "Additional information:",
Content: `For more information on Vim, visit the official website at https://www.vim.org/
For a comprehensive guide on Vim, check out the Vim documentation at https://vimhelp.org/`,
},
}
VimInfoSections contains the sections of information to be displayed on the Vim Information screen
Functions ¶
func ChangeScreen ¶
ChangeScreen returns a command to change the current screen to the specified screen
func ToDefaultCharacterStyle ¶
ToDefaultCharacterStyle maps a rune to a default character style
Types ¶
type AdventureGameState ¶
type AdventureGameState struct {
WindowSize tea.WindowSizeMsg `json:"window_size"`
Level SavedLevel `json:"level"`
Stats Stats `json:"stats"`
SaveID string `json:"save_id"`
}
AdventureGameState represents the controllers of an adventure game
func (AdventureGameState) IsCompleted ¶
func (ags AdventureGameState) IsCompleted() bool
IsCompleted returns true if the level is completed
type Characters ¶
type Characters struct {
Player struct {
Cursor Character
Trail Character
}
Target struct {
Active Character
Inactive Character
Reached Character
}
Wall Character
}
Characters represents the app characters
type GameSave ¶
type GameSave struct {
ID string `json:"id"`
Player Player `json:"player"`
Timestamp time.Time `json:"timestamp"`
GameMode string `json:"game_mode"`
GameState GameState `json:"game_state"`
Score int `json:"score"`
}
GameSave represents a saved game
func (*GameSave) MarshalJSON ¶
MarshalJSON encodes a GameSave to JSON
func (*GameSave) UnmarshalJSON ¶
UnmarshalJSON decodes a GameSave from JSON
type GameState ¶
type GameState interface {
IsCompleted() bool
}
GameState represents the controllers of a game
type HighScore ¶
type HighScore struct {
PlayerName string `json:"player_name"`
Level int `json:"level"`
Score int `json:"score"`
Timestamp time.Time `json:"timestamp"`
}
HighScore represents a player's high score entry
type Level ¶
type Level interface {
Number() int
Description() string
Init(width, height int)
PlayerMove(position Position) PlayerMovement
PlacePlayer(position Position)
Render() [][]rune
GetStartPosition() Position
GetCurrentPosition() Position
GetTargets() []Target
GetCurrentTarget() int
GetInstructions() string
InProgress() bool
IsCompleted() bool
Restore(state SavedLevel) error
Exit()
}
Level represents a level in the adventure mode
type LifetimeStats ¶
type LifetimeStats struct {
TotalKeystrokes int `json:"total_keystrokes"`
TotalPlaytime int `json:"total_playtime"`
TotalGames int `json:"total_games"`
KeyPresses map[string]int `json:"key_presses"`
}
LifetimeStats represents aggregated statistics for all games
func NewLifetimeStats ¶
func NewLifetimeStats() *LifetimeStats
NewLifetimeStats initializes an empty LifetimeStats
func (*LifetimeStats) Merge ¶
func (ls *LifetimeStats) Merge(stats Stats)
Merge aggregates stats from another Stats instance
type PlayerMovement ¶
type PlayerMovement struct {
UpdatedPosition Position
Completed bool
ValidMove bool
InstructionMessage string
}
PlayerMovement represents the result of a player action
type SavedLevel ¶
type SavedLevel struct {
Number int `json:"number"`
Width int `json:"width"`
Height int `json:"height"`
PlayerPosition Position `json:"player_position"`
Targets []Target `json:"targets"`
CurrentTarget int `json:"current_target"`
Completed bool `json:"completed"`
InProgress bool `json:"in_progress"`
}
SavedLevel represents a saved level
type Screen ¶
type Screen uint8
Screen represents the different screens available in the app
const ( // MainMenuScreen represents the main menu screen MainMenuScreen Screen = iota // InfoMenuScreen represents the information menu screen InfoMenuScreen // VimInfoScreen represents the vim information screen VimInfoScreen // CheatsheetInfoScreen represents the cheatsheet information screen CheatsheetInfoScreen // NewGameScreen represents the new app screen NewGameScreen // PlayerSelectionScreen represents the player selection screen PlayerSelectionScreen // LevelSelectionScreen represents the level selection screen LevelSelectionScreen // LoadSaveSelectionScreen represents the load save screen LoadSaveSelectionScreen // AdventureModeScreen represents the adventure app mode screen AdventureModeScreen // StatsScreen represents the stats screen StatsScreen // ScoresScreen represents the scores screen ScoresScreen )
type ScreenTransitionMsg ¶
ScreenTransitionMsg represents a message to transition to a different screen
type Section ¶
Section represents a section of information to be displayed on the Vim Information screen
type SetLevelMsg ¶
type SetLevelMsg struct {
LevelNumber int
}
SetLevelMsg represents a message to set the level for the game modes
type SetPlayerMsg ¶
type SetPlayerMsg struct {
Player Player
}
SetPlayerMsg represents a message to set the player for the game modes
type Stats ¶
type Stats struct {
KeyPresses map[string]int `json:"key_presses"`
TotalKeystrokes int `json:"total_keystrokes"`
TimeElapsed int `json:"time_elapsed"`
}
Stats represent the statistics of a game
func (*Stats) IncrementTime ¶
func (s *Stats) IncrementTime()
IncrementTime increments the time counter
func (*Stats) RegisterKey ¶
RegisterKey increments the count for a given key if allowed
type TargetBehavior ¶
type TargetBehavior interface {
DefineTargets(width, height int) []Target
UpdateGrid(grid [][]rune, targets []Target, current int, chars *Characters)
GetTargetCount() int
}
TargetBehavior defines the behavior of a target
type UpdateLoadButtonMsg ¶
type UpdateLoadButtonMsg struct {
CanLoadGame bool
}
UpdateLoadButtonMsg represents a message to update the load button