goro

package module
v0.0.0-...-117f852 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2022 License: GPL-3.0 Imports: 9 Imported by: 4

README

Going Rogue / goRo

This library is for writing roguelikes in Go. Please note that it is highly experimental at the moment.

Building

goRo can have the following tags supplied during building:

  • disableTCell
  • enableEbiten

If you wish to use the graphical interface only:

# go build -tags "disableTCell enableEbiten"

If you wish to use the terminal interface only:

# go build

If you wish to have support for both and choose one programmatically:

# go build -tags "enableEbiten"

Documentation

Index

Constants

View Source
const (
	KeyNull Key = iota

	KeyBackspace
	KeyTab

	KeyReturn

	KeyEscape

	KeySpace
	KeyExclaim
	KeyDoubleQuote
	KeyHash
	KeyDollar
	KeyPercent
	KeyAmpersand
	KeyQuote
	KeyLeftParenthesis
	KeyRightParenthesis
	KeyAsterisk
	KeyPlus
	KeyComma
	KeyMinus
	KeyPeriod
	KeySlash
	Key0
	Key1
	Key2
	Key3
	Key4
	Key5
	Key6
	Key7
	Key8
	Key9
	KeyColon
	KeySemiColon
	KeyLess
	KeyEqual
	KeyGreater
	KeyQuestion
	KeyAt
	KeyLeftBracket = iota + 26
	KeyBackslash
	KeyRightBracket
	KeyCaret
	KeyUnderscore
	KeyBackquote
	KeyA
	KeyB
	KeyC
	KeyD
	KeyE
	KeyF
	KeyG
	KeyH
	KeyI
	KeyJ
	KeyK
	KeyL
	KeyM
	KeyN
	KeyO
	KeyP
	KeyQ
	KeyR
	KeyS
	KeyT
	KeyU
	KeyV
	KeyW
	KeyX
	KeyY
	KeyZ
	KeyLeftCurlyBracket
	KeyPipe
	KeyRightCurlyBracket
	KeyGraveAccent
	KeyDelete
	KeyAlt
	KeyControl
	KeyShift
	KeyCapsLock
	KeyEnd
	KeyMenu
	KeyHome
	KeyPrintScreen
	KeyScrollLock
	KeyEnter
	KeyInsert
	KeyPageUp
	KeyPageDown
	KeyPause
	KeySemicolon
	KeyApostrophe
	KeyF1
	KeyF2
	KeyF3
	KeyF4
	KeyF5
	KeyF6
	KeyF7
	KeyF8
	KeyF9
	KeyF10
	KeyF11
	KeyF12
	KeyNumLock
	KeyKP0
	KeyKP1
	KeyKP2
	KeyKP3
	KeyKP4
	KeyKP5
	KeyKP6
	KeyKP7
	KeyKP8
	KeyKP9
	KeyKPAdd
	KeyKPPeriod
	KeyKPDivide
	KeyKPDecimal
	KeyKPEnter
	KeyKPEqual
	KeyKPMultiply
	KeyKPSubtract
	KeyLeft
	KeyUp
	KeyRight
	KeyDown
)

These are our constant key variables.

View Source
const (
	UnitCells = iota
	UnitPixels
)

Units a backend might use.

Variables

View Source
var (
	ColorNone    = Color{0x00, 0x00, 0x00, 0x00}
	Color0       = Color{0x00, 0x00, 0x00, 0xFF}
	Color1       = Color{0x80, 0x00, 0x00, 0xFF}
	Color2       = Color{0x00, 0x80, 0x00, 0xFF}
	Color3       = Color{0x80, 0x80, 0x00, 0xFF}
	Color4       = Color{0x00, 0x00, 0x80, 0xFF}
	Color5       = Color{0x80, 0x00, 0x80, 0xFF}
	Color6       = Color{0x00, 0x80, 0x80, 0xFF}
	Color7       = Color{0xC0, 0xC0, 0xC0, 0xFF}
	Color8       = Color{0x80, 0x80, 0x80, 0xFF}
	Color9       = Color{0xFF, 0x00, 0x00, 0xFF}
	Color10      = Color{0x00, 0xFF, 0x00, 0xFF}
	Color11      = Color{0xFF, 0xFF, 0x00, 0xFF}
	Color12      = Color{0x00, 0x00, 0xFF, 0xFF}
	Color13      = Color{0xFF, 0x00, 0xFF, 0xFF}
	Color14      = Color{0x00, 0xFF, 0xFF, 0xFF}
	Color15      = Color{0xFF, 0xFF, 0xFF, 0xFF}
	ColorBlack   = Color0
	ColorMaroon  = Color1
	ColorGreen   = Color2
	ColorOlive   = Color3
	ColorNavy    = Color4
	ColorPurple  = Color5
	ColorTeal    = Color6
	ColorSilver  = Color7
	ColorGray    = Color8
	ColorRed     = Color9
	ColorLime    = Color10
	ColorYellow  = Color11
	ColorBlue    = Color12
	ColorFuchsia = Color13
	ColorAqua    = Color14
	ColorWhite   = Color15
)

These colors represent the default 8 color and 8 bright colors.

View Source
var Random = rand.New(rand.NewSource(0))

Random is our global default for random calls.

View Source
var RuneMap = map[Key]rune{
	KeySpace:            ' ',
	KeyExclaim:          '!',
	KeyDoubleQuote:      '"',
	KeyHash:             '#',
	KeyDollar:           '$',
	KeyPercent:          '%',
	KeyAmpersand:        '&',
	KeyQuote:            '\'',
	KeyLeftParenthesis:  '(',
	KeyRightParenthesis: ')',
	KeyAsterisk:         '*',
	KeyPlus:             '+',
	KeyComma:            ',',
	KeyMinus:            '-',
	KeyPeriod:           '.',
	KeySlash:            '/',
	Key0:                '0',
	Key1:                '1',
	Key2:                '2',
	Key3:                '3',
	Key4:                '4',
	Key5:                '5',
	Key6:                '6',
	Key7:                '7',
	Key8:                '8',
	Key9:                '9',
	KeyColon:            ':',
	KeySemiColon:        ';',
	KeyLess:             '<',
	KeyEqual:            '=',
	KeyGreater:          '>',
	KeyQuestion:         '?',
	KeyAt:               '@',
	KeyA:                'A',
	KeyB:                'B',
	KeyC:                'C',
	KeyD:                'D',
	KeyE:                'E',
	KeyF:                'F',
	KeyG:                'G',
	KeyH:                'H',
	KeyI:                'I',
	KeyJ:                'J',
	KeyK:                'K',
	KeyL:                'L',
	KeyM:                'M',
	KeyN:                'N',
	KeyO:                'O',
	KeyP:                'P',
	KeyQ:                'Q',
	KeyR:                'R',
	KeyS:                'S',
	KeyT:                'T',
	KeyU:                'U',
	KeyV:                'V',
	KeyW:                'W',
	KeyX:                'X',
	KeyY:                'Y',
	KeyZ:                'Z',
}

RuneMap provides a Key to default rune mapping.

View Source
var RuneToKeyMap = map[rune]Key{
	' ':  KeySpace,
	'!':  KeyExclaim,
	'"':  KeyDoubleQuote,
	'#':  KeyHash,
	'$':  KeyDollar,
	'%':  KeyPercent,
	'&':  KeyAmpersand,
	'\'': KeyQuote,
	'(':  KeyLeftParenthesis,
	')':  KeyRightParenthesis,
	'*':  KeyAsterisk,
	'+':  KeyPlus,
	',':  KeyComma,
	'-':  KeyMinus,
	'.':  KeyPeriod,
	'/':  KeySlash,
	'0':  Key0,
	'1':  Key1,
	'2':  Key2,
	'3':  Key3,
	'4':  Key4,
	'5':  Key5,
	'6':  Key6,
	'7':  Key7,
	'8':  Key8,
	'9':  Key9,
	':':  KeyColon,
	';':  KeySemiColon,
	'<':  KeyLess,
	'=':  KeyEqual,
	'>':  KeyGreater,
	'?':  KeyQuestion,
	'@':  KeyAt,
	'A':  KeyA,
	'B':  KeyB,
	'C':  KeyC,
	'D':  KeyD,
	'E':  KeyE,
	'F':  KeyF,
	'G':  KeyG,
	'H':  KeyH,
	'I':  KeyI,
	'J':  KeyJ,
	'K':  KeyK,
	'L':  KeyL,
	'M':  KeyM,
	'N':  KeyN,
	'O':  KeyO,
	'P':  KeyP,
	'Q':  KeyQ,
	'R':  KeyR,
	'S':  KeyS,
	'T':  KeyT,
	'U':  KeyU,
	'V':  KeyV,
	'W':  KeyW,
	'X':  KeyX,
	'Y':  KeyY,
	'Z':  KeyZ,
	'[':  KeyLeftBracket,
	'\\': KeyBackslash,
	']':  KeyRightBracket,
	'^':  KeyCaret,
	'_':  KeyUnderscore,
	'`':  KeyGraveAccent,
	'a':  KeyA,
	'b':  KeyB,
	'c':  KeyC,
	'd':  KeyD,
	'e':  KeyE,
	'f':  KeyF,
	'g':  KeyG,
	'h':  KeyH,
	'i':  KeyI,
	'j':  KeyJ,
	'k':  KeyK,
	'l':  KeyL,
	'm':  KeyM,
	'n':  KeyN,
	'o':  KeyO,
	'p':  KeyP,
	'q':  KeyQ,
	'r':  KeyR,
	's':  KeyS,
	't':  KeyT,
	'u':  KeyU,
	'v':  KeyV,
	'w':  KeyW,
	'x':  KeyX,
	'y':  KeyY,
	'z':  KeyZ,
	'{':  KeyLeftCurlyBracket,
	'|':  KeyPipe,
	'}':  KeyRightCurlyBracket,
	'~':  KeyGraveAccent,
}

RuneToKeyMap provides rune to key mapping.

Functions

func Init

func Init(backend Backend) error

Init initializes a given Backend interface. Built-in options are EbitenBackend and TCellBackend.

func InitTCell

func InitTCell() error

InitTCell initializes the TCell backend for use. Calls BackendTCell.Init().

func MaxInt

func MaxInt(a, b int) int

MaxInt returns the larger of two integers.

func MinInt

func MinInt(a, b int) int

MinInt returns the smaller of two integers.

func Quit

func Quit()

Quit tells the current Backend to Quit before calling os.Exit.

func RGBAToTCellColor

func RGBAToTCellColor(color color.RGBA) tcell.Color

RGBAToTCellColor converts a color.RGBA to a tcell.Color type.

func RandomSeed

func RandomSeed() int64

RandomSeed returns a randomized int64 seed based upon time.

func Run

func Run(cb func(*Screen)) error

Run runs the Backend with the provided logic callback.

func SetSeed

func SetSeed(seed int64)

SetSeed sets the current seed to the provided int64 seed.

func Setup

func Setup(cb func(*Screen)) error

Setup takes a callback for setting up goro before the backend creates any windows. Optional.

func StyleToTCellStyle

func StyleToTCellStyle(style Style) tcell.Style

StyleToTCellStyle converts a provided Style into a tcell.Style.

Types

type Backend

type Backend interface {
	Init() error
	Setup(func(*Screen)) error
	Run(func(*Screen)) error
	Refresh()
	Quit()
	Size() (int, int)
	SetSize(int, int)
	Units() int
	Scale() float64
	SetScale(float64)
	SetTitle(string)
	SetGlyphs(glyphs.ID, string, float64) error
	SyncSize()
}

Backend is an interface through which a Screen is displayed and controlled.

type BackendTCell

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

BackendTCell is the backend for the tcell library.

func (*BackendTCell) Init

func (backend *BackendTCell) Init() (err error)

Init initializes the base data structures and sets up the library for use.

func (*BackendTCell) Quit

func (backend *BackendTCell) Quit()

Quit causes our screen to close.

func (*BackendTCell) Refresh

func (backend *BackendTCell) Refresh()

Refresh causes the backend loop to redraw the screen.

func (*BackendTCell) Run

func (backend *BackendTCell) Run(cb func(*Screen)) (err error)

Run runs the given function cb as a goroutine and starts the entire tcell loop.

func (*BackendTCell) Scale

func (backend *BackendTCell) Scale() float64

Scale returns the current backend window scaling. Does nothing.

func (*BackendTCell) SetGlyphs

func (backend *BackendTCell) SetGlyphs(id glyphs.ID, path string, size float64) error

SetGlyphs does nothing!

func (*BackendTCell) SetScale

func (backend *BackendTCell) SetScale(scale float64)

SetScale sets the backend window's scaling. Does nothing.

func (*BackendTCell) SetSize

func (backend *BackendTCell) SetSize(w, h int)

SetSize sets the backend window to the provided width and height. Does nothing.

func (*BackendTCell) SetTitle

func (backend *BackendTCell) SetTitle(title string)

SetTitle sets the backend window's title.

func (*BackendTCell) Setup

func (backend *BackendTCell) Setup(cb func(*Screen)) (err error)

Setup runs the given function cb.

func (*BackendTCell) Size

func (backend *BackendTCell) Size() (int, int)

Size returns the current backend window dimensions.

func (*BackendTCell) SyncSize

func (backend *BackendTCell) SyncSize()

SyncSize does nothing!

func (*BackendTCell) Units

func (backend *BackendTCell) Units() int

Units returns the unit type the backend uses for Size().

type BackendVirtual

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

BackendVirtual is the virtual backend used for sub-screens.

func (*BackendVirtual) Init

func (backend *BackendVirtual) Init() error

Init sets up our appropriate data structures.

func (*BackendVirtual) Quit

func (backend *BackendVirtual) Quit()

Quit closes all screens.

func (*BackendVirtual) Refresh

func (backend *BackendVirtual) Refresh()

Refresh forces the screen to redraw.

func (*BackendVirtual) Run

func (backend *BackendVirtual) Run(cb func(*Screen)) (err error)

Run runs the given function cb as a goroutine.

func (*BackendVirtual) Scale

func (backend *BackendVirtual) Scale() float64

Scale returns the current backend window scaling.

func (*BackendVirtual) SetGlyphs

func (backend *BackendVirtual) SetGlyphs(id glyphs.ID, path string, size float64) error

SetGlyphs does nothing!

func (*BackendVirtual) SetScale

func (backend *BackendVirtual) SetScale(scale float64)

SetScale sets the backend window's scaling.

func (*BackendVirtual) SetSize

func (backend *BackendVirtual) SetSize(w, h int)

SetSize sets the backend window to the provided width and height.

func (*BackendVirtual) SetTitle

func (backend *BackendVirtual) SetTitle(title string)

SetTitle sets the backend window's title.

func (*BackendVirtual) Setup

func (backend *BackendVirtual) Setup(cb func(*Screen)) (err error)

Setup runs the given function cb.

func (*BackendVirtual) Size

func (backend *BackendVirtual) Size() (int, int)

Size returns the current backend window dimensions.

func (*BackendVirtual) SyncSize

func (backend *BackendVirtual) SyncSize()

SyncSize does nothing!

func (*BackendVirtual) Units

func (backend *BackendVirtual) Units() int

Units returns the unit type the backend uses for Size().

type Cell

type Cell struct {
	Rune          rune
	Style         Style
	Redraw        bool
	Dirty         bool
	PendingRune   rune
	PendingStyle  Style
	PendingGlyphs glyphs.ID
	Glyphs        glyphs.ID
}

Cell abstractly represents a rune, style, and other data.

type Color

type Color = color.RGBA

Color is an alias to color.RGBA.

type Event

type Event interface {
}

Event is the Event interface.

type EventKey

type EventKey struct {
	Key   Key
	Rune  rune
	State bool
	Shift bool
	Ctrl  bool
	Alt   bool
	Meta  bool
}

EventKey represents a keypress event.

func (EventKey) HasModifiers

func (e EventKey) HasModifiers() bool

HasModifiers returns if any modifier keys were held.

type EventMouse

type EventMouse struct {
	X, Y   int
	Button int
	State  bool
}

EventMouse represents a mouse press event.

type EventQuit

type EventQuit struct {
}

EventQuit represents a quit event.

type EventResize

type EventResize struct {
	Columns, Rows int
}

EventResize represents screen changes such as terminal resizing.

type Key

type Key uint8

Key is our type representing keyboard codes.

type Mod

type Mod uint8

Mod represents a modifier key state.

const (
	ModShift Mod = 1 << iota
	ModCtrl
	ModAlt
	ModMeta
	ModNone Mod = 0
)

These are our const modifier variables.

type Screen

type Screen struct {
	ScrollX, ScrollY int
	Columns, Rows    int

	UseKeys    bool
	UseMouse   bool
	AutoSize   bool
	Foreground Color
	Background Color
	Redraw     bool
	// contains filtered or unexported fields
}

Screen is a virtual Rows x Columns buffer used for drawing runes to.

func NewScreen

func NewScreen(width, height int) (screen *Screen, err error)

NewScreen creates a new screen with the virtual backend.

func (*Screen) Clear

func (screen *Screen) Clear()

Clear clears the underlying screen.

func (*Screen) Close

func (screen *Screen) Close()

Close sets the Screen as inactive thereby allowing the backend to clean it up.

func (*Screen) DrawRune

func (screen *Screen) DrawRune(x int, y int, r rune, s Style) error

DrawRune draws a given rune at the position of x and y with a given style.

func (*Screen) DrawScreen

func (screen *Screen) DrawScreen(destX, destY, destWidth, destHeight, sourceX, sourceY int, subscreen *Screen) error

DrawScreen draws the provided screen onto the current screen.

func (*Screen) DrawString

func (screen *Screen) DrawString(x int, y int, str string, s Style) error

DrawString draws a string at the position of x and y with a given style, iterating in the x direction as it goes.

func (*Screen) Flush

func (screen *Screen) Flush()

Flush forcibly causes the screen to commit any pending changes via a Draw* call and render to the backend.

func (*Screen) ForceRedraw

func (screen *Screen) ForceRedraw()

ForceRedraw marks each cell of the screen to be redrawn.

func (*Screen) Init

func (screen *Screen) Init() (err error)

Init initializes the Screen's data structures and default values.

func (*Screen) Scale

func (screen *Screen) Scale() float64

Scale returns the current screen window scaling. Does nothing.

func (*Screen) SetBackground

func (screen *Screen) SetBackground(x int, y int, c Color) error

SetBackground sets the background at the given location.

func (*Screen) SetDefaultBackground

func (screen *Screen) SetDefaultBackground(c Color)

SetDefaultBackground sets the default background color to use.

func (*Screen) SetDefaultForeground

func (screen *Screen) SetDefaultForeground(c Color)

SetDefaultForeground sets the default foreground color to use.

func (*Screen) SetForeground

func (screen *Screen) SetForeground(x int, y int, c Color) error

SetForeground sets the foreground at the given location.

func (*Screen) SetGlyphs

func (screen *Screen) SetGlyphs(id glyphs.ID, path string, size float64) error

SetGlyphs sets the screen backend's window to use the provided font. Only available for graphical backends.

func (*Screen) SetGlyphsID

func (screen *Screen) SetGlyphsID(x int, y int, id glyphs.ID) error

SetGlyphsID sets the glyphs at a given location.

func (*Screen) SetRune

func (screen *Screen) SetRune(x int, y int, r rune) error

SetRune sets the rune at the given location.

func (*Screen) SetScale

func (screen *Screen) SetScale(scale float64)

SetScale sets the screen window's scaling. Does nothing.

func (*Screen) SetSize

func (screen *Screen) SetSize(c, r int)

SetSize sets the screen's columns and rows.

func (*Screen) SetStyle

func (screen *Screen) SetStyle(x int, y int, s Style) error

SetStyle sets the style at the given location.

func (*Screen) SetTitle

func (screen *Screen) SetTitle(title string)

SetTitle sets the backend window's title to title.

func (*Screen) SetWindowSize

func (screen *Screen) SetWindowSize(w, h int)

SetWindowSize sets the current backend's window to the provided width and height in the backend's units, if available.

func (*Screen) Size

func (screen *Screen) Size() (int, int)

Size returns the current screen columns by rows.

func (*Screen) Sync

func (screen *Screen) Sync() (err error)

Sync synchronizes the screen's actual cells with the current Rows and Columns.

func (*Screen) WaitEvent

func (screen *Screen) WaitEvent() Event

WaitEvent returns an Event from the Screen's event channel.

func (*Screen) WindowSize

func (screen *Screen) WindowSize() (int, int)

WindowSize returns the current backend's window size in its preferred units, if available.

type Style

type Style struct {
	Background, Foreground               color.RGBA
	Blink, Underline, Bold, Dim, Reverse bool
}

Style represents the styling for a given Cell.

Directories

Path Synopsis
This file is a part of goRo, a library for writing roguelikes.
This file is a part of goRo, a library for writing roguelikes.

Jump to

Keyboard shortcuts

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