ui

package
v0.0.0-...-40c434c Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const CUT_WIDTH = 1
View Source
const GRID_SIZE = 50.0
View Source
const HELP_TEXT = `` /* 250-byte string literal not displayed */
View Source
const HOLE_RADIUS = 7.0
View Source
const LAMP_RADIUS = GRID_SIZE / 2
View Source
const MAX_ZOOM = 2.0
View Source
const MIN_ZOOM = 0.5
View Source
const SWITCH_HEIGHT = GRID_SIZE
View Source
const SWITCH_WIDTH = GRID_SIZE
View Source
const WIRE_WIDTH = 3.0

Variables

View Source
var ADD_WIRE_KEY = pixelgl.Key1
View Source
var ChipClasses = map[string]ChipClass{
	"NOT": ChipClass{
		InputsCount:  1,
		OutputsCount: 1,
		Delay:        time.Second / 4,
		Logic: func(inputs []bool) []bool {
			return []bool{!inputs[0]}
		},
	},
	"AND": ChipClass{
		InputsCount:  2,
		OutputsCount: 1,
		Delay:        time.Second / 2,
		Logic: func(inputs []bool) []bool {
			return []bool{inputs[0] && inputs[1]}
		},
	},
	"OR": ChipClass{
		InputsCount:  2,
		OutputsCount: 1,
		Delay:        time.Second / 2,
		Logic: func(inputs []bool) []bool {
			return []bool{inputs[0] || inputs[1]}
		},
	},
}

Functions

func DrawLabels

func DrawLabels(win *pixelgl.Window)

Types

type Camera

type Camera struct {
	Pos       pixel.Vec
	Speed     float64
	Zoom      float64
	ZoomSpeed float64
}

func (Camera) Matrix

func (c Camera) Matrix(win *pixelgl.Window) pixel.Matrix

func (*Camera) Update

func (c *Camera) Update(win *pixelgl.Window, dt float64)

type ChipClass

type ChipClass struct {
	InputsCount  int
	OutputsCount int
	Delay        time.Duration
	Logic        func([]bool) []bool
}

func (ChipClass) Height

func (cc ChipClass) Height() int

type ChipInstance

type ChipInstance struct {
	Class    string
	Location GridPoint
}

func NewChipInstance

func NewChipInstance(class string, pos GridPoint) ChipInstance

func (ChipInstance) Draw

func (ci ChipInstance) Draw(imd *imdraw.IMDraw, win *pixelgl.Window)

func (ChipInstance) HasInputAt

func (ci ChipInstance) HasInputAt(pos GridPoint) bool

func (*ChipInstance) Process

func (ci *ChipInstance) Process(cb *CircuitBoard)

type ChipTool

type ChipTool struct {
	Class string
}

func (ChipTool) Draw

func (ct ChipTool) Draw(win *pixelgl.Window, mp pixel.Vec)

func (ChipTool) Update

func (ct ChipTool) Update(win *pixelgl.Window, cb *CircuitBoard, mp pixel.Vec)

type CircuitBoard

type CircuitBoard struct {
	Filename string

	WireGroups map[GridPoint]*WireGroup

	Switches map[GridPoint]bool
	Lamps    map[GridPoint]bool
	Chips    []ChipInstance
	// contains filtered or unexported fields
}

func NewCircuitBoard

func NewCircuitBoard() *CircuitBoard

func (*CircuitBoard) AddChip

func (cb *CircuitBoard) AddChip(chip string, x, y int)

func (*CircuitBoard) AddLamp

func (cb *CircuitBoard) AddLamp(x, y int)

func (*CircuitBoard) AddSwitch

func (cb *CircuitBoard) AddSwitch(x, y int)

func (*CircuitBoard) AddWire

func (cb *CircuitBoard) AddWire(x1, y1, x2, y2 int)

func (*CircuitBoard) CutThrough

func (cb *CircuitBoard) CutThrough(a, b pixel.Vec)

func (*CircuitBoard) Draw

func (cb *CircuitBoard) Draw(win *pixelgl.Window)

func (*CircuitBoard) GetSignal

func (cb *CircuitBoard) GetSignal(p GridPoint) bool

func (*CircuitBoard) Load

func (cb *CircuitBoard) Load()

func (*CircuitBoard) MarshalJSON

func (cb *CircuitBoard) MarshalJSON() ([]byte, error)

func (*CircuitBoard) PressSwitch

func (cb *CircuitBoard) PressSwitch(x, y int)

func (*CircuitBoard) Save

func (cb *CircuitBoard) Save()

func (*CircuitBoard) SetSignal

func (cb *CircuitBoard) SetSignal(p GridPoint, signal bool)

func (*CircuitBoard) SplitWire

func (cb *CircuitBoard) SplitWire(pos GridPoint)

type Finger

type Finger struct {
}

func (Finger) Draw

func (f Finger) Draw(win *pixelgl.Window, mp pixel.Vec)

func (*Finger) Update

func (f *Finger) Update(win *pixelgl.Window, cb *CircuitBoard, mp pixel.Vec)

type GridPoint

type GridPoint struct {
	X int
	Y int
}

func (GridPoint) Pos

func (gp GridPoint) Pos() pixel.Vec

func (GridPoint) ToRight

func (gp GridPoint) ToRight() GridPoint

type Help

type Help struct {
	Hidden bool
	// contains filtered or unexported fields
}

func NewHelp

func NewHelp() (*Help, error)

func (Help) Draw

func (h Help) Draw(win *pixelgl.Window)

func (*Help) Update

func (h *Help) Update(win *pixelgl.Window)

type LampTool

type LampTool struct {
}

func (*LampTool) Draw

func (st *LampTool) Draw(win *pixelgl.Window, mp pixel.Vec)

func (*LampTool) Update

func (st *LampTool) Update(win *pixelgl.Window, cb *CircuitBoard, mp pixel.Vec)

type Scissors

type Scissors struct {
	CutStart *pixel.Vec
}

func (Scissors) Draw

func (s Scissors) Draw(win *pixelgl.Window, mp pixel.Vec)

func (*Scissors) Update

func (s *Scissors) Update(win *pixelgl.Window, cb *CircuitBoard, mp pixel.Vec)

type SwitchTool

type SwitchTool struct {
}

func (*SwitchTool) Draw

func (st *SwitchTool) Draw(win *pixelgl.Window, mp pixel.Vec)

func (*SwitchTool) Update

func (st *SwitchTool) Update(win *pixelgl.Window, cb *CircuitBoard, mp pixel.Vec)

type Tool

type Tool interface {
	Update(win *pixelgl.Window, board *CircuitBoard, mousePosition pixel.Vec)
	Draw(win *pixelgl.Window, mousePosition pixel.Vec)
}

type UI

type UI struct {
	WindowConfig pixelgl.WindowConfig
	Window       *pixelgl.Window
	Help         *Help
	Workspace    *Workspace
}

func NewUI

func NewUI() (*UI, error)

func (UI) MainLoop

func (u UI) MainLoop()

type Wire

type Wire struct {
	A, B GridPoint
}

func (Wire) AsLine

func (w Wire) AsLine() pixel.Line

type WireGroup

type WireGroup struct {
	Signal bool
	Wires  []Wire
}

func (WireGroup) ConnnectedPoints

func (wg WireGroup) ConnnectedPoints() (res []GridPoint)

func (WireGroup) Draw

func (wg WireGroup) Draw(imd *imdraw.IMDraw)

func (*WireGroup) SetSignal

func (wg *WireGroup) SetSignal(s bool, cb *CircuitBoard)

type WireTool

type WireTool struct {
	WireEnd *pixel.Vec
}

func (*WireTool) Draw

func (wt *WireTool) Draw(win *pixelgl.Window, mp pixel.Vec)

func (*WireTool) Update

func (wt *WireTool) Update(win *pixelgl.Window, cb *CircuitBoard, mp pixel.Vec)

type Workspace

type Workspace struct {
	Camera Camera

	// For drawing background
	HoleSprite *pixel.Sprite
	HoleBatch  *pixel.Batch

	// For wires & elements they connect
	CircuitBoard *CircuitBoard

	// Tools
	UsedTool Tool
}

func NewWorkspace

func NewWorkspace() (*Workspace, error)

func (*Workspace) Draw

func (w *Workspace) Draw(win *pixelgl.Window)

func (*Workspace) Update

func (w *Workspace) Update(win *pixelgl.Window, dt float64)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳