common

package
v0.0.0-...-fc7e386 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2024 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ICON_WIDTH  = 15
	ICON_HEIGHT = 7
)

Variables

View Source
var (
	EnableSsh = flag.Bool("ssh", false, "turns into a ssh server")
	// https://github.com/muesli/termenv/blob/51d72d34e2b9778a31aa5dd79fbdd8cdac50b4d5/profile.go#L12
	ColorProfile      = flag.Int("profile", 1, "chooses a color profile")
	EnableMultiplayer = flag.Bool("multiplayer", true, "enables multiplayer mode")
)
View Source
var (
	Twenty48 = (func() Metadata {
		logo := lipgloss.NewStyle().
			Background(lipgloss.Color("214")).
			Align(lipgloss.Center).
			Padding(3, 6).
			PaddingRight(5).
			Margin(1, 2).
			Render("2048")

		return Metadata{
			Name:     "2048",
			Features: []string{"saving"},
			Icon:     logo,
			ID:       0,
		}
	})()

	TicTacToe = (func() Metadata {
		logo := lipgloss.NewStyle().
			Background(lipgloss.Color("168")).
			Align(lipgloss.Center).
			Padding(3, 6).
			Margin(1, 2).
			Render("X/O")

		return Metadata{
			Name:     "TicTacToe",
			Features: []string{"saving", "multiplayer"},
			Icon:     logo,
			ID:       1,
		}
	})()

	Chess = (func() Metadata {
		logo := lipgloss.NewStyle().
			Background(lipgloss.Color("63")).
			Align(lipgloss.Center).
			Padding(3, 6).
			Margin(1, 2).
			Render("♚ ♖")

		return Metadata{
			Name:     "TicTacToe",
			Features: []string{"saving", "multiplayer"},
			Icon:     logo,
			ID:       2,
		}
	})()

	Snake = (func() Metadata {
		logo := lipgloss.NewStyle().
			Background(lipgloss.Color("70")).
			Align(lipgloss.Center).
			Padding(3, 6).
			Margin(1, 2).
			Render("Snake")

		return Metadata{
			Name:     "Snake",
			Features: []string{},
			Icon:     logo,
			ID:       3,
		}
	})()

	Saves = (func() Metadata {
		logo := lipgloss.NewStyle().
			Background(lipgloss.Color("244")).
			Align(lipgloss.Center).
			Padding(3, 5).
			Margin(1, 2).
			Render("Saves")

		return Metadata{
			Name: "Saves",
			Icon: logo,
			ID:   4,
		}
	})()
)
View Source
var Games = map[uint]Metadata{
	Twenty48.ID:  Twenty48,
	TicTacToe.ID: TicTacToe,
	Saves.ID:     Saves,
	Chess.ID:     Chess,
	Snake.ID:     Snake,
}

Functions

func CompareBoards

func CompareBoards[T ~[][]E, E comparable](a T, b T) (equal bool)

func CreateBoard

func CreateBoard[T any](w int, h int) [][]T

func ErrorWithBack

func ErrorWithBack(err error) tea.Msg

func NewBackBinding

func NewBackBinding() key.Binding

func NewHelpBinding

func NewHelpBinding() key.Binding

func NewResetBinding

func NewResetBinding() key.Binding

func NewSaveBinding

func NewSaveBinding() key.Binding

func RenderBoard

func RenderBoard[T any](board [][]T, renderCell func(cell T) string) string

Types

type ArrowsKeyMap

type ArrowsKeyMap struct {
	Up    key.Binding
	Down  key.Binding
	Left  key.Binding
	Right key.Binding
}

func NewArrowsKeyMap

func NewArrowsKeyMap() ArrowsKeyMap

type BackMsg

type BackMsg struct{}

type ErrorMsg

type ErrorMsg struct {
	Err        error
	Action     tea.Cmd
	ActionText string
	Fatal      bool
}

type Metadata

type Metadata struct {
	Name string
	// icons should be 15x7
	Icon string
	// loading, saving, and any other common features the game may support
	Features []string
	ID       uint
}

Jump to

Keyboard shortcuts

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