goedx

package module
v0.0.0-...-57768f3 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2020 License: GPL-3.0 Imports: 18 Imported by: 0

README

GoEDX

Go: Elite Dangerous Extensions Framework

This is primarily driven by giving more design to BC+. If everything goes well GoEDX should turn into something useful itself…

Documentation

Index

Examples

Constants

View Source
const (
	Major   = 0
	Minor   = 1
	Patch   = 0
	Quality = `dev`
	BuildNo = 1
)
View Source
const EchoGalaxy = echoGxy(0)

Variables

Functions

func FindJournals

func FindJournals() (dir string, err error)

func LoadJSON

func LoadJSON(file string, into interface{}) error

func Must

func Must(err error)

func SaveJSON

func SaveJSON(file string, data interface{}) error

Types

type App

type App interface {
	Prepare(e events.Event) (token interface{})
	Finish(token interface{}, e events.Event, chg Change)
}

type AppChannel

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

func NewAppChannel

func NewAppChannel(app App, capacity int) *AppChannel

func (*AppChannel) Close

func (ac *AppChannel) Close()

func (*AppChannel) Finish

func (ac *AppChannel) Finish(token interface{}, e events.Event, chg Change)

type Change

type Change uint64
const (
	ChgGame Change = (1 << iota)
	ChgCommander
	ChgLocation

	ChgTopNum = 3
)

type ChgF32

type ChgF32 float32

func (ChgF32) MarshalJSON

func (f ChgF32) MarshalJSON() ([]byte, error)

func (*ChgF32) Set

func (f *ChgF32) Set(v float32, chg Change) Change

func (*ChgF32) UnmarshalJSON

func (f *ChgF32) UnmarshalJSON(data []byte) error

type ChgString

type ChgString string

func (*ChgString) Set

func (s *ChgString) Set(v string, chg Change) Change

type Commander

type Commander struct {
	FID    string
	Name   string
	Ranks  Ranks
	ShipID int
	At     JSONLocation
	Ships  map[int]*Ship
	Mats   Materials
	// contains filtered or unexported fields
}

func NewCommander

func NewCommander(fid string) *Commander

func (*Commander) FindShip

func (cmdr *Commander) FindShip(id int) *Ship

func (*Commander) GetShip

func (cmdr *Commander) GetShip(id int) *Ship

func (*Commander) Load

func (cmdr *Commander) Load(file string) error

func (*Commander) Save

func (cmdr *Commander) Save(file string) error

func (*Commander) SetShip

func (cmdr *Commander) SetShip(id int) *Ship

func (*Commander) StoreCurrentShip

func (cmdr *Commander) StoreCurrentShip(shipId int)

shipId == 0 => caller has no idea of id

type EDState

type EDState struct {
	Lock         sync.RWMutex `json:"-"`
	GoEDXversion struct{ Major, Minor, Patch int }
	// Is modified w/o using Lock!
	EDVersion string
	Beta      bool
	Language  string
	L10n      struct {
		Lang   string
		Region string
	}
	Cmdr             *Commander `json:"-"`
	LastJournalEvent time.Time
}

func NewEDState

func NewEDState() *EDState

func (*EDState) Load

func (ed *EDState) Load(file string) error

func (*EDState) MustCommander

func (es *EDState) MustCommander() *Commander

func (*EDState) Read

func (es *EDState) Read(do func() error) error

func (*EDState) Save

func (ed *EDState) Save(file string, cmdrFile string) error

func (*EDState) SetEDVersion

func (es *EDState) SetEDVersion(v string)

func (*EDState) SetLanguage

func (es *EDState) SetLanguage(lang string)

func (*EDState) Write

func (es *EDState) Write(do func() error) error

func (*EDState) WriteCmdr

func (es *EDState) WriteCmdr(do func(*Commander) error) error

type EventHandlingError

type EventHandlingError struct {
	Type  events.Type
	Err   error
	Event string
}

func (*EventHandlingError) Error

func (ehe *EventHandlingError) Error() string

type Extension

type Extension struct {
	JournalDir   string
	JournalAfter time.Time
	EdState      *EDState
	Galaxy       Galaxy
	CmdrFile     func(*Commander) string
	// contains filtered or unexported fields
}

func New

func New(edState *EDState, gxy Galaxy) *Extension

func (*Extension) AddApp

func (ext *Extension) AddApp(name string, app App)

func (*Extension) DiffEvtsHdls

func (ext *Extension) DiffEvtsHdls() (es []string, hs []string)

func (*Extension) EventHandler

func (ext *Extension) EventHandler(evtType events.Type, raw []byte) (err error)

func (*Extension) MustRun

func (ext *Extension) MustRun(latestJournal bool)

func (*Extension) Run

func (ext *Extension) Run(latestJournal bool) (err error)

func (*Extension) Stop

func (ext *Extension) Stop()

type Galaxy

type Galaxy interface {
	EdgxSystem(addr uint64, name string, coos []float32) (*System, interface{})
}

type InMemGalaxy

type InMemGalaxy map[uint64]*System

func (InMemGalaxy) EdgxSystem

func (g InMemGalaxy) EdgxSystem(addr uint64, name string, coos []float32) (*System, interface{})

type JSONLocation

type JSONLocation struct {
	Location
}

func (JSONLocation) MarshalJSON

func (jloc JSONLocation) MarshalJSON() ([]byte, error)

func (JSONLocation) Port

func (jl JSONLocation) Port() *Port

func (JSONLocation) System

func (jl JSONLocation) System() *System

func (*JSONLocation) UnmarshalJSON

func (jloc *JSONLocation) UnmarshalJSON(data []byte) (err error)

type Location

type Location interface {
	System() *System
}

type Material

type Material struct {
	Stock  int
	Demand int
}

type Materials

type Materials struct {
	Raw map[string]Material
	Man map[string]Material
	Enc map[string]Material
}

type Port

type Port struct {
	Sys    *System
	Name   string
	Docked bool
}
Example
p := Port{
	Sys: &System{
		Addr: 4711,
		Name: "Köln",
		Coos: ToSysCoos(3, 2, 1),
	},
	Name: "Hafen",
}
var sb bytes.Buffer
enc := json.NewEncoder(&sb)
enc.Encode(&p)
os.Stdout.Write(sb.Bytes())
sb.Reset()
enc.Encode(JSONLocation{&p})
os.Stdout.Write(sb.Bytes())
var jloc JSONLocation
fmt.Println(json.Unmarshal(sb.Bytes(), &jloc))
sb.Reset()
enc.Encode(&p)
os.Stdout.Write(sb.Bytes())
Output:

{"Sys":{"Addr":4711,"Name":"Köln","Coos":[3,2,1]},"Name":"Hafen","Docked":false}
{"@type":"port","Docked":false,"Name":"Hafen","Sys":{"Addr":4711,"Name":"Köln","Coos":[3,2,1]}}
<nil>
{"Sys":{"Addr":4711,"Name":"Köln","Coos":[3,2,1]},"Name":"Hafen","Docked":false}

func (*Port) System

func (p *Port) System() *System

type Rank

type Rank struct {
	Level    int
	Progress int
}

type RankType

type RankType int
const (
	Combat RankType = iota
	Trade
	Explore
	CQC
	Federation
	Empire

	RanksNum
)

func (RankType) String

func (i RankType) String() string

type Ranks

type Ranks [RanksNum]Rank

type Ship

type Ship struct {
	Type  string
	Ident string
	Name  string
	Berth *Port      `json:",omitempty"`
	Sold  *time.Time `json:",omitempty"`
}

type SysCoos

type SysCoos [3]ChgF32

func ToSysCoos

func ToSysCoos(x, y, z float32) SysCoos

func (*SysCoos) Set

func (sc *SysCoos) Set(x, y, z float32, chg Change) (res Change)

type System

type System struct {
	Addr uint64
	Name string
	Coos SysCoos
}

func NewSystem

func NewSystem(addr uint64, name string, coos ...float32) *System

func (*System) Same

func (s *System) Same(name string, coos ...float32) bool

func (*System) Set

func (s *System) Set(name string, coos ...float32)

func (*System) System

func (s *System) System() *System

Directories

Path Synopsis
apps
examples
tools

Jump to

Keyboard shortcuts

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