stated

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2022 License: GPL-3.0 Imports: 21 Imported by: 0

README

StatED

Trace the state of your commander in Elite Dangerous

Note that this is not a ready-to-use application. Instead its a library supporting one to build ED related companion applications for ED.

Disclaimer

StatED was created using assets from Elite: Dangerous, with the permission of Frontier Developments plc, for non-commercial purposes. It is not endorsed by nor reflects the views or opinions of Frontier Developments and no employee of Frontier Developments was involved in the making of it.

Documentation

Overview

Example (ParseModuleItem)
const example = "int_powerplant_size3_class5"
base, size, class := parseModuleItem(example)
fmt.Println(base, size, class)
Output:

int_powerplant 3 5

Index

Examples

Constants

View Source
const (
	ChgGame change.Flags = (1 << iota)
	ChgCommander
	ChgSystem
	ChgLocation
	ChgShip

	ChgEND
)
View Source
const (
	LocTypeSystem  = "system"
	LocTypePort    = "port"
	LocTypeFSDJump = "jump"
)

Variables

View Source
var (
	LogCfg c4hgol.LogConfig = log
)

Functions

func EconomyKey

func EconomyKey(k string) string

func GovernmentKey

func GovernmentKey(k string) string

func LoadJSON

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

func ParseEDLang

func ParseEDLang(edlang string) (lang, region string)

func PortSvcKey

func PortSvcKey(k string) string

func SaveJSON

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

func ShipFromLoadout

func ShipFromLoadout(e *journal.Loadout, types ships.TypeRepo) (ship *ships.Ship, err error)

func ShipKey

func ShipKey(k string) string

func SysSecurityKey

func SysSecurityKey(k string) string

Types

type Cargo

type Cargo struct {
	Name   string
	Count  int16
	Stolen int16
}

type ChangeEvent

type ChangeEvent struct {
	Change change.Flags
	Event  events.Event
}

type CmdrFile

type CmdrFile struct {
	Dir    string
	MkDirs bool
}

func (CmdrFile) Filename

func (cf CmdrFile) Filename(fid, _ string) string

type Commander

type Commander struct {
	FID    string
	Name   change.Val[string]
	Ranks  Ranks
	ShipID change.Val[int]
	// contains filtered or unexported fields
}

func NewCommander

func NewCommander(fid string) *Commander

type Config

type Config struct {
	CmdrFile        func(fid, name string) string `json:"-"`
	ShutdownLogsOut bool
}

type EDState

type EDState struct {
	Config `json:"-"`

	EDVersion string `json:"-"`
	Beta      bool   `json:"-"`
	Language  string `json:"-"`
	L10n      struct {
		Lang   string
		Region string
	} `json:"-"`
	Cmdr  *Commander
	Loc   JSONLocation
	Ships map[int]*Ship
	Mats  Materials
	Cargo map[string]*Cargo

	Notify []chan<- ChangeEvent `json:"-"`
	// contains filtered or unexported fields
}
Example (Marshal)
eds := NewEDState(&Config{
	CmdrFile: CmdrFile{Dir: "."}.Filename,
})
eds.Cmdr = NewCommander("F4711")
eds.Cmdr.Name = change.NewVal("John Doe")
_, err := json.Marshal(eds)
fmt.Println(err)
Output:

<nil>

func NewEDState

func NewEDState(cfg *Config) *EDState

func (*EDState) Close

func (ed *EDState) Close() error

func (*EDState) FindShip

func (ed *EDState) FindShip(id int) *Ship

func (*EDState) GetShip

func (ed *EDState) GetShip(id int) *Ship

func (*EDState) Load

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

func (*EDState) MustCommander

func (ed *EDState) MustCommander(where string) *Commander

func (*EDState) OnJournalEvent

func (ed *EDState) OnJournalEvent(e watched.JounalEvent) (err error)

func (*EDState) OnStatusEvent

func (ed *EDState) OnStatusEvent(e watched.StatusEvent) error

func (*EDState) RdLocked

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

func (*EDState) Reset

func (ed *EDState) Reset()

func (*EDState) Save

func (ed *EDState) Save() error

func (*EDState) SetEDVersion

func (es *EDState) SetEDVersion(v string)

func (*EDState) SetLanguage

func (es *EDState) SetLanguage(lang string)

func (*EDState) SwitchCommander

func (ed *EDState) SwitchCommander(fid string, name string) error

func (*EDState) WrLocked

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

type FSDJump

type FSDJump struct {
	Sys *System
	To  *System
}

func (*FSDJump) FromMap

func (j *FSDJump) FromMap(m map[string]interface{}) (err error)

func (*FSDJump) System

func (j *FSDJump) System() *System

func (*FSDJump) ToMap

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

type HandlerFunc

type HandlerFunc func(*EDState, events.Event) change.Flags

type JSONLocation

type JSONLocation struct {
	Location
}

func (JSONLocation) FSDJump

func (jl JSONLocation) FSDJump() *FSDJump

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
	ToMap(m *map[string]interface{}, setType bool) error
	FromMap(m map[string]interface{}) error
}

type Materials

type Materials struct {
	Raw map[string]int `json:",omitempty"`
	Man map[string]int `json:",omitempty"`
	Enc map[string]int `json:",omitempty"`
}

type Port

type Port struct {
	Sys    *System
	Name   string
	Type   string `json:",omitempty"`
	Docked bool
}
Example
p := Port{
	Sys: &System{
		Addr: 4711,
		Name: "Köln",
		Coos: ToSysCoos(3, 2, 1),
	},
	Name:   "Hafen",
	Type:   "Orbis",
	Docked: true,
}
var sb bytes.Buffer
enc := json.NewEncoder(&sb)
enc.SetIndent("", "  ")
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",
  "Type": "Orbis",
  "Docked": true
}
{
  "@type": "port",
  "Docked": true,
  "Name": "Hafen",
  "Sys": {
    "Addr": 4711,
    "Coos": [
      3,
      2,
      1
    ],
    "Name": "Köln"
  },
  "Type": "Orbis"
}
<nil>
{
  "Sys": {
    "Addr": 4711,
    "Name": "Köln",
    "Coos": [
      3,
      2,
      1
    ]
  },
  "Name": "Hafen",
  "Type": "Orbis",
  "Docked": true
}

func (*Port) FromMap

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

func (*Port) System

func (p *Port) System() *System

func (*Port) ToMap

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

type Rank

type Rank struct {
	Level    int `json:"L"`
	Progress int `json:"P"`
}

type RankType

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

	RanksNum
)

func (RankType) String

func (i RankType) String() string

type Ranks

type Ranks [RanksNum]Rank
Example
var rs Ranks
enc := json.NewEncoder(os.Stdout)
enc.Encode(rs)
Output:

{"CQC":{"L":0,"P":0},"Combat":{"L":0,"P":0},"Empire":{"L":0,"P":0},"Explore":{"L":0,"P":0},"Federation":{"L":0,"P":0},"Trade":{"L":0,"P":0}}

func (Ranks) MarshalJSON

func (rs Ranks) MarshalJSON() ([]byte, error)

func (*Ranks) UnmarshalJSON

func (rs *Ranks) UnmarshalJSON(raw []byte) error

type Ship

type Ship struct {
	Type     string
	Ident    change.Val[string]
	Name     change.Val[string]
	Cargo    change.Val[int]
	MaxRange att.Float32
	MaxJump  att.Float32
	Berth    *Port      `json:",omitempty"`
	Sold     *time.Time `json:",omitempty"`
}

type SysCoos

type SysCoos [3]att.Float32

func ToSysCoos

func ToSysCoos(x, y, z float32) SysCoos

func (*SysCoos) Set

func (sc *SysCoos) Set(x, y, z float32, chg change.Flags) (res change.Flags)

func (*SysCoos) Valid

func (sc *SysCoos) Valid() bool

type System

type System struct {
	Addr uint64
	Name string
	Coos SysCoos
}
Example
s := NewSystem(4711, "Köln", 3, 2, 1)
var sb bytes.Buffer
enc := json.NewEncoder(&sb)
enc.SetIndent("", "  ")
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
  ]
}
{
  "@type": "system",
  "Addr": 4711,
  "Coos": [
    3,
    2,
    1
  ],
  "Name": "Köln"
}
<nil>
{
  "Addr": 4711,
  "Name": "Köln",
  "Coos": [
    3,
    2,
    1
  ]
}

func NewSystem

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

func (*System) FromMap

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) (changed bool)

func (*System) System

func (s *System) System() *System

func (*System) ToMap

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

func (*System) Update

func (sys *System) Update(addr uint64, name string, coos ...float32) (*System, bool)

Directories

Path Synopsis
examples
tools

Jump to

Keyboard shortcuts

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