goedx

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 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   = 2
	Quality = `a`
	BuildNo = 3
)
View Source
const EchoGalaxy = echoGxy(0)
View Source
const JumpHitsMax = 100

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 {
	PrepareEDEvent(e events.Event) (token interface{})
	FinishEDEvent(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) FinishEDEvent added in v0.2.0

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

func (*AppChannel) PrepareEDEvent added in v0.2.0

func (ac *AppChannel) PrepareEDEvent(e events.Event) (token interface{})

type Change

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

	ChgLocation
	ChgSystem

	ChgShip
)

func (Change) All added in v0.2.0

func (chg Change) All(c Change) bool

func (Change) Any added in v0.2.0

func (chg Change) Any(c Change) bool

func (Change) Without added in v0.2.0

func (chg Change) Without(c Change) Change

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 ChgInt added in v0.2.0

type ChgInt int

func (*ChgInt) Set added in v0.2.0

func (i *ChgInt) Set(v int, chg Change) Change

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

	JumpHist    []Jump
	LastJump    int
	RawMatStats map[string]*RawMatStats
	// 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) Jump added in v0.2.0

func (cmdr *Commander) Jump(addr uint64, t time.Time)

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) (res *Ship, chg bool)

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
	ShutdownLogsOut bool
	// 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()

func (*Extension) SwitchCommander

func (ext *Extension) SwitchCommander(fid, name string) *Commander

type Galaxy

type Galaxy interface {
	// Extended galaxy implementations may return extended system info in the interface{}
	EdgxSystem(addr uint64, name string, coos []float32, touch time.Time) (*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 Jump added in v0.2.0

type Jump struct {
	SysAddr uint64
	Arrive  time.Time
}

type Location

type Location interface {
	System() *System
	ToMap(m *map[string]interface{}, setType bool) error
	FromMap(m map[string]interface{}) error
}

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",
	Docked: true,
}
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],"FirstAccess":"0001-01-01T00:00:00Z","LastAccess":"0001-01-01T00:00:00Z"},"Name":"Hafen","Docked":true}
{"@type":"port","Docked":true,"Name":"Hafen","Sys":{"Addr":4711,"Coos":[3,2,1],"Name":"Köln"}}
<nil>
{"Sys":{"Addr":4711,"Name":"Köln","Coos":[3,2,1],"FirstAccess":"0001-01-01T00:00:00Z","LastAccess":"0001-01-01T00:00:00Z"},"Name":"Hafen","Docked":true}

func (*Port) FromMap added in v0.2.0

func (p *Port) FromMap(m map[string]interface{}) (err error)

func (*Port) System

func (p *Port) System() *System

func (*Port) ToMap added in v0.2.0

func (p *Port) ToMap(m *map[string]interface{}, setType bool) error

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 RawMatStats added in v0.2.0

type RawMatStats struct {
	Min, Max float32
	Sum      float64
	Count    int
}

type Ship

type Ship struct {
	Type     string
	Ident    ChgString
	Name     ChgString
	Cargo    ChgInt
	MaxRange ChgF32
	MaxJump  ChgF32
	Berth    *Port      `json:",omitempty"`
	Sold     *time.Time `json:",omitempty"`
}

type ShutdownMode added in v0.2.0

type ShutdownMode int

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)

func (*SysCoos) Valid added in v0.2.0

func (sc *SysCoos) Valid() bool

type System

type System struct {
	Addr        uint64
	Name        string
	Coos        SysCoos
	FirstAccess time.Time
	LastAccess  time.Time
}
Example
s := System{
	Addr: 4711,
	Name: "Köln",
	Coos: ToSysCoos(3, 2, 1),
}
var sb bytes.Buffer
enc := json.NewEncoder(&sb)
enc.Encode(&s)
os.Stdout.Write(sb.Bytes())
sb.Reset()
enc.Encode(JSONLocation{&s})
os.Stdout.Write(sb.Bytes())
var jloc JSONLocation
fmt.Println(json.Unmarshal(sb.Bytes(), &jloc))
sb.Reset()
enc.Encode(&s)
os.Stdout.Write(sb.Bytes())
Output:

{"Addr":4711,"Name":"Köln","Coos":[3,2,1],"FirstAccess":"0001-01-01T00:00:00Z","LastAccess":"0001-01-01T00:00:00Z"}
{"@type":"system","Addr":4711,"Coos":[3,2,1],"Name":"Köln"}
<nil>
{"Addr":4711,"Name":"Köln","Coos":[3,2,1],"FirstAccess":"0001-01-01T00:00:00Z","LastAccess":"0001-01-01T00:00:00Z"}

func NewSystem

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

func (*System) FromMap added in v0.2.0

func (s *System) FromMap(m map[string]interface{}) (err error)

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

func (*System) ToMap added in v0.2.0

func (s *System) ToMap(m *map[string]interface{}, setType bool) error

Directories

Path Synopsis
apps
examples
tools

Jump to

Keyboard shortcuts

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