Skip to main content
A NanoForge game is code: there is no scene file beside it. A plugin that shows or edits something of the game reads the code and writes code. The editor gives three tools for that. The code worker holds the project’s files in memory, with unsaved edits, and TypeScript. It is the only place where the compiler is loaded.

A worker entry

Add a second entry to the manifest and to the build.
The context of an analyzer has: A transformer also gets edit, which records the changes: replace(node, text), insertBefore, insertAfter, insertAt(offset, text), remove(node), removeLines(node).

Call them from the page

code.edit returns a HistoryCommand (or undefined when nothing changes). Push it on the file’s history, or group several in a transaction: see history. The model an analyzer returns crosses to the page as plain data: no syntax nodes, no functions.

Codegen targets

A codegen target is how one kind of app keeps part of its state in code. The ECS plugin’s target reads an app’s entry file as a list of entities, components and systems, and writes back operations such as “add a component to this entity”.
  • When several targets apply to an app, the highest priority wins (selectTarget).
  • The Scene screen shows the editor a plugin contributed to SCENE_EDITORS for the target in use.
  • To make the ECS widgets (hierarchy, inspector, systems, 2D scene) edit another place than the entry file’s main, contribute to the ECS plugin’s ecs.sources instead: a location is a file and a function body ({ kind: 'method', class: 'Level1', method: 'setup' }), and the widgets keep working unchanged. The scene plugin edits the selected scene’s setup this way.

Item owners

Items are exports of the game’s code that the editor lists: components, systems, and whatever a plugin describes. The editor extracts for each one its name, documentation, constructor parameters and fields, with their types and defaults, from the code and its TSDoc. What an item is belongs to a plugin, its owner. The ECS plugin owns the @component and @system tags; the core knows nothing about them.
extract returns the plugin’s own data about an export, stored under the plugin’s name. Read items in the page with the catalog:
Items come from the project’s apps, its shared libraries and its installed packages (nf_modules, read-only). The catalog keeps a cache in .nanoforge/editor/cache/meta/ and extracts again only what changed.

Problems

A plugin reports problems (shown in the Problems panel and in the code editor) through DiagnosticsServiceToken, and JSON files get completion and validation from a schema contributed to JSON_SCHEMAS.