GitHub快速开始

API 参考取自源码中的 Go 文档注释,以英文书写。

package editorcmd

import "github.com/nsgo-dev/game/pkg/editor/editorcmd"

概述

Package editorcmd is the scene editor's command line, which `go tool game editor` runs and which a game's own editor command runs with the game's component types and editor plugins built in. `game generate editor` writes such a command into a project: a main function built with the gameeditor tag that calls Main with the project's Components and plugins, so its scenes' components are checked against their registered types. `go tool game editor <dir>` runs that command when the project has one.

An editor command opens a project, as its directory or its game.yaml, which opens its main scene, or a scene file, which inside a project opens that project too, and optionally an animation clip on one of the scene's objects. The editor New returns sets editor.Editor.ProjectAssets, so an open project's scenes draw its own atlases, its atlases fill the asset browser and its scene files can be placed as instances (project.Resolver).

索引

常量

const (
	DefaultWindowWidth  = 1120
	DefaultWindowHeight = 680
)

Default window size, in points, Show opens the editor at.

const Usage = "[project-dir | game.yaml | scene.yaml] [clip.animation.yaml [object-id]]"

Usage is the arguments an editor command takes after its flags.

函数

func IsProject(p string) bool

IsProject reports whether p names a project rather than a scene file: a directory, or a file named game.yaml.

func Main(opts Options)

Main is a game's editor command: it runs Run with the process's arguments and opts, and exits with status 2 for a usage error and 1 for any other, after printing it.

func New(opts Options) (*editor.Editor, error)

New returns an editor on an empty scene with opts' component types, plugins, name and library, and ProjectAssets set, so the project Open opens supplies the scenes' assets. A scene opened outside any project resolves no atlases.

func Open(ed *editor.Editor, args []string) error

Open opens in ed what an editor command's arguments name, as Usage gives them. args[0] is a project, as its directory or its game.yaml, which opens the project and its main scene (editor.Editor.OpenProject), or a scene file, which opens with the project whose directory holds it, when one does (editor.Editor.OpenProjectScene, which sets ScenePath), and on its own otherwise (editor.Editor.OpenFile). args[1] is an animation clip file the animation panel opens on the object named by args[2], or on the scene's first object; that object is selected, so when the clip file does not exist yet the toolbar's Animate button starts a clip on it, and the panel's Save Clip button writes the clip to args[1]. No arguments open nothing.

func ProjectRoot(p string) (string, bool)

ProjectRoot returns the directory of the project p belongs to, and false when it belongs to none: p itself for a directory holding a game.yaml, the directory of a game.yaml, and for any other file the nearest directory above it that holds a game.yaml, unless a directory nearer the file holds an nsgo.yaml or a go.mod, which makes that directory the file's root as game check finds it. For a file, the directory it returns is absolute.

func Run(args []string, opts Options, stderr io.Writer, launch func(*editor.Editor)) error

Run is an editor command run with args, its command line after the program's name: it parses the -library flag into opts.Library and the arguments Usage gives, builds the editor with New, opens the arguments with Open, or the project in the working directory without any, refuses a project listing plugins the editor lacks when opts.RequirePlugins is set, and shows the editor with launch, or when launch is nil as Show does, in a window of opts.WindowWidth by opts.WindowHeight. Usage and flag errors are reported on stderr and wrap a usage error that Main exits 2 for.

func Serve(cx *core.Scope, ed *editor.Editor, stderr io.Writer) *editormcp.Server

Serve serves ed's MCP server (package editormcp) on the endpoint of the project ed has open, and of each project it opens later, until cx is cleaned up, and offers its tools to nsgo mcp under go tool nsgo dev -automation, so an agent reaches a game's own editor as it reaches go tool game editor. An endpoint it cannot open, as when another editor has the project open, is reported on stderr; the editor works without it.

func Show(ed *editor.Editor)

Show shows ed in the scene editor's window, DefaultWindowWidth by DefaultWindowHeight, serving its MCP server for go tool game mcp (Serve), and returns once it closes.

类型

type Options struct {
	// Components are the component types the scenes' objects may set, which the editor checks every component and field against and lists in the inspector, together with the built-in 2D and 3D physics components (sceneformat.RegisterPhysicsComponents) the registry does not register itself; nil leaves components free-form.
	Components *sceneformat.ComponentRegistry
	// Plugins are the editor plugins built into the command, which a project turns on under editor.plugins in its game.yaml.
	Plugins []editor.Plugin
	// AppName is the editor's name in its window title (editor.Editor.AppName); empty means the editor's default.
	AppName string
	// Library is the library index the library panel installs packs from (editor.Editor.Library), as library.Open takes it: an https URL, an index file or a directory holding index.yaml; empty hides the panel.
	Library string
	// WindowWidth and WindowHeight are the size, in points, of the window Run shows the editor in; zero for either means the default, 1120 by 680.
	WindowWidth, WindowHeight core.Points
	// RequirePlugins makes Run refuse a project whose game.yaml lists an editor plugin that Plugins lacks (editor.Editor.MissingPlugins), for a command that should not edit the project's scenes without them.
	RequirePlugins bool
}

Options are what an editor command builds its editor with.