app

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

animations - Animations timers

Index

Constants

View Source
const (
	// Top bar height in px
	TopbarHeight = 50.0
	// Side bar width in px
	SidebarWidth = 300.0
	// Details bar width in px
	DetailsBarWidth = 300.0
	// Status bar height in px
	StatusBarHeight = 30.0
)
View Source
const (
	Any optBool = iota
	No          // false
	Yes         // true
)
View Source
const (
	SceneOpAdd    sceneOpType = "add"
	SceneOpDelete sceneOpType = "delete"
	SceneOpModify sceneOpType = "modify"
)
View Source
const (
	DefaultTargetFPS = 30
)
View Source
const MAX_INOUT = 4

Variables

This section is empty.

Functions

func CheckCollisionRecLine

func CheckCollisionRecLine(rec rl.Rectangle, p1, p2 rl.Vector2) bool

func Close

func Close()

Close cleanup resources used by the application before exiting.

func CopyIdxs

func CopyIdxs[T any](dst, src []T, idxs []int) []T

CopyIdxs clears dst and copies the elements at idxs from src into dst

It reallocates of cap(dst) < len(idxs)

func GetKeyName

func GetKeyName(key int32) string

func Init

func Init(assets embed.FS, opts *AppOptions) error

Init initializes the application.

It loads assets, initializes the window, and sets up the default state.

It must only be called once at startup.

func LoadAssets

func LoadAssets(assets embed.FS) error

func LoadFonts

func LoadFonts(assets embed.FS) error

func LoadIcon

func LoadIcon(assets embed.FS) (*rl.Image, error)

LoadIcon loads the application icon

func NormalizePath

func NormalizePath(p string) string

NormalizePath normalizes a path to use the OS path separator.

It preserves the trailing separator if any.

func ParseFloat32

func ParseFloat32(s string) (float32, error)

ParseFloat32 parses a string to a float32 value.

See: strconv.ParseFloat

func Range

func Range(i, j int) []int

Range returns a slice of integers [i; j[

func RemoveQuotes

func RemoveQuotes(s string) string

Replaces single and double quotes with asterisks.

func Repeat

func Repeat[T any](dst []T, v T, n int) []T

Repeat clears dst and fills it with n copies of the given value

It reallocates of cap(dst) < n

func ShouldExit

func ShouldExit() bool

ShouldQuit returns true if the application should exit.

func SortedIntsIndex

func SortedIntsIndex(a []int, x int) int

SortedIntsIndex returns the index of x in a ascending sorted int slice (-1 if not found)

Binary search is used.

func Step

func Step()

Step updates and draw a frame.

func SwapDelete

func SwapDelete[T any](s []T, i int) []T

SwapDelete efficiently deletes the element at index i by swapping it with the last element and then truncating the slice.

Calling SwapDelete with i == len(s) - 1 simply removes the last element.

The complexity is O(1) but the slice order is not preserved.

func SwapDeleteMany

func SwapDeleteMany[T any](s []T, idxs []int) []T

SwapDeleteMany efficiently deletes the elements at given indices idxs by swapping them with the last elements and then truncating the slice.

idxs must be sorted in ascending order.

The complexity is O(len(indices)) but the slice order is not preserved.

func SwapInsert

func SwapInsert[T any](s []T, i int, v T) []T

SwapInsert efficiently inserts the given element at index i by pushing the current i-th element to the back.

Calling SwapInsert with i == len(s) simply appends the element.

This is the reverse of SwapDelete.

The complexity is O(1) but the slice order is not preserved.

func SwapInsertMany

func SwapInsertMany[T any](s []T, idxs []int, vs []T) []T

SwapInsertMany efficiently inserts the given elements at given indices idxs by pushing the current$ elements at idxs to the back.

Idxs values must all be between 0 and len(s)+len(idxs)-1.

This is the reverse of SwapDeleteMany.

The complexity is O(len(indices)) but the slice order is not preserved.

Types

type Action

type Action interface {
	// Returns which app mode the action is for
	Target() ActionTarget
}

Action is an abstraction layer between inputs and state updates in [Update] step.

It allows to decouple inputs and state updates, cleanly defining atomic state updates and each function / method perimeter.

See: - ActionHandler - GetActionFunc - [getAction] - [DispatchAction]

type ActionHandler

type ActionHandler func(Action) Action

ActionHandler are responsible for performing and an Action, and may return a follow up Action.

Each AppMode has a corresponding struct implementing a Do ActionHandler method.

In most cases, the ActionHandler only calls appropriate handler for the specific action they recieve. Those handler,in turn, often do not return an Action directly, but rather calls other handler directly and returns their result.

This prevents runtime reflection (switch action.(type) statements) at the expense of a deeper call stack.

type ActionTarget

type ActionTarget int

ActionTarget - action target

const (
	// TargetApp - app level actions
	TargetApp ActionTarget = iota
	// TargetGui - gui level actions
	TargetGui
	// TargetCamera - camera level actions
	TargetCamera
	// TargetSelector - selector level actions
	TargetSelector
	// TargetNewPath - new path level actions
	TargetNewPath
	// TargetNewBuilding - new building level actions
	TargetNewBuilding
	// TargetNewTextBox - new text box level actions
	TargetNewTextBox
	// TargetSelection - selection level actions
	TargetSelection
)

type Animations

type Animations struct {
	// Elapsed time since window initialization (seconds)
	Timer float32
	// Brightness factor for DrawSelected
	SelectedLerp float32
	// Belt arrows offset
	BeltOffset float32
}

func (*Animations) Update

func (a *Animations) Update()

Update animations state

Do not depends on any other state

type App

type App struct {
	// Application view mode
	Mode AppMode
	// contains filtered or unexported fields
}

App contains application global state

type AppActionNew

type AppActionNew struct{}

AppActionNew - create a new project

type AppActionOpen

type AppActionOpen struct{}

AppActionOpen - open and load a project from a file

func (AppActionOpen) Target

func (a AppActionOpen) Target() ActionTarget

type AppActionSave

type AppActionSave struct{ Filepath string }

AppActionSave - save the current project to a file

func (AppActionSave) Target

func (a AppActionSave) Target() ActionTarget

type AppActionSaveAs

type AppActionSaveAs struct{}

AppActionSaveAs - save the current project to a new file

func (AppActionSaveAs) Target

func (a AppActionSaveAs) Target() ActionTarget

type AppActionSwitchMode

type AppActionSwitchMode struct {
	Mode   AppMode
	Resets Resets
}

AppActionSwitchMode - switch app mode

This action terminates the action chain in the current frame.

func (AppActionSwitchMode) Target

func (a AppActionSwitchMode) Target() ActionTarget

type AppMode

type AppMode int
const (
	// ModeNormal is the default mode
	ModeNormal AppMode = iota
	// ModeNewPath is used when creating a new path
	ModeNewPath
	// ModeNewBuilding is used when creating a new building
	ModeNewBuilding
	// ModeNewTextBox is used when creating a new text box
	ModeNewTextBox
	// ModeSelection is used when one or many object are selected
	ModeSelection
)

func (AppMode) Assert

func (m AppMode) Assert(mode AppMode)

Assert panics if AppMode is not the expected one

func (AppMode) String

func (mode AppMode) String() string

type AppOptions

type AppOptions struct {
	// A file to load
	File string
	// Target / Max FPS
	Fps int
}

type Building

type Building struct {
	DefIdx int
	Pos    rl.Vector2
	Rot    int32
}

func (Building) Bounds

func (b Building) Bounds() rl.Rectangle

func (Building) Def

func (b Building) Def() BuildingDef

func (Building) Draw

func (b Building) Draw(state DrawState)

func (Building) DrawLabel

func (b Building) DrawLabel(bounds rl.Rectangle)

func (Building) String

func (b Building) String() string

type BuildingDef

type BuildingDef struct {
	Class    string
	Category string
	Dims     rl.Vector2
	BeltIn   inputOutputs
	BeltOut  inputOutputs
	PipeIn   inputOutputs
	PipeOut  inputOutputs
}

func (BuildingDef) String

func (b BuildingDef) String() string

type BuildingDefs

type BuildingDefs []BuildingDef

func (BuildingDefs) Categories

func (defs BuildingDefs) Categories() []string

func (BuildingDefs) Classes

func (defs BuildingDefs) Classes() []string

func (BuildingDefs) Index

func (defs BuildingDefs) Index(class string) int

type Camera

type Camera struct {

	// true if camera is currently zooming (middle mouse button down)
	Zooming bool
	// zoom at position
	ZoomAt rl.Vector2
	// contains filtered or unexported fields
}

Holds camera state

func (*Camera) BeginMode2D

func (c *Camera) BeginMode2D()

BeginMode2D enters raylib 2D mode

func (*Camera) Dispatch

func (c *Camera) Dispatch(action Action) Action

Dispatch performs a Camera action, updating its state, and returns an new action to be performed

Note: All camera actions returns nil (no follow up)

See: ActionHandler

func (*Camera) EndMode2D

func (c *Camera) EndMode2D()

EndMode2D exits raylib 2D mode

func (*Camera) ScreenPos

func (c *Camera) ScreenPos(worldPos rl.Vector2) rl.Vector2

ScreenPos converts world position to screen position

func (*Camera) Update

func (c *Camera) Update()

Update processes inputs, and directly execute the TargetCamera action to be performed.

TargetCamera actions does not have follow up actions.

func (*Camera) WorldPos

func (c *Camera) WorldPos(screenPos rl.Vector2) rl.Vector2

WorldPos converts screen position to world position

func (*Camera) Zoom

func (c *Camera) Zoom() float32

Zoom returns the current zoom level

type CameraActionPan

type CameraActionPan struct{ By rl.Vector2 }

CameraActionPan - pan the camera by the given vector

func (CameraActionPan) Target

func (a CameraActionPan) Target() ActionTarget

type CameraActionReset

type CameraActionReset struct{}

CameraActionReset - reset the camera to its default position and zoom

func (CameraActionReset) Target

func (a CameraActionReset) Target() ActionTarget

type CameraActionZoom

type CameraActionZoom struct {
	By float32
	At rl.Vector2
}

CameraActionZoom - zoom the camera

func (CameraActionZoom) Target

func (a CameraActionZoom) Target() ActionTarget

type DecodeTextError

type DecodeTextError struct {
	Msg     string
	Err     error
	Line    int
	Version int
}

func (DecodeTextError) Error

func (e DecodeTextError) Error() string

type Dims

type Dims struct {

	// Screen size
	Screen rl.Vector2
	// Scene area dimensions
	Scene rl.Rectangle
	// Scene area dimensions (world coordinates)
	World rl.Rectangle
	// Scene area dimensions (world coordinates) expanded by 1 world unit on each side
	ExWorld rl.Rectangle
	// contains filtered or unexported fields
}

func (*Dims) Update

func (d *Dims) Update()

Update screen and scene dimensions state

Depends on Camera

type DrawCounts

type DrawCounts struct {
	Buildings int
	Paths     int
}

type DrawState

type DrawState uint8

DrawState enumerates object drawing states

const (
	DrawNormal   DrawState = 0
	DrawNew      DrawState = 1
	DrawSelected DrawState = 2
	DrawInvalid  DrawState = 3
	DrawShadow   DrawState = 4
	DrawSkip     DrawState = 5

	DrawHovered DrawState = 1 << 6
	DrawClicked DrawState = 2 << 6
)

type GetActionFunc

type GetActionFunc func() Action

GetActionFunc are responsible for converting inputs (mouse and keyboard) into an Action.

Each AppMode has a corresponding struct implementing a GetActionFunc method. They do not modify the state directly.

In most cases, the GetActionFunc methods do not returns an Action directly, but rather calls appropriate ActionHandler directly and returns their result.

This prevents runtime reflection (switch action.(type) statements) at the expense of a deeper call stack.

type Grid

type Grid struct {
	// SnapStep is the snap step in world units, 0 to disable
	SnapStep float32
}

func (Grid) Draw

func (g Grid) Draw()

Draw grid

func (Grid) Snap

func (g Grid) Snap(v rl.Vector2) rl.Vector2

Snap returns the vector snapped to the grid

type Gui

type Gui struct {
	Topbar     guiTopbar
	Sidebar    guiSidebar
	Detailsbar guiDetailsbar
	Statusbar  guiStatusbar
}

Gui is a container struct for all the GUI elements

func (*Gui) CapturesKeyPress

func (g *Gui) CapturesKeyPress() bool

Whether the gui should captures key presses

func (*Gui) Dispatch

func (g *Gui) Dispatch(action Action) Action

Dispatch performs an Gui action, updating its state, and returns an new action to be performed

See: ActionHandler

func (*Gui) Init

func (gui *Gui) Init()

Precompute and store some static data

func (*Gui) Reset

func (g *Gui) Reset()

Reset resets GUI state

func (*Gui) UpdateAndDraw

func (g *Gui) UpdateAndDraw() (action Action)

UpdateAndDraw combines drawing the GUI, handling GUI inputs and returns an Action to be performed.

Note: Raygui being an immediate mode GUI, we cannot seperate the update and draw steps.

type KeyBinding

type KeyBinding int

KeyBinding represents a keyboard key binding

const (
	BindingNull KeyBinding = iota
	BindingEscape
	BindingSave
	BindingSaveAs
	BindingUndo
	BindingRedo
	BindingDelete
	BindingDuplicate
	BindingRotate
	BindingDrag
	BindingUp
	BindingDown
	BindingLeft
	BindingRight
	BindingZoomIn
	BindingZoomOut
	BindingZoomReset
)

type Keyboard

type Keyboard struct {
	// Pressed key (handles repeated key presses)
	//
	// It is not 0 (KeyNull) on the first frame the key is down and if a key is maintained down
	// and no other key is pressed, it will periodically repeat that key.
	Pressed int32

	// True if left or right shift key is down
	Shift bool

	// True if left or right control key is down
	Ctrl bool

	// True if alt key is down
	Alt bool
	// contains filtered or unexported fields
}

func (Keyboard) Binding

func (kb Keyboard) Binding() KeyBinding

Binding returns the key binding that matches the pressed key and modifiers

If gui is capturing key presses, always returns BindingNull

func (*Keyboard) Update

func (kb *Keyboard) Update()

Update keyboard state

Do not depends on any other state

type MaskIterator

type MaskIterator struct {
	// index for which to return true
	TrueIdxs []int
	// current index counter
	Idx int
	// contains filtered or unexported fields
}

Iterate over a would-be mask from the true values indices.

func NewMaskIterator

func NewMaskIterator(trueIdx []int) MaskIterator

NewMaskIterator returns a new MaskIterator from the given true values indices.

trueIdxs must be sorted in ascending order.

func (*MaskIterator) Next

func (it *MaskIterator) Next() bool

Next returns the next value from the mask.

It always returns false when all the true values have been iterated over, but keep incrementing [MaskIterator.Idx] counter.

type Mouse

type Mouse struct {
	// Mouse position (in world coordinates)
	Pos rl.Vector2

	// Mouse position (in screen coordinates)
	ScreenPos rl.Vector2

	// Snapped mouse position (in world coordinates)
	SnappedPos rl.Vector2

	// Mouse movement delta since last frame (in screen coordinates)
	ScreenDelta rl.Vector2

	// True when mouse is inside the scene area
	InScene bool

	// Wheel movement
	Wheel float32

	// Left mouse button
	Left mouseButton

	// Middle mouse button
	Middle mouseButton

	// Right mouse button
	Right mouseButton
}

func (*Mouse) Update

func (m *Mouse) Update()

Update mouse state

Depends on Dims and Camera

type NewBuilding

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

NewBuilding represents a new building creation state (corresponding to ModeNewBuilding)

func (*NewBuilding) Dispatch

func (np *NewBuilding) Dispatch(action Action) Action

Dispatch performs an NewBuilding action, updating its state, and returns an new action to be performed

See: ActionHandler

func (NewBuilding) Draw

func (np NewBuilding) Draw()

func (*NewBuilding) GetAction

func (nb *NewBuilding) GetAction() (action Action)

GetAction processes inputs in ModeNewBuilding, and returns an action to be performed.

See: GetActionFunc

func (*NewBuilding) Reset

func (nb *NewBuilding) Reset()

Reset resets the NewBuilding state

type NewBuildingActionInit

type NewBuildingActionInit struct{ DefIdx int }

NewBuildingActionInit - initialize placing a new path

func (NewBuildingActionInit) Target

type NewBuildingActionMoveTo

type NewBuildingActionMoveTo struct{ Pos rl.Vector2 }

NewBuildingActionMoveTo - update the new building position

func (NewBuildingActionMoveTo) Target

type NewBuildingActionPlace

type NewBuildingActionPlace struct{}

NewBuildingActionPlace - place a new building

func (NewBuildingActionPlace) Target

type NewBuildingActionRotate

type NewBuildingActionRotate struct{}

NewBuildingActionRotate - rotate the new building direction

func (NewBuildingActionRotate) Target

type NewPath

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

NewPath represents a new path creation state (corresponding to ModeNewPath)

func (*NewPath) Dispatch

func (np *NewPath) Dispatch(action Action) Action

Dispatch performs an NewPath action, updating its state, and returns an new action to be performed

See: ActionHandler

func (NewPath) Draw

func (np NewPath) Draw()

func (*NewPath) GetAction

func (np *NewPath) GetAction() Action

GetAction processes inputs in ModeNewPath, and returns an action to be performed

See: GetActionFunc

func (*NewPath) Reset

func (np *NewPath) Reset()

Reset resets the NewPath state

type NewPathActionInit

type NewPathActionInit struct{ DefIdx int }

NewPathActionInit - initialize placing a new path

func (NewPathActionInit) Target

func (a NewPathActionInit) Target() ActionTarget

type NewPathActionMoveTo

type NewPathActionMoveTo struct{ Pos rl.Vector2 }

NewPathActionMoveTo - update the new path position (either start or end, depending on internal state)

func (NewPathActionMoveTo) Target

func (a NewPathActionMoveTo) Target() ActionTarget

type NewPathActionPlace

type NewPathActionPlace struct{}

NewPathActionPlace - add a new path to the scene

func (NewPathActionPlace) Target

func (a NewPathActionPlace) Target() ActionTarget

type NewPathActionPlaceStart

type NewPathActionPlaceStart struct{}

NewPathActionPlaceStart - place a new path start

func (NewPathActionPlaceStart) Target

type NewPathActionReverse

type NewPathActionReverse struct{}

NewPathActionReverse - reverse the new path direction

func (NewPathActionReverse) Target

type NewTextBox

type NewTextBox struct {
	TextBox TextBox
	// contains filtered or unexported fields
}

func (*NewTextBox) Dispatch

func (np *NewTextBox) Dispatch(action Action) Action

Dispatch performs an NewTextBox action, updating its state, and returns an new action to be performed

See: ActionHandler

func (NewTextBox) Draw

func (np NewTextBox) Draw()

func (*NewTextBox) GetAction

func (ntb *NewTextBox) GetAction() (action Action)

GetAction processes inputs in ModeNewTextBox, and returns an action to be performed.

See: GetActionFunc

func (*NewTextBox) Reset

func (ntb *NewTextBox) Reset()

Reset resets the NewTextBox state

type NewTextBoxActionInit

type NewTextBoxActionInit struct{ DefIdx int }

NewTextBoxActionInit - initialize placing a new text box

func (NewTextBoxActionInit) Target

type NewTextBoxActionMoveTo

type NewTextBoxActionMoveTo struct{ Pos rl.Vector2 }

NewTextBoxActionMoveTo - update the new text box position (either start or end, depending on internal state)

func (NewTextBoxActionMoveTo) Target

type NewTextBoxActionPlace

type NewTextBoxActionPlace struct{}

NewTextBoxActionPlace - add a new text box to the scene

func (NewTextBoxActionPlace) Target

type NewTextBoxActionPlaceStart

type NewTextBoxActionPlaceStart struct{}

NewTextBoxActionPlaceStart - place a new text box start

func (NewTextBoxActionPlaceStart) Target

type NewTextBoxActionReverse

type NewTextBoxActionReverse struct{}

NewTextBoxActionReverse - reverse the new text box direction

func (NewTextBoxActionReverse) Target

type Object

type Object struct {
	// Type of the object
	Type ObjectType
	// Index in either [Scene.Buildings], [Scene.Paths] or [Scene.TextBoxes]
	Idx int
}

Object represents a building, a whole path, a path start or a path end in the scene

func (Object) Draw

func (o Object) Draw(state DrawState)

Draw draws the object in the given state

Noop if [Object.Type] is TypeInvalid

func (Object) IsEmpty

func (o Object) IsEmpty() bool

IsEmpty returns true if Object is TypeInvalid

type ObjectCollection

type ObjectCollection struct {
	Buildings []Building
	Paths     []Path
	TextBoxes []TextBox
}

ObjectCollection represents a collection of objects (buildings, & paths)

func (ObjectCollection) IsEmpty

func (oc ObjectCollection) IsEmpty() bool

IsEmpty returns true if the collection is empty

func (ObjectCollection) SelectFromRect

func (oc ObjectCollection) SelectFromRect(sel *ObjectSelection, rect rl.Rectangle)

SelectFromRect fills sel with the objects in the given rectangle and recomputes its bounding box

sel must be empty, it is passed to avoid reallocating it

type ObjectSelection

type ObjectSelection struct {
	// BuildingIdxs is the slice of selected buildings indices of a [ObjectCollection.Buildings]
	//
	// It must be sorted in ascending order.
	BuildingIdxs []int
	// PathIdxs is the slice of selected paths indices of a [ObjectCollection.Paths] and whether
	// the path start and/or end is selected
	//
	// It must be sorted in ascending order.
	PathIdxs []PathSel
	// TextBoxIdxs is the slice of selected text boxes indices of a [ObjectCollection.TextBoxes]
	//
	// It must be sorted in ascending order.
	TextBoxIdxs []int
	// Bounds is the bounding box of the selection
	Bounds rl.Rectangle
}

ObjectSelection represents a selection of objects in a ObjectCollection

func (ObjectSelection) AnyPathIdxs

func (os ObjectSelection) AnyPathIdxs() []int

AnyPathIdxs returns the indices of the path with either start or end selected

func (ObjectSelection) BuildingsIterator

func (os ObjectSelection) BuildingsIterator() MaskIterator

BuildingsIterator returns a mask iterator of the selected buildings

func (ObjectSelection) Contains

func (os ObjectSelection) Contains(obj Object) bool

Contains returns true if the given object is in the selection (false for TypeInvalid)

func (ObjectSelection) EndIdxs

func (os ObjectSelection) EndIdxs() []int

EndIdxs returns the indices of the path with end selected

func (ObjectSelection) FullPathIdxs

func (os ObjectSelection) FullPathIdxs() []int

FullPathIdxs returns the indices of the path with both start and end selected

func (ObjectSelection) IsEmpty

func (os ObjectSelection) IsEmpty() bool

IsEmpty returns true if the selection is empty

func (ObjectSelection) PathsIterator

func (os ObjectSelection) PathsIterator() PathSelMaskIterator

PathsIterator returns a mask iterator of the selected paths

func (ObjectSelection) StartIdxs

func (os ObjectSelection) StartIdxs() []int

StartIdxs returns the indices of the path with start selected

func (ObjectSelection) TextBoxesIterator

func (os ObjectSelection) TextBoxesIterator() MaskIterator

TextBoxesIterator returns a mask iterator of the selected text boxes

type ObjectType

type ObjectType int

ObjectType enumerates the different types of objects

const (
	TypeInvalid ObjectType = iota
	TypeBuilding
	TypePath
	TypePathStart
	TypePathEnd
	TypeTextBox
)

func (ObjectType) String

func (ot ObjectType) String() string

type Path

type Path struct {
	DefIdx     int
	Start, End rl.Vector2
}

func (Path) CheckCollisionPoint

func (p Path) CheckCollisionPoint(pos rl.Vector2) bool

Returns true if the given position is inside the path body.

func (Path) CheckEndCollisionPoint

func (p Path) CheckEndCollisionPoint(pos rl.Vector2) bool

Returns true if the given position is inside the path end.

func (Path) CheckStartCollisionPoint

func (p Path) CheckStartCollisionPoint(pos rl.Vector2) bool

Returns true if the given position is inside the path start.

func (Path) Def

func (p Path) Def() PathDef

func (Path) Draw

func (p Path) Draw(state DrawState)

func (Path) DrawBody

func (p Path) DrawBody(state DrawState)

func (Path) DrawEnd

func (p Path) DrawEnd(state DrawState)

func (Path) DrawStart

func (p Path) DrawStart(state DrawState)

func (Path) IsValid

func (p Path) IsValid() bool

func (Path) String

func (p Path) String() string

type PathDef

type PathDef struct {
	Class         string
	Width         float32
	Color         rl.Color
	IsDirectional bool
}

func (PathDef) String

func (def PathDef) String() string

func (*PathDef) UnmarshalJSON

func (def *PathDef) UnmarshalJSON(data []byte) error

type PathDefs

type PathDefs []PathDef

func (PathDefs) Classes

func (defs PathDefs) Classes() []string

func (PathDefs) Index

func (defs PathDefs) Index(class string) int

type PathSel

type PathSel struct {
	// Idx is the index of the path in [ObjectCollection.Paths]
	Idx int
	// Start is true if the path start is selected
	Start bool
	// End is true if the path end is selected
	End bool
}

PathSel represents a selected path in a ObjectSelection

One of [Start] or [End] must be true.

func (PathSel) String

func (p PathSel) String() string

type PathSelMaskIterator

type PathSelMaskIterator struct {
	// index for which to return true
	TrueIdxs []PathSel
	// current index counter
	Idx int
	// contains filtered or unexported fields
}

Iterate over a would-be mask from the true values.

func NewPathSelMaskIterator

func NewPathSelMaskIterator(trueIdx []PathSel) PathSelMaskIterator

NewPathSelMaskIterator returns a new PathSelMaskIterator from the given true values.

trueIdxs must be sorted in ascending order.

func (*PathSelMaskIterator) Next

func (it *PathSelMaskIterator) Next() (bool, bool)

Next returns the next pair of (start, end) from the mask.

It always returns (false, flase) when all the true values have been iterated over [PathSelMaskIterator.Idx] counter.

type Resets

type Resets struct {
	Selector    bool
	NewPath     bool
	NewBuilding bool
	NewTextBox  bool
	Selection   bool
	Gui         bool
	Camera      bool
}

TODO: Make it a flag set

func ResetAll

func ResetAll() Resets

ResetAll resets all states but the camera.

func (Resets) String

func (r Resets) String() string

func (Resets) WithCamera

func (r Resets) WithCamera(v bool) Resets

func (Resets) WithGui

func (r Resets) WithGui(v bool) Resets

func (Resets) WithNewBuilding

func (r Resets) WithNewBuilding(v bool) Resets

func (Resets) WithNewPath

func (r Resets) WithNewPath(v bool) Resets

func (Resets) WithNewTextBox

func (r Resets) WithNewTextBox(v bool) Resets

func (Resets) WithSelection

func (r Resets) WithSelection(v bool) Resets

func (Resets) WithSelector

func (r Resets) WithSelector(v bool) Resets

type Scene

type Scene struct {
	ObjectCollection

	// The scene object currently hovered by the mouse
	Hovered Object
	// contains filtered or unexported fields
}

Scene holds the scene objects (buildings and paths)

func (*Scene) AddBuilding

func (s *Scene) AddBuilding(building Building)

AddBuilding adds the given building to the scene.

No validity check is performed.

func (*Scene) AddObjects

func (s *Scene) AddObjects(col ObjectCollection)

AddObjects adds the given paths and buildings to the scene.

No validity checks is performed.

func (*Scene) AddPath

func (s *Scene) AddPath(path Path)

AddPath adds the given path to the scene.

No validity check is performed.

func (*Scene) AddTextBox

func (s *Scene) AddTextBox(tb TextBox)

AddTextBox adds the given text box to the scene.

func (*Scene) DeleteObjects

func (s *Scene) DeleteObjects(sel ObjectSelection)

DeleteObjects deletes the given paths and buildings from the scene.

func (Scene) Draw

func (s Scene) Draw()

Draw scene objects

func (Scene) GetObjectAt

func (s Scene) GetObjectAt(pos rl.Vector2) Object

GetObjectAt returns the object at the given position (world coordinates)

If multiple objects are at the position returns first one on this list:

  • selected path with highest index: start / end over body
  • selected building with highest index
  • selected text box with highest index
  • normal path with highest index: start / end over body
  • normal building with highest index
  • normal text box with highest index

This is (mostly) the reverse of Scene.Draw order to make viewing/selecting masked objects easier.

If no object is found, returns an zero-valued Object

func (*Scene) HasRedo

func (s *Scene) HasRedo() bool

HasRedo returns true if there are more redo operations to perform

func (*Scene) HasUndo

func (s *Scene) HasUndo() bool

HasUndo returns true if there are more undo operations to perform

func (Scene) IsBuildingValid

func (s Scene) IsBuildingValid(building Building, ignore int) bool

func (*Scene) IsModified

func (s *Scene) IsModified() bool

IsModified returns true if the scene has been modified since last save

func (Scene) IsPathValid

func (s Scene) IsPathValid(path Path) bool

func (*Scene) LoadFromText

func (s *Scene) LoadFromText(r io.Reader) error

func (*Scene) ModifyObjects

func (s *Scene) ModifyObjects(sel ObjectSelection, new ObjectCollection)

ModifyObjects updates the given paths and buildings in the scene.

No validity checks is performed.

func (*Scene) Redo

func (s *Scene) Redo() (bool, Action)

Redo tries to redo the last undone operation, and returns whether it has, and the action to be performed.

func (*Scene) ResetModified

func (s *Scene) ResetModified()

ResetModified resets the scene modified flag

func (*Scene) SaveToText

func (s *Scene) SaveToText(w io.Writer) error

SaveToText saves the scene into text format.

All errors originate from the underlying io.Writer.

func (*Scene) Undo

func (s *Scene) Undo() (bool, Action)

Undo tries to undo the last operation, and returns whether it has, and the action to be performed.

func (*Scene) Update

func (s *Scene) Update() (action Action)

Update hovered object

type Selection

type Selection struct {
	ObjectSelection
	// contains filtered or unexported fields
}

func (*Selection) Dispatch

func (s *Selection) Dispatch(action Action) Action

Dispatch performs a Selection action, updating its state, and returns an new action to be performed

See: ActionHandler

func (Selection) Draw

func (s Selection) Draw()

Draws the selection (and the transformed selection if any)

func (*Selection) GetAction

func (s *Selection) GetAction() Action

GetAction processes inputs in ModeSelection and returns an action to be performed.

See: GetActionFunc

func (*Selection) Reset

func (s *Selection) Reset()

type SelectionActionBeginTransformation

type SelectionActionBeginTransformation struct {
	// Selection mode
	Mode SelectionMode
	// Start position for transformation
	Pos rl.Vector2
	// If true, the transformation will track the mouse even on mouse down
	MoveOnMouseDown bool
}

SelectionActionBeginTransformation - switch selection to either SelectionDrag or SelectionDuplicate

func (SelectionActionBeginTransformation) Target

type SelectionActionDelete

type SelectionActionDelete struct{}

SelectionActionDelete - delete the current selection (SelectionNormal)

func (SelectionActionDelete) Target

type SelectionActionEndTransformation

type SelectionActionEndTransformation struct {
	// If true, discard the transformation regardless of its validity
	Discard bool
}

SelectionActionEndTransformation - commit the selection transformation to the scene

func (SelectionActionEndTransformation) Target

type SelectionActionInitSelection

type SelectionActionInitSelection struct{ Selection ObjectSelection }

SelectionActionInitSelection - initialize a new selection from a subset of the scene

func (SelectionActionInitSelection) Target

type SelectionActionInitSingleDrag

type SelectionActionInitSingleDrag struct {
	// Object to select
	Object Object
	// Start position [SelectionDrag]
	Pos rl.Vector2
}

SelectionActionInitSingleDrag - initialize a new selection with a single object in SelectionDrag mode

func (SelectionActionInitSingleDrag) Target

type SelectionActionMoveBy

type SelectionActionMoveBy struct{ Delta rl.Vector2 }

SelectionActionMoveBy - translate the selection by a given delta

func (SelectionActionMoveBy) Target

type SelectionActionMoveTo

type SelectionActionMoveTo struct{ Pos rl.Vector2 }

SelectionActionMoveTo - update the selection transformation position

func (SelectionActionMoveTo) Target

type SelectionActionRotate

type SelectionActionRotate struct{}

SelectionActionRotate - rotate the selection transformation

func (SelectionActionRotate) Target

type SelectionMode

type SelectionMode int

Represents a selection sub mode

const (
	// Normal selection
	SelectionNormal SelectionMode = iota
	// A single text box is selected, allow text editing in details panel & text box resizing
	SelectionSingleTextBox
	// Selection is dragged
	SelectionDrag
	// Selection is being duplicated
	SelectionDuplicate
	// A single text box is being resized
	SelectionTextBoxResize
)

func (SelectionMode) String

func (m SelectionMode) String() string

type Selector

type Selector struct {

	// objects in selector rectangle
	ObjectSelection
	// contains filtered or unexported fields
}

func (*Selector) Dispatch

func (s *Selector) Dispatch(action Action) Action

Dispatch performs Selector action, updating its state, and returns an new action to be performed

See: ActionHandler

func (Selector) Draw

func (s Selector) Draw()

Draw selector rectangle

func (*Selector) GetAction

func (s *Selector) GetAction() Action

GetAction processes inputs in ModeNormal and returns an action to be performed.

See: GetActionFunc

func (*Selector) Reset

func (s *Selector) Reset()

type SelectorActionInit

type SelectorActionInit struct{ Pos rl.Vector2 }

SelectorActionInit - initialize the rectangle selector

func (SelectorActionInit) Target

func (a SelectorActionInit) Target() ActionTarget

type SelectorActionMoveTo

type SelectorActionMoveTo struct{ Pos rl.Vector2 }

SelectorActionMoveTo - update the rectangle selector end corner position

func (SelectorActionMoveTo) Target

type SelectorActionSelect

type SelectorActionSelect struct{}

SelectorActionSelect - apply the rectangle selector

func (SelectorActionSelect) Target

type TextBox

type TextBox struct {
	Bounds  rl.Rectangle
	Content string
}

func (*TextBox) Draw

func (tb *TextBox) Draw(state DrawState, drawHandle bool)

Draw draws the textbox (must be called outside of Camera2D mode)

func (TextBox) HandleRect

func (tb TextBox) HandleRect() rl.Rectangle

Jump to

Keyboard shortcuts

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