vimman

package module
v0.0.0-...-bb8e8fc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2022 License: MIT Imports: 9 Imported by: 0

README

VimMan

Learn how to use Vim in its natural environment, the Terminal!

About

VimMan is terminal program that's a semi editor and a semi game. The purpose of VimMan is to teach people how to use vim and have fun at the same time!

Installation

git clone https://github.com/ozankasikci/vim-man && cd vim-man

go run cmd/console/vimman.go

to start from a specific level;

LEVEL=2 go run cmd/console/vimman.go

Demo

Level - 1 - Basic movement in Normal Mode

Level - 2 - How to exit Vim

Level - 3 - Basic text editing

Level - 4 - Vimberman!

TODO

  • Add missing levels
    • File save
    • Deletion commands level (dw, d$ vs)
    • Operators and motions
    • Using count
    • Operating on lines
    • Undo & redo
    • Put, replace, change operators
    • Search & substitute
    • Accessing Shell
  • Handle edge cases in some levels
    • level 3

Documentation

Index

Constants

View Source
const LevelBasicMovementTileMapString = `` /* 1306-byte string literal not displayed */
View Source
const LevelBombermanTileMapString = `` /* 515-byte string literal not displayed */
View Source
const LevelExitingVimTileMapString = `` /* 1365-byte string literal not displayed */
View Source
const LevelTextEditingTileMapString = `` /* 1365-byte string literal not displayed */

Variables

View Source
var CommonTileMapCellData = TileMapCellDataMap{
	'0': {
		BgColor:            termbox.ColorBlack,
		FgColor:            termbox.ColorWhite,
		Ch:                 ' ',
		CollidesPhysically: false,
		CollisionCallback:  func() {},
	},
	'↓': {
		BgColor:            termbox.ColorBlack,
		FgColor:            termbox.ColorWhite,
		Ch:                 '↓',
		CollidesPhysically: false,
		CollisionCallback:  func() {},
	},
	'+': {
		BgColor:            termbox.ColorBlack,
		FgColor:            termbox.ColorWhite,
		Ch:                 '+',
		CollidesPhysically: true,
		CollisionCallback:  func() {},
	},
	'-': {
		BgColor:            termbox.ColorBlack,
		FgColor:            termbox.ColorWhite,
		Ch:                 '-',
		CollidesPhysically: true,
		CollisionCallback:  func() {},
	},
	'|': {
		BgColor:            termbox.ColorBlack,
		FgColor:            termbox.ColorWhite,
		Ch:                 '|',
		CollidesPhysically: true,
		CollisionCallback:  func() {},
	},
	'█': {
		BgColor:            termbox.ColorBlack,
		FgColor:            termbox.ColorWhite,
		Ch:                 '█',
		CollidesPhysically: true,
		CollisionCallback:  func() {},
	},
	'◼': {
		BgColor:            termbox.ColorBlack,
		FgColor:            termbox.ColorWhite,
		Ch:                 '◼',
		CollidesPhysically: true,
		CollisionCallback:  func() {},
	},
	'▅': {
		BgColor:            termbox.ColorBlack,
		FgColor:            termbox.ColorWhite,
		Ch:                 '▅',
		CollidesPhysically: true,
		CollisionCallback:  func() {},
	},
	'▀': {
		BgColor:            termbox.ColorBlack,
		FgColor:            termbox.ColorWhite,
		Ch:                 '▀',
		CollidesPhysically: true,
		CollisionCallback:  func() {},
	},
	'☵': {
		BgColor:            termbox.ColorBlack,
		FgColor:            termbox.ColorWhite,
		Ch:                 '☵',
		CollidesPhysically: true,
		CollisionCallback:  func() {},
	},
	'☲': {
		BgColor:            termbox.ColorBlack,
		FgColor:            termbox.ColorWhite,
		Ch:                 '☲',
		CollidesPhysically: true,
		CollisionCallback:  func() {},
	},
	' ': {
		BgColor:            termbox.ColorBlack,
		FgColor:            termbox.ColorWhite,
		Ch:                 ' ',
		CollidesPhysically: false,
		CollisionCallback:  func() {},
	},
}

Functions

func ContainsRune

func ContainsRune(s []rune, e rune) bool

func ContainsString

func ContainsString(s []string, e string) bool

func ContainsTermboxKey

func ContainsTermboxKey(s []termbox.Key, e termbox.Key) bool

func Init

func Init(level int)

func MinInt

func MinInt(a, b int) int

func ParseLine

func ParseLine(l string) []rune

func ParseTileMapString

func ParseTileMapString(tileMap string) [][]rune

Types

type Canvas

type Canvas [][]*TermBoxCell

func NewCanvas

func NewCanvas(width, height int) Canvas

func (Canvas) CheckCollision

func (c Canvas) CheckCollision(x, y int) bool

func (Canvas) GetCellAt

func (c Canvas) GetCellAt(x, y int) *TermBoxCell

func (*Canvas) IsInLastColumn

func (c *Canvas) IsInLastColumn(x int) bool

func (*Canvas) IsInsideOfBoundaries

func (c *Canvas) IsInsideOfBoundaries(x, y int) bool

func (*Canvas) OverWriteCanvasCell

func (c *Canvas) OverWriteCanvasCell(x, y int, termboxCell *TermBoxCell)

func (*Canvas) SetCellAt

func (c *Canvas) SetCellAt(row, column int, cell *TermBoxCell)

type Class

type Class int

type Direction

type Direction int

type Entity

type Entity struct {
	Stage        *Stage
	Position     Point
	Width        int
	Height       int
	Rune         rune
	Cell         *TermBoxCell
	Cells        []*TermBoxCell
	DrawPriority int
	Tags         []Tag
	InitCallback func()
}

func NewEntity

func NewEntity(s *Stage, x, y, w, h int, r rune, fg termbox.Attribute, bg termbox.Attribute, cells []*TermBoxCell, collidesPhysically bool, options EntityOptions) *Entity

func (*Entity) Destroy

func (e *Entity) Destroy()

func (*Entity) GetCells

func (e *Entity) GetCells() []*TermBoxCell

func (*Entity) GetDrawPriority

func (e *Entity) GetDrawPriority() int

func (*Entity) GetPosition

func (e *Entity) GetPosition() (int, int)

func (*Entity) GetPositionX

func (e *Entity) GetPositionX() int

func (*Entity) GetPositionY

func (e *Entity) GetPositionY() int

func (*Entity) GetScreenOffset

func (e *Entity) GetScreenOffset() (int, int)

func (*Entity) GetStage

func (e *Entity) GetStage() *Stage

func (*Entity) GetTags

func (e *Entity) GetTags() []Tag

func (*Entity) IsInsideOfCanvasBoundaries

func (e *Entity) IsInsideOfCanvasBoundaries() bool

func (*Entity) SetCells

func (e *Entity) SetCells(s *Stage)

func (*Entity) SetPosition

func (e *Entity) SetPosition(x, y int)

func (*Entity) SetPositionX

func (e *Entity) SetPositionX(x int)

func (*Entity) SetPositionY

func (e *Entity) SetPositionY(y int)

func (*Entity) SetStage

func (e *Entity) SetStage(s *Stage)

func (*Entity) Update

func (e *Entity) Update(s *Stage, event termbox.Event, time time.Duration)

type EntityOptions

type EntityOptions struct {
	DrawPriority int
	Tags         []Tag
	InitCallback func()
}

type Game

type Game struct {
	Stage *Stage

	VimManEvents chan VimManEvent
	// contains filtered or unexported fields
}

func NewGame

func NewGame(opts GameOptions) *Game

type GameOptions

type GameOptions struct {
	VimManEvents chan VimManEvent
	// contains filtered or unexported fields
}

type Level

type Level struct {
	Game                 *Game
	VimMode              VimMode
	TileMapString        string
	TileMap              [][]*TermBoxCell
	TileData             TileMapCellDataMap
	Entities             []Renderer
	InputRunes           []rune
	BlockedKeys          []termbox.Key
	InputBlocked         bool
	TextShiftingDisabled bool
	BgCell               *termbox.Cell
	Width                int
	Height               int
	Init                 func()
	ColonLineCallbacks   map[string]func(game *Game)
}

func NewLevelBasicMovement

func NewLevelBasicMovement(g *Game) *Level

func NewLevelBomberman

func NewLevelBomberman(g *Game) *Level

func NewLevelExitingVim

func NewLevelExitingVim(g *Game) *Level

func NewLevelTextEditing

func NewLevelTextEditing(g *Game) *Level

func (*Level) GetScreenOffset

func (l *Level) GetScreenOffset() (int, int)

func (*Level) GetSize

func (l *Level) GetSize() (int, int)

func (*Level) GetTileMapDimensions

func (l *Level) GetTileMapDimensions() (int, int)

row, length

func (*Level) InitDefaults

func (l *Level) InitDefaults()

func (*Level) LoadTileMap

func (l *Level) LoadTileMap()

func (*Level) LoadTileMapCells

func (l *Level) LoadTileMapCells(parsedRunes [][]rune) [][]*TermBoxCell

func (*Level) SetCells

func (l *Level) SetCells(s *Stage)

func (*Level) Update

func (l *Level) Update(s *Stage, t time.Duration)

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

func GetLogger

func GetLogger() *Logger

func (*Logger) DumpLogs

func (l *Logger) DumpLogs()

func (*Logger) Log

func (l *Logger) Log(strings ...string)

func (*Logger) LogValue

func (l *Logger) LogValue(values ...interface{})

func (*Logger) WriteFile

func (l *Logger) WriteFile(text string)

type Point

type Point struct {
	// contains filtered or unexported fields
}

type Renderer

type Renderer interface {
	Update(*Stage, termbox.Event, time.Duration)
	Destroy()
	SetCells(*Stage)
	GetCells() []*TermBoxCell
	GetPosition() (int, int)
	GetPositionX() int
	GetPositionY() int
	SetPositionX(int)
	GetScreenOffset() (int, int)
	GetDrawPriority() int
	GetTags() []Tag
	ShouldCenterHorizontally() bool
}

type Stage

type Stage struct {
	Game           *Game
	Level          int
	LevelInstance  *Level
	Fps            float64
	CanvasEntities []Renderer // entities to be rendered in canvas
	ScreenEntities []Renderer // entities to be rendered outside of the canvas
	TypedEntities  []Renderer
	BgCell         *termbox.Cell
	Canvas         Canvas
	Width          int
	Height         int

	ModeLabel *Word
	ColonLine *Word
	// contains filtered or unexported fields
}

holds the current level meta data, canvas and entities

func NewStage

func NewStage(g *Game, level int, fps float64, bgCell *termbox.Cell) *Stage

func (*Stage) AddCanvasEntity

func (s *Stage) AddCanvasEntity(e ...Renderer)

func (*Stage) AddScreenEntity

func (s *Stage) AddScreenEntity(e ...Renderer)

func (*Stage) AddTypedEntity

func (s *Stage) AddTypedEntity(e ...Renderer)

func (*Stage) CheckCollision

func (s *Stage) CheckCollision(x, y int) bool

func (*Stage) ClearCanvasEntities

func (s *Stage) ClearCanvasEntities()

func (*Stage) ClearTileMapCellsAt

func (s *Stage) ClearTileMapCellsAt(positions [][2]int)

clear Canvas cell and TileMap cell at the given positions

func (*Stage) GetDefaultBgCell

func (s *Stage) GetDefaultBgCell() *TermBoxCell

func (*Stage) GetRendererEntityByTag

func (s *Stage) GetRendererEntityByTag(wantedTag Tag) Renderer

func (*Stage) Init

func (s *Stage) Init()

func (*Stage) Render

func (s *Stage) Render()

this function handles all the rendering sets and renders in order: tilemap cells: the background cells canvas entities: canvas entities, they have update methods that gets called on stage.update method screen cells: cells outside of the canvas such as level label and instructions

func (*Stage) Reset

func (s *Stage) Reset()

func (*Stage) Resize

func (s *Stage) Resize(w, h int)

func (*Stage) SetCanvasBackgroundCells

func (s *Stage) SetCanvasBackgroundCells()

sets the background cells to be rendered, this gets rendered first in the render method so that other cells can be overwritten into the same location

func (*Stage) SetGame

func (s *Stage) SetGame(game *Game)

func (*Stage) SetLevel

func (s *Stage) SetLevel(levelInstance *Level)

func (*Stage) TermboxSetCanvasCells

func (s *Stage) TermboxSetCanvasCells()

sets the cells inside the canvas, offset is being applied in order to keep the canvas in center

func (*Stage) TermboxSetCell

func (s *Stage) TermboxSetCell(x, y int, cell *TermBoxCell, offset bool)

calls termbox.setCell, sets the coordinates and the cell attributes this does the actual rendering of the characters, thanks to termbox-go <3

func (*Stage) TermboxSetCursorCell

func (s *Stage) TermboxSetCursorCell()

func (*Stage) TermboxSetScreenCells

func (s *Stage) TermboxSetScreenCells()

sets the cells outside of the canvas, no offset is being applied

func (*Stage) TermboxSetTypedCells

func (s *Stage) TermboxSetTypedCells()

type Tag

type Tag struct {
	Name string
}

type TermBoxCell

type TermBoxCell struct {
	*termbox.Cell
	// contains filtered or unexported fields
}

func ConvertStringToCells

func ConvertStringToCells(s string, fg termbox.Attribute, bg termbox.Attribute) []*TermBoxCell

func EmptyTileMapCell

func EmptyTileMapCell() *TermBoxCell

type TileMapCellData

type TileMapCellData struct {
	Ch                 rune
	BgColor            termbox.Attribute
	FgColor            termbox.Attribute
	CollidesPhysically bool
	CollisionCallback  func()
	InitCallback       func(*Entity)
	LineNumber         int
}

func NewTileMapCell

func NewTileMapCell(ch rune, fn func(), lineNumber int) TileMapCellData

type TileMapCellDataMap

type TileMapCellDataMap map[rune]TileMapCellData

type User

type User struct {
	*Entity
}

func NewUser

func NewUser(s *Stage, x, y int) (u *User)

func (*User) ShouldCenterHorizontally

func (u *User) ShouldCenterHorizontally() bool

func (*User) Update

func (u *User) Update(s *Stage, event termbox.Event, delta time.Duration)

type VimManEvent

type VimManEvent struct {
	Content string
}

type VimMode

type VimMode int

func (VimMode) String

func (m VimMode) String() string

type Word

type Word struct {
	*Entity
	Content            string
	Speed              float64
	Direction          Direction
	CenterHorizontally bool
	Fg                 termbox.Attribute
	Bg                 termbox.Attribute
}

func NewEmptyCharacter

func NewEmptyCharacter(s *Stage, x, y int, options WordOptions) *Word

func NewWord

func NewWord(s *Stage, x, y int, content string, options WordOptions) *Word

func (*Word) ShouldCenterHorizontally

func (w *Word) ShouldCenterHorizontally() bool

func (*Word) Update

func (w *Word) Update(s *Stage, event termbox.Event, delta time.Duration)

type WordOptions

type WordOptions struct {
	InitCallback       func()
	Fg                 termbox.Attribute
	Bg                 termbox.Attribute
	CollidesPhysically bool
	CenterHorizontally bool
	Tags               []Tag
}

func DefaultWordOptions

func DefaultWordOptions() WordOptions

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL