wedit

package
v0.0.0-...-4ede3f3 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: BSD-2-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package wedit provides the server backend for a game world editor. We originally had separate maped and chared, which unified code in gamed. Now that we want to import the old editor data, we need a new package to avoid an import cycle. We should later moved code from gamed into the editor package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Import

func Import(dbpath, dir string) (*bbolt.DB, error)

func Load

func Load(dir string) (db *bbolt.DB, err error)

we want to check for a bolt db first. then if we have not found one check for chared and map data to import.

Types

type ConnSubs

type ConnSubs struct {
	Conn hub.Conn
	*Editor
	Subs []*TopicSubs
}

func (*ConnSubs) SubTop

func (sub *ConnSubs) SubTop(t Top) *TopicSubs

func (*ConnSubs) UnsubKind

func (sub *ConnSubs) UnsubKind(kind string)

func (*ConnSubs) UnsubTop

func (sub *ConnSubs) UnsubTop(t Top) *TopicSubs

type EditFunc

type EditFunc = func(*ConnSubs, *hub.Msg) error

type Editor

type Editor struct {
	// The world data that is saved to disk.
	bolt.WorldSync
	// Conns holds a list of clients connected to this editor.
	site.Conns

	// Tops stores all topics and the clients that are subscribed to them.
	Tops map[Top]*TopicSubs
}

Editor provides the world data and ways to edit this data. It also holds client subscriptions for certain topics.

func NewEditor

func NewEditor(w *game.World) *Editor

type IDReq

type IDReq[I ids.ID] struct {
	ID I `json:"id"`
}

func ParseID

func ParseID[I ids.ID](m *hub.Msg) (req IDReq[I])

type InitInfo

type InitInfo struct {
	Worlds []string `json:"worlds"`
}

type NameReq

type NameReq struct {
	Name string `json:"name"`
}

func ParseName

func ParseName(m *hub.Msg) (req NameReq)

type PicsData

type PicsData struct {
	ID   ids.Img    `json:"id"`
	Pics []*pix.Pic `json:"pics"`
}

type Room

type Room struct {
	DB *bbolt.DB
	site.ChatRoom
	RoomSubs

	Worlds []string
	// contains filtered or unexported fields
}

func NewRoom

func NewRoom(datapath string) (*Room, error)

func (*Room) Export

func (r *Room) Export(dir string, zw *zip.Writer) error

func (*Room) HasWorld

func (r *Room) HasWorld(name string) bool

func (*Room) NewWorld

func (r *Room) NewWorld(name string) (*game.World, error)

func (*Room) Route

func (r *Room) Route(m *hub.Msg)

func (*Room) SetDefaults

func (r *Room) SetDefaults(w *game.World) error

func (*Room) WorldIdx

func (r *Room) WorldIdx(name string) int

type RoomSubs

type RoomSubs struct {
	Editors map[string]*Editor
	Subs    map[int64]*ConnSubs
}

func MakeRoomSubs

func MakeRoomSubs() RoomSubs

func (*RoomSubs) EditorSub

func (r *RoomSubs) EditorSub(c hub.Conn) *Editor

func (*RoomSubs) SubEditor

func (r *RoomSubs) SubEditor(c hub.Conn, ed *Editor)

func (*RoomSubs) Unsub

func (r *RoomSubs) Unsub(id int64)

type SliceReq

type SliceReq[T any] struct {
	Idx  int  `json:"idx,omitempty"`
	Del  int  `json:"del,omitempty"`
	Copy bool `json:"copy,omitempty"`
}

func (SliceReq[T]) Apply

func (r SliceReq[T]) Apply(old, new []T) ([]T, error)

type Top

type Top interface {
	Top() string
}

type TopicSubs

type TopicSubs struct {
	Top Top
	site.Conns
}

most model changes are sent to all connected clients however the level grids an img pics are only subscribed when needed when user opens a img or lvl we auto subscribe for grid and pics changes

func (*TopicSubs) BcastRaw

func (ts *TopicSubs) BcastRaw(subj string, data any, except int64)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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