Skip to content

Scene file and Editor #6

@MesterMan03

Description

@MesterMan03

Problem / motivation

Currently, to set up a scene in Whatever, mods have to specify every entity, their components and parent-child relations manually. This is rather tedious, especially for bigger scenes. To solve this, create a text-based scene descriptor file that can be referenced and automatically loaded by scripts and design a new, visual editor that will be responsible for managing these scene files, automatically setting up the dev environment and managing mod and game creation, similar to how other game engines do it (Unity, Unreal Engine, Godot etc).

Proposed solution

This issue contains two parts:

Scene descriptor

Scene descriptors are .wscene files that live under the scenes folder of a mod. These files include the entity structure including their components that scripts can request to load. A script can call Scene.loadScene(path) where path is {mod_id}://{path} and works similarly to how VFS assets are loaded.

Implementation notice: Currently, VFS only applies to the assets subfolder of mods, it must be reworked slightly to support the same infrastructure for the scenes and potentially any additional arbitrary subfolder in the future.

The current structure of a .wscene file is TBD, however it must fulfil four criteria:

  • Parent-child relations (perhaps using indentation)
  • Components (should be simple as component data is simple JSON)
  • No predefined entity IDs
  • Script-facing IDs so scripts can automatically get a reference to the created entities.

The last one works like this: each entity in a .wscene file can optionally have a script ID. After loading a scene, scripts can then automatically get a reference to the created entity by using its script ID. The script IDs must be unique inside a .wscene file but can be repeated across different scenes.

Example:

// Load the scene found under mods/scene_mod/scenes/test.wscene
const scene: LoadedScene = await Scene.loadScene("scene_mod://test");

// This scene contains one entity with the script ID "chooseme"
const entity: Entity = scene.get("chooseme");

// Additionally, a LoadedScene object contains helpful metadata
scene.loadTime // time in ms it took the engine to parse and load the scene
scene.entityCount // total entity count in the scene
scene.entities() // Entity[], returns a list of every entity in this scene

Alternatives considered

No response

Scope check

  • This feature belongs in the engine, not a mod
  • This feature does not add game logic to the engine

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions