Compare commits

...

3 Commits

Author SHA1 Message Date
AlexandreSi
0cea3cbace WIP 2024-03-01 10:10:45 +01:00
AlexandreSi
f5a0a0ce0e Add space 2024-02-29 17:25:08 +01:00
AlexandreSi
5b8e912b9e Expose variable persistent uuid to JS 2024-02-29 17:24:37 +01:00
5 changed files with 72 additions and 18 deletions

View File

@@ -271,6 +271,7 @@ interface Variable {
void UnserializeFrom([Const, Ref] SerializerElement element); void UnserializeFrom([Const, Ref] SerializerElement element);
[Ref] Variable ResetPersistentUuid(); [Ref] Variable ResetPersistentUuid();
[Ref] Variable ClearPersistentUuid(); [Ref] Variable ClearPersistentUuid();
[Const, Ref] DOMString GetPersistentUuid();
}; };
interface VariablesContainer { interface VariablesContainer {
@@ -1854,7 +1855,7 @@ interface BehaviorMetadata {
[Ref] Behavior Get(); [Ref] Behavior Get();
BehaviorsSharedData GetSharedDataInstance(); BehaviorsSharedData GetSharedDataInstance();
[Value] MapStringPropertyDescriptor GetProperties(); [Value] MapStringPropertyDescriptor GetProperties();
[Value] MapStringPropertyDescriptor GetSharedProperties(); [Value] MapStringPropertyDescriptor GetSharedProperties();
}; };

View File

@@ -264,6 +264,7 @@ export class Variable extends EmscriptenObject {
unserializeFrom(element: SerializerElement): void; unserializeFrom(element: SerializerElement): void;
resetPersistentUuid(): Variable; resetPersistentUuid(): Variable;
clearPersistentUuid(): Variable; clearPersistentUuid(): Variable;
getPersistentUuid(): string;
} }
export class VariablesContainer extends EmscriptenObject { export class VariablesContainer extends EmscriptenObject {

View File

@@ -36,6 +36,7 @@ declare class gdVariable {
unserializeFrom(element: gdSerializerElement): void; unserializeFrom(element: gdSerializerElement): void;
resetPersistentUuid(): gdVariable; resetPersistentUuid(): gdVariable;
clearPersistentUuid(): gdVariable; clearPersistentUuid(): gdVariable;
getPersistentUuid(): string;
delete(): void; delete(): void;
ptr: number; ptr: number;
}; };

View File

@@ -62,10 +62,10 @@ export const insertInVariablesContainer = (
const newVariable = new gd.Variable(); const newVariable = new gd.Variable();
if (serializedVariable) { if (serializedVariable) {
unserializeFromJSObject(newVariable, serializedVariable); unserializeFromJSObject(newVariable, serializedVariable);
newVariable.resetPersistentUuid();
} else { } else {
newVariable.setString(''); newVariable.setString('');
} }
newVariable.resetPersistentUuid();
const variable = variablesContainer.insert(newName, newVariable, index); const variable = variablesContainer.insert(newName, newVariable, index);
newVariable.delete(); newVariable.delete();
return { name: newName, variable }; return { name: newName, variable };

View File

@@ -12,7 +12,7 @@ import ChevronRight from '../UI/CustomSvgIcons/ChevronArrowRight';
import ChevronBottom from '../UI/CustomSvgIcons/ChevronArrowBottom'; import ChevronBottom from '../UI/CustomSvgIcons/ChevronArrowBottom';
import ButtonBase from '@material-ui/core/ButtonBase'; import ButtonBase from '@material-ui/core/ButtonBase';
import { Column, Line, Spacer } from '../UI/Grid'; import { Column, Line, marginsSize, Spacer } from '../UI/Grid';
import IconButton from '../UI/IconButton'; import IconButton from '../UI/IconButton';
import { DragHandleIcon } from '../UI/DragHandle'; import { DragHandleIcon } from '../UI/DragHandle';
import { makeDragSourceAndDropTarget } from '../UI/DragAndDrop/DragSourceAndDropTarget'; import { makeDragSourceAndDropTarget } from '../UI/DragAndDrop/DragSourceAndDropTarget';
@@ -84,7 +84,11 @@ const DragSourceAndDropTarget = makeDragSourceAndDropTarget('variable-editor');
const stopEventPropagation = (event: SyntheticPointerEvent<HTMLInputElement>) => const stopEventPropagation = (event: SyntheticPointerEvent<HTMLInputElement>) =>
event.stopPropagation(); event.stopPropagation();
const styles = { inlineIcon: { padding: 0 }, handlePlaceholder: { width: 24 } }; const styles = {
inlineIcon: { padding: 0 },
handlePlaceholder: { width: 24 },
undeclaredVariablePaper: { marginTop: marginsSize },
};
export type HistoryHandler = {| export type HistoryHandler = {|
saveToHistory: () => void, saveToHistory: () => void,
@@ -528,6 +532,48 @@ const VariablesList = (props: Props) => {
() => (onComputeAllVariableNames ? onComputeAllVariableNames() : null), () => (onComputeAllVariableNames ? onComputeAllVariableNames() : null),
[onComputeAllVariableNames] [onComputeAllVariableNames]
); );
const computeVariableNamesToVariablesUuid = React.useCallback(
() => {
console.log('salut', allVariablesNames);
if (!allVariablesNames) return {};
return allVariablesNames.reduce((acc, variableName) => {
if (props.variablesContainer.has(variableName)) {
console.log(`got it ${variableName}`);
acc[variableName] = props.variablesContainer
.get(variableName)
.getPersistentUuid();
} else if (
props.inheritedVariablesContainer &&
props.inheritedVariablesContainer.has(variableName)
) {
acc[variableName] = props.inheritedVariablesContainer
.get(variableName)
.getPersistentUuid();
} else {
acc[variableName] = null;
}
return acc;
}, {});
},
[
allVariablesNames,
props.variablesContainer,
props.inheritedVariablesContainer,
]
);
const initialVariableNamesToVariablesUuid = React.useRef<{
[variableName: string]: ?string,
}>(computeVariableNamesToVariablesUuid());
const [
variableNamesToVariablesUuid,
setVariableNamesToVariablesUuid,
] = React.useState<{
[variableName: string]: ?string,
}>(computeVariableNamesToVariablesUuid);
const [selectedNodes, setSelectedNodes] = React.useState<Array<string>>([]); const [selectedNodes, setSelectedNodes] = React.useState<Array<string>>([]);
const [searchMatchingNodes, setSearchMatchingNodes] = React.useState< const [searchMatchingNodes, setSearchMatchingNodes] = React.useState<
Array<string> Array<string>
@@ -596,15 +642,12 @@ const VariablesList = (props: Props) => {
[containerWidth, props.size] [containerWidth, props.size]
); );
const undefinedVariableNames = allVariablesNames const undeclaredVariableNames = Object.entries(variableNamesToVariablesUuid)
? allVariablesNames.filter(variableName => { .map(([variableName, variableUuid]) =>
return ( variableUuid !== null ? null : variableName
!props.variablesContainer.has(variableName) && )
(!props.inheritedVariablesContainer || .filter(Boolean);
!props.inheritedVariablesContainer.has(variableName)) console.log(variableNamesToVariablesUuid, undeclaredVariableNames);
);
})
: [];
const { historyHandler, onVariablesUpdated, variablesContainer } = props; const { historyHandler, onVariablesUpdated, variablesContainer } = props;
const _onChange = React.useCallback( const _onChange = React.useCallback(
@@ -844,9 +887,10 @@ const VariablesList = (props: Props) => {
if (success) { if (success) {
_onChange(); _onChange();
forceUpdate(); forceUpdate();
setVariableNamesToVariablesUuid(computeVariableNamesToVariablesUuid);
} }
}, },
[_onChange, forceUpdate, _deleteNode] [_onChange, forceUpdate, _deleteNode, computeVariableNamesToVariablesUuid]
); );
const deleteSelection = React.useCallback( const deleteSelection = React.useCallback(
@@ -864,9 +908,10 @@ const VariablesList = (props: Props) => {
if (deleteSuccesses.some(Boolean)) { if (deleteSuccesses.some(Boolean)) {
_onChange(); _onChange();
setSelectedNodes([]); setSelectedNodes([]);
setVariableNamesToVariablesUuid(computeVariableNamesToVariablesUuid);
} }
}, },
[_onChange, _deleteNode, selectedNodes] [_onChange, _deleteNode, selectedNodes, computeVariableNamesToVariablesUuid]
); );
const updateExpandedAndSelectedNodesFollowingNameChange = React.useCallback( const updateExpandedAndSelectedNodesFollowingNameChange = React.useCallback(
@@ -1463,6 +1508,7 @@ const VariablesList = (props: Props) => {
if (!parentVariable) { if (!parentVariable) {
props.variablesContainer.rename(name, safeAndUniqueNewName); props.variablesContainer.rename(name, safeAndUniqueNewName);
setVariableNamesToVariablesUuid(computeVariableNamesToVariablesUuid);
} else { } else {
parentVariable.renameChild(name, safeAndUniqueNewName); parentVariable.renameChild(name, safeAndUniqueNewName);
} }
@@ -1478,6 +1524,7 @@ const VariablesList = (props: Props) => {
_onChange, _onChange,
props.variablesContainer, props.variablesContainer,
updateExpandedAndSelectedNodesFollowingNameChange, updateExpandedAndSelectedNodesFollowingNameChange,
computeVariableNamesToVariablesUuid,
refocusNameField, refocusNameField,
] ]
); );
@@ -1709,13 +1756,17 @@ const VariablesList = (props: Props) => {
? renderTree(i18n, true) ? renderTree(i18n, true)
: null} : null}
{renderTree(i18n)} {renderTree(i18n)}
{!!undefinedVariableNames.length && ( {!!undeclaredVariableNames.length && (
<Paper background="dark" variant="outlined"> <Paper
background="dark"
variant="outlined"
style={styles.undeclaredVariablePaper}
>
<Column> <Column>
<Text> <Text>
<MarkdownText <MarkdownText
translatableSource={t`There are variables used in events but not declared in this list: ${'`' + translatableSource={t`There are variables used in events but not declared in this list: ${'`' +
undefinedVariableNames.join('`, `') + undeclaredVariableNames.join('`, `') +
'`'}.`} '`'}.`}
/> />
</Text> </Text>