Skip to content

Story.set should support dot-path notation for nested object properties #150

Description

@rohal12

Problem

The twee macro system supports dot-path assignment on object variables:

{set $alma.view = "home"}
{set $character.level = $character.level + 1}

But the JavaScript Story.set API does not — it treats the key as a flat string:

Story.set('alma.view', 'home');  // creates a variable literally named "alma.view"
                                  // instead of setting $alma's "view" property

This is because Story.set passes the key directly to state.setVariable(name, value) without any dot-path splitting:

set(nameOrVars: string | Record<string, unknown>, value?: unknown): void {
  const state = useStoryStore.getState();
  if (typeof nameOrVars === 'string') {
    if (nameOrVars.startsWith('%')) {
      state.setTransient(nameOrVars.slice(1), value);
    } else {
      state.setVariable(nameOrVars, value);
    }
  }
  // ...
}

Expected behavior

Story.set('alma.view', 'home') should behave the same as {set $alma.view = "home"} — setting the view property on the $alma object variable.

Similarly, Story.get('alma.view') should return the view property of $alma, consistent with how {$alma.view} works in twee.

Motivation

When game code uses an object variable (e.g. $alma = { view: "home", expanded: "", ... }) to group related UI state, the TS action layer currently has to do read-modify-write:

const alma = Story.get('alma');
Story.set('alma', { ...alma, view: 'home' });

This is verbose and error-prone compared to the twee equivalent. Dot-path support in the API would allow the natural:

Story.set('alma.view', 'home');

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions