internal

package
v0.3.13 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2021 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package internal contains utility functions and constants for Spy Cards Online.

Index

Constants

View Source
const (
	MMServerError     websocket.StatusCode = 3000
	MMClientError     websocket.StatusCode = 3001
	MMConnectionError websocket.StatusCode = 3002
	MMTimeout         websocket.StatusCode = 3003
	MMNotFound        websocket.StatusCode = 3004
)

Matchmaking websocket close codes.

Variables

View Source
var DefaultConfig = &Config{
	MatchmakingServer:     "wss://spy-cards.lubar.me/spy-cards/ws",
	UserImageBaseURL:      "https://spy-cards.lubar.me/spy-cards/user-img/",
	CustomCardAPIBaseURL:  "https://spy-cards.lubar.me/spy-cards/custom/api/",
	MatchRecordingBaseURL: "https://spy-cards.lubar.me/spy-cards/recording/",
	ArcadeAPIBaseURL:      "https://spy-cards.lubar.me/spy-cards/arcade/api/",
	GamePageURL:           "https://spy-cards.lubar.me/game.html",
	IPFSBaseURL:           "https://ipfs.lubar.me/ipfs/",
}

DefaultConfig is the Config used by the official Spy Cards Online site.

View Source
var ErrRandomFailure = errors.New("internal: synthesized error for testing")
View Source
var OnSettingsChanged []func(*Settings)

OnSettingsChanged is a slice of callbacks for when a setting is saved.

View Source
var RenderLoopID string
View Source
var SetWindowTitle func(string)
View Source
var Version = [3]uint64{0, 3, 13}

Version is the current version of Spy Cards Online.

Functions

func DecodeJPEG added in v0.2.73

func DecodeJPEG(b []byte) (image.Image, error)

DecodeJPEG allows JPEG decoding to be implemented differently per platform.

func DecodePNG added in v0.2.73

func DecodePNG(b []byte, grayscale bool) (image.Image, error)

DecodePNG allows PNG decoding to be implemented differently per platform.

func DecodeWebP added in v0.3.5

func DecodeWebP(b []byte) (image.Image, error)

DecodeWebP allows WebP decoding to be implemented differently per platform.

func GoRoutineID added in v0.3.1

func GoRoutineID() string

func LoadData added in v0.2.75

func LoadData(key string) ([]byte, error)

func ModifyRequest added in v0.2.67

func ModifyRequest(r *http.Request) *http.Request

ModifyRequest modifies an HTTP request before it is sent.

func OpenAsset added in v0.2.73

func OpenAsset(ctx context.Context, name string) (io.ReadCloser, error)

OpenAsset opens a local asset or performs an HTTP request.

func OpenURL added in v0.3.1

func OpenURL(ctx context.Context, u string) error

func PrefersReducedMotion added in v0.3.4

func PrefersReducedMotion() bool

func RandomlyFail added in v0.3.9

func RandomlyFail() error

func ReadClipboard added in v0.2.81

func ReadClipboard() (string, error)

func SaveSettings

func SaveSettings(s *Settings)

SaveSettings stores the settings in the user's persistent storage and invokes OnSettingsChanged callbacks.

func SecretFlag added in v0.3.5

func SecretFlag(name string) bool

func SelectFile added in v0.3.1

func SelectFile(ctx context.Context, accept string) ([]byte, error)

func SetActive

func SetActive(b bool)

SetActive sets the active flag for the UI, which hides some UI elements.

func SetTitle added in v0.2.81

func SetTitle(title string)

SetTitle sets the window title.

func StoreData added in v0.2.75

func StoreData(key string, val []byte) error

func VersionNumber added in v0.2.75

func VersionNumber() []byte

VersionNumber returns a string representation of Version.

func WarnIfCalledFromRenderLoop added in v0.3.1

func WarnIfCalledFromRenderLoop(message string, args ...interface{})

func WithConfig

func WithConfig(ctx context.Context, config *Config) context.Context

WithConfig attaches a Config to a context.

func WriteClipboard added in v0.2.81

func WriteClipboard(s string) error

Types

type AudioSettings added in v0.2.67

type AudioSettings struct {
	Music  float64 `json:"music"`
	Sounds float64 `json:"sounds"`
}

AudioSettings are the audio volume settings.

type ButtonStyle added in v0.2.67

type ButtonStyle int

ButtonStyle is a graphical style for button prompts.

const (
	StyleKeyboard       ButtonStyle = 0
	StyleGenericGamepad ButtonStyle = 1
)

Constants for ButtonStyle.

func (ButtonStyle) String added in v0.2.72

func (i ButtonStyle) String() string

type Cache added in v0.2.75

type Cache struct {
	MaxEntries int
	// contains filtered or unexported fields
}

Cache is a FIFO cache.

func (*Cache) Do added in v0.2.75

func (c *Cache) Do(key string, f func() (interface{}, error)) (interface{}, error)

Do returns the cached result of f.

func (*Cache) Get added in v0.2.75

func (c *Cache) Get(key string) (interface{}, bool, error)

Get returns the value and error stored for a given key.

type Config

type Config struct {
	MatchmakingServer     string `json:"matchmaking_server"`
	UserImageBaseURL      string `json:"user_image_base_url"`
	CustomCardAPIBaseURL  string `json:"custom_card_api_base_url"`
	MatchRecordingBaseURL string `json:"match_recording_base_url"`
	ArcadeAPIBaseURL      string `json:"arcade_api_base_url"`
	GamePageURL           string `json:"game_page_url"`
	IPFSBaseURL           string `json:"ipfs_base_url"`
}

Config holds data about external services used by Spy Cards Online.

func GetConfig

func GetConfig(ctx context.Context) *Config

GetConfig returns the Config associated with a context, or DefaultConfig.

type ControlsSettings added in v0.2.67

type ControlsSettings struct {
	Keyboard int              `json:"keyboard,omitempty"`
	Gamepad  map[string]int   `json:"gamepad,omitempty"`
	CustomKB []KeyboardLayout `json:"customKB"`
	CustomGP []GamepadLayout  `json:"customGP"`
}

ControlsSettings are the input settings.

type ErrUnexpectedStatus added in v0.3.7

type ErrUnexpectedStatus struct {
	Status string
}

func (ErrUnexpectedStatus) Error added in v0.3.7

func (err ErrUnexpectedStatus) Error() string

type GamepadButton added in v0.2.67

type GamepadButton struct {
	Button     int
	IsAxis     bool
	IsPositive bool
}

GamepadButton is a button on a gamepad.

func (GamepadButton) MarshalJSON added in v0.2.67

func (gpb GamepadButton) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (GamepadButton) String added in v0.2.67

func (gpb GamepadButton) String() string

String implements fmt.Stringer.

func (*GamepadButton) UnmarshalJSON added in v0.2.67

func (gpb *GamepadButton) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type GamepadLayout added in v0.2.67

type GamepadLayout struct {
	Name   string            `json:"name"`
	Button [10]GamepadButton `json:"button"`
	Style  ButtonStyle       `json:"style,omitempty"`
}

GamepadLayout is a custom gamepad layout.

type KeyboardLayout added in v0.2.67

type KeyboardLayout struct {
	Name string     `json:"name"`
	Code [10]string `json:"code"`
}

KeyboardLayout is a custom keyboard layout.

type Settings

type Settings struct {
	Audio AudioSettings `json:"audio"`

	Character string `json:"character,omitempty"`

	Disable3D            bool `json:"disable3D,omitempty"`
	ForceRelay           bool `json:"forceRelay,omitempty"`
	DisableCRT           bool `json:"disableCRT,omitempty"`
	PrefersReducedMotion bool `json:"prefersReducedMotion,omitempty"`
	NoStandardSize       bool `json:"noStandardSize,omitempty"`

	AutoUploadRecording     bool `json:"autoUploadRecording,omitempty"`
	DisplayTermacadeButtons bool `json:"displayTermacadeButtons,omitempty"`

	LastTermacadeOption int    `json:"lastTermacadeOption"`
	LastTermacadeName   string `json:"lastTermacadeName,omitempty"`

	Theme    string  `json:"theme,omitempty"`
	DPIScale float64 `json:"dpiScale,omitempty"`

	Controls ControlsSettings `json:"controls"`
}

Settings are the user-configurable options for Spy Cards Online.

func LoadSettings

func LoadSettings() *Settings

LoadSettings retrieves saved settings from persistent storage.

Jump to

Keyboard shortcuts

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