scrap

package
v0.0.0-...-fcfcbe3 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Overview

Package scrap defines the scrap types and functions on them.

Package scrap defines the scrap types and functions on them.

Package scrap defines the scrap types and functions on them.

Package scrap defines the scrap types and functions on them.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidScrapType = errors.New("Invalid scrap type.")
	ErrInvalidScrapName = errors.New("Invalid scrap name.")
	ErrInvalidLanguage  = errors.New("Invalid language.")
	ErrInvalidHash      = errors.New("Invalid SHA256 hash.")
	ErrInvalidScrapSize = errors.New("Scrap is too large.")
)
View Source
var AllLangs = []Lang{CPP, JS}

AllLangs is the list of all supported Langs.

View Source
var AllTypes = []Type{SVG, SKSL, Particle}

AllTypes is a slice of supported Types.

View Source
var MimeTypes = map[Type]string{
	SVG:      "image/svg+xml",
	SKSL:     "text/plain",
	Particle: "application/json",
}

MimeTypes for each scrap type when served raw.

Functions

func New

func New(client gcs.GCSClient) (*scrapExchange, error)

New returns a new instance of ScrapExchange.

Types

type ChildShader

type ChildShader struct {
	UniformName     string
	ScrapHashOrName string
}

ChildShader is the scrap id of a single child shader along with the name that the uniform should have to access it.

type Lang

type Lang string

Lang is a programming language a scrap can be embedded in.

const (
	// CPP is the C++ language.
	CPP Lang = "cpp"

	// JS is the Javascript language.
	JS Lang = "js"

	// UnknownLang is an unknown language.
	UnknownLang Lang = ""
)

func ToLang

func ToLang(s string) Lang

ToLang converts a string to a Lang, returning UnknownLang if it not a valid Lang.

type Name

type Name struct {
	Hash        SHA256
	Description string
}

Name has information about a single named scrap.

type ParticlesMetaData

type ParticlesMetaData struct {
}

ParticlesMetaData is metadata for Particle scraps.

type SHA256

type SHA256 string

SHA256 is a SHA 256 hash encoded in hex.

type SKSLMetaData

type SKSLMetaData struct {
	// Uniforms are all the inputs to the shader.
	Uniforms []float32

	// ImageURL is the URL of an image to load as an input shader.
	ImageURL string

	// Child shaders. A slice because order is important when mapping uniform
	// names in code to child shaders passed to makeShaderWithChildren.
	Children []ChildShader
}

SKSLMetaData is metadata for SKSL scraps.

type SVGMetaData

type SVGMetaData struct {
}

SVGMetaData is metadata for SVG scraps.

type ScrapBody

type ScrapBody struct {
	Type Type
	Body string

	// Type specific metadata:
	SVGMetaData       *SVGMetaData       `json:",omitempty"`
	SKSLMetaData      *SKSLMetaData      `json:",omitempty"`
	ParticlesMetaData *ParticlesMetaData `json:",omitempty"`
}

ScrapBody is the body of scrap stored in GCS and transported by the API.

type ScrapExchange

type ScrapExchange interface {
	// Expand the given scrap into a full program in the given language and write
	// that code to the given io.Writer.
	Expand(ctx context.Context, t Type, hashOrName string, lang Lang, w io.Writer) error

	// LoadScrap loads a scrap. The 'name' can be either a hash, or if prefixed with
	// an "@" it is the name of scrap.
	LoadScrap(ctx context.Context, t Type, hashOrName string) (ScrapBody, error)

	// CreateScrap and return the hash by the ScrapID.
	CreateScrap(ctx context.Context, scrap ScrapBody) (ScrapID, error)

	// DeleteScrap and also delete the name if hashOrName is a name, which is indicated by
	// the prefix "@".
	DeleteScrap(ctx context.Context, t Type, hashOrName string) error

	// PutName creates or updates a name for a given scrap.
	PutName(ctx context.Context, t Type, name string, nameBody Name) error

	// GetName retrieves the hash for the given named scrap.
	GetName(ctx context.Context, t Type, name string) (Name, error)

	// DeleteName removes the name for the given named scrap.
	DeleteName(ctx context.Context, t Type, name string) error

	// ListNames lists all the known names for a given type of scrap.
	ListNames(ctx context.Context, t Type) ([]string, error)
}

ScrapExchange handles reading and writing scraps.

type ScrapID

type ScrapID struct {
	Hash SHA256
}

ScrapID contains the identity of a newly created scrap.

type Type

type Type string

Type identifies the type of a scrap.

const (
	// SVG scrap.
	SVG Type = "svg"

	// SKSL scrap.
	SKSL Type = "sksl"

	// Particle scrap.
	Particle Type = "particle"

	// UnknownType type of scrap.
	UnknownType Type = ""
)

func ToType

func ToType(s string) Type

ToType converts a string to a Type, returning UnknownType if it is not a valid Type.

type Uniform

type Uniform struct {
	Name  string
	Value float64
}

Uniform is a single uniform for an SkSL shader.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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