Keep behavior variables private to their own graph (#257)
A behavior often needs working state such as a timer or a counter. Until now every variable showed up on each placed object and in the Properties menu, so the inspector filled up with values nobody should touch. A private variable works like any other inside its graph but is not offered anywhere outside. - Each behavior variable gets a lock switch next to Keep. It starts off, so existing projects stay as they are (`privateVariables`). - A placed object shows no private variable, neither in the inspector nor while the game runs. If all are private, it says so. - Switching a variable to private drops its overrides on every placed object in one undo step. Switching back does not restore them. - A running game does not write a private value back as an override, and a project change during the run does not reset it. - `+ Property` no longer offers private variables. A port that names one by hand still reads and writes it without a warning. - The default value of a private variable is read-only in the asset inspector. Its shape (name, fields, type, delete) stays editable. - Keep is now a pin icon instead of a word. With the lock added, the header of a list variable had no room left and the lock covered `+ Item`. Not done: the animation track picker still offers private variables. Tests: ./check.sh -> 186 files, 2711 tests, CHECK EXIT 0. e2e 1,19,20,21,56 -> ALL PASSED, 119 checks. New module 56 has 7 checks with a real mouse. Counter-checks fail as expected: unit without the write-back filter, the sync guard, dropping overrides or loading the flag. Browser with all variables on the object, an unfiltered menu, or no value lock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cf6565d108
commit
e8b3ac0a3b
16 files changed
+455
-49
No files matched your search
@@ -184,9 +184,14 @@ export function deserializeProject(raw: unknown, fallbackId = ''): Project {
|
||||
graph: normalizeGraph(a.graph),
|
||||
};
|
||||
// Only names that are declared, each once, in declaration order.
|
||||
const kept = new Set(Array.isArray(a.keptVariables) ? a.keptVariables : []);
|
||||
const keptVariables = declared.map((v) => v.key).filter((key) => kept.has(key));
|
||||
const declaredOf = (list: unknown): string[] => {
|
||||
const named = new Set(Array.isArray(list) ? list : []);
|
||||
return declared.map((v) => v.key).filter((key) => named.has(key));
|
||||
};
|
||||
const keptVariables = declaredOf(a.keptVariables);
|
||||
if (keptVariables.length > 0) behavior.keptVariables = keptVariables;
|
||||
const privateVariables = declaredOf(a.privateVariables);
|
||||
if (privateVariables.length > 0) behavior.privateVariables = privateVariables;
|
||||
assets.push(behavior);
|
||||
} else if (type === 'variables') {
|
||||
const shared: VariablesAsset = { id, type, name, props, variables: variables.get(id) ?? [] };
|
||||
|
||||
Reference in new issue
Block a user