Skip to content

Commit 0aea8df

Browse files
committed
WIP: refactoring and prepare for handling external layout in-game edition
1 parent 81ca180 commit 0aea8df

File tree

7 files changed

+56
-17
lines changed

7 files changed

+56
-17
lines changed

GDJS/Runtime/debugger-client/abstract-debugger-client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ namespace gdjs {
283283
}
284284

285285
runtimeGame.getSceneStack().replace(sceneName, true);
286+
// TODO: handle external layouts.
287+
286288
// TODO: if fatal error, should probably reload. The editor should handle this
287289
// as it knows the current scene to show.
288290
} else if (data.command === 'updateInstances') {

newIDE/app/src/EmbeddedGame/EmbeddedGameFrame.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type AttachToPreviewOptions = {|
88

99
type SwitchToSceneEditionOptions = {|
1010
sceneName: string,
11+
externalLayoutName?: string,
1112
|};
1213

1314
let onAttachToPreview: null | (AttachToPreviewOptions => void) = null;
@@ -22,15 +23,19 @@ export const attachToPreview = ({
2223

2324
export const switchToSceneEdition = ({
2425
sceneName,
26+
externalLayoutName,
2527
}: SwitchToSceneEditionOptions) => {
2628
if (!onSwitchToSceneEdition)
2729
throw new Error('No EmbeddedGameFrame registered.');
28-
onSwitchToSceneEdition({ sceneName });
30+
onSwitchToSceneEdition({ sceneName, externalLayoutName });
2931
};
3032

3133
type Props = {|
3234
previewDebuggerServer: PreviewDebuggerServer | null,
33-
onLaunchPreviewForInGameEdition: ({| sceneName: string |}) => void,
35+
onLaunchPreviewForInGameEdition: ({|
36+
sceneName: string,
37+
externalLayoutName: ?string,
38+
|}) => void,
3439
|};
3540

3641
export const EmbeddedGameFrame = ({
@@ -55,12 +60,13 @@ export const EmbeddedGameFrame = ({
5560
onSwitchToSceneEdition = (options: SwitchToSceneEditionOptions) => {
5661
if (!previewDebuggerServer) return;
5762

58-
const { sceneName } = options;
63+
const { sceneName, externalLayoutName } = options;
5964

6065
if (!previewIndexHtmlLocation) {
6166
console.info('Launching preview for embedded game.');
62-
onLaunchPreviewForInGameEdition({ sceneName });
67+
onLaunchPreviewForInGameEdition({ sceneName, externalLayoutName });
6368
} else {
69+
// TODO: handle external layouts (and custom objects later).
6470
console.info(`Switching previews to scene "${sceneName}".`);
6571
previewDebuggerServer.getExistingDebuggerIds().forEach(debuggerId => {
6672
previewDebuggerServer.sendMessage(debuggerId, {

newIDE/app/src/ExportAndShare/PreviewLauncher.flow.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export type LaunchPreviewOptions = {
1515
fullLoadingScreen?: boolean,
1616
forceDiagnosticReport?: boolean,
1717
numberOfWindows?: number,
18-
isForInGameEdition?: { forcedSceneName: string },
18+
isForInGameEdition?: {|
19+
forcedSceneName: string,
20+
forcedExternalLayoutName: ?string,
21+
|},
1922
launchCaptureOptions?: LaunchCaptureOptions,
2023
};
2124
export type CaptureOptions = {|

newIDE/app/src/MainFrame/EditorContainers/ExternalLayoutEditorContainer.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ import {
2727
} from '../ResourcesWatcher';
2828
import { ProjectScopedContainersAccessor } from '../../InstructionOrExpression/EventsScope';
2929
import { type ObjectWithContext } from '../../ObjectsList/EnumerateObjects';
30+
import { switchToSceneEdition } from '../../EmbeddedGame/EmbeddedGameFrame';
31+
32+
const gameEditorMode = 'embedded-game'; // TODO: move to a preference.
3033

3134
const styles = {
3235
container: {
@@ -69,6 +72,13 @@ export class ExternalLayoutEditorContainer extends React.Component<
6972
layout ? layout.getName() : null,
7073
projectItemName
7174
);
75+
76+
if (gameEditorMode === 'embedded-game' && layout && projectItemName) {
77+
switchToSceneEdition({
78+
sceneName: layout.getName(),
79+
externalLayoutName: projectItemName,
80+
});
81+
}
7282
}
7383
this.resourceExternallyChangedCallbackId = registerOnResourceExternallyChangedCallback(
7484
this.onResourceExternallyChanged.bind(this)
@@ -88,6 +98,13 @@ export class ExternalLayoutEditorContainer extends React.Component<
8898
layout ? layout.getName() : null,
8999
projectItemName
90100
);
101+
102+
if (gameEditorMode === 'embedded-game' && layout && projectItemName) {
103+
switchToSceneEdition({
104+
sceneName: layout.getName(),
105+
externalLayoutName: projectItemName,
106+
});
107+
}
91108
}
92109
}
93110

newIDE/app/src/MainFrame/EditorContainers/SceneEditorContainer.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import {
1212
} from './BaseEditor';
1313
import { ProjectScopedContainersAccessor } from '../../InstructionOrExpression/EventsScope';
1414
import { type ObjectWithContext } from '../../ObjectsList/EnumerateObjects';
15+
import { switchToSceneEdition } from '../../EmbeddedGame/EmbeddedGameFrame';
16+
17+
const gameEditorMode = 'embedded-game'; // TODO: move to a preference.
1518

1619
export class SceneEditorContainer extends React.Component<RenderEditorContainerProps> {
1720
editor: ?SceneEditor;
@@ -32,13 +35,21 @@ export class SceneEditorContainer extends React.Component<RenderEditorContainerP
3235
if (this.props.isActive) {
3336
const { projectItemName } = this.props;
3437
this.props.setPreviewedLayout(projectItemName);
38+
39+
if (gameEditorMode === 'embedded-game' && projectItemName) {
40+
switchToSceneEdition({ sceneName: projectItemName });
41+
}
3542
}
3643
}
3744

3845
componentDidUpdate(prevProps: RenderEditorContainerProps) {
3946
if (!prevProps.isActive && this.props.isActive) {
4047
const { projectItemName } = this.props;
4148
this.props.setPreviewedLayout(projectItemName);
49+
50+
if (gameEditorMode === 'embedded-game' && projectItemName) {
51+
switchToSceneEdition({ sceneName: projectItemName });
52+
}
4253
}
4354
}
4455

newIDE/app/src/MainFrame/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,7 @@ const MainFrame = (props: Props) => {
16331633
? previewState.overridenPreviewLayoutName
16341634
: previewState.previewLayoutName;
16351635
const externalLayoutName = isForInGameEdition
1636-
? null
1636+
? isForInGameEdition.forcedExternalLayoutName
16371637
: previewState.isPreviewOverriden
16381638
? previewState.overridenPreviewExternalLayoutName
16391639
: previewState.previewExternalLayoutName;
@@ -1676,6 +1676,7 @@ const MainFrame = (props: Props) => {
16761676
const startTime = Date.now();
16771677
await previewLauncher.launchPreview({
16781678
project: currentProject,
1679+
// TODO: replace by scene name and external layout name
16791680
layout,
16801681
externalLayout,
16811682
networkPreview: !!networkPreview,
@@ -1789,13 +1790,20 @@ const MainFrame = (props: Props) => {
17891790
);
17901791

17911792
const onLaunchPreviewForInGameEdition = React.useCallback(
1792-
({ sceneName }: {| sceneName: string |}) => {
1793+
({
1794+
sceneName,
1795+
externalLayoutName,
1796+
}: {|
1797+
sceneName: string,
1798+
externalLayoutName: ?string,
1799+
|}) => {
17931800
launchPreview({
17941801
networkPreview: false,
17951802
hotReload: false,
17961803
forceDiagnosticReport: false,
17971804
isForInGameEdition: {
17981805
forcedSceneName: sceneName,
1806+
forcedExternalLayoutName: externalLayoutName,
17991807
},
18001808
numberOfWindows: 0,
18011809
});
@@ -1821,6 +1829,8 @@ const MainFrame = (props: Props) => {
18211829
isForInGameEdition: {
18221830
forcedSceneName:
18231831
runningInGameEditionPreviewStatus.currentSceneName || '',
1832+
// TODO: add support for forced external layout name.
1833+
forcedExternalLayoutName: null,
18241834
},
18251835
numberOfWindows: 0,
18261836
});

newIDE/app/src/SceneEditor/index.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ import { unserializeFromJSObject } from '../Utils/Serializer';
8080
import { ProjectScopedContainersAccessor } from '../InstructionOrExpression/EventsScope';
8181
import { type TileMapTileSelection } from '../InstancesEditor/TileSetVisualizer';
8282
import { extractAsCustomObject } from './CustomObjectExtractor/CustomObjectExtractor';
83-
import { switchToSceneEdition } from '../EmbeddedGame/EmbeddedGameFrame';
8483

8584
const gd: libGDevelop = global.gd;
8685

@@ -249,11 +248,6 @@ export default class SceneEditor extends React.Component<Props, State> {
249248
this.resourceExternallyChangedCallbackId = registerOnResourceExternallyChangedCallback(
250249
this.onResourceExternallyChanged.bind(this)
251250
);
252-
if (this.props.isActive) {
253-
if (this.props.layout && this.state.gameEditorMode === 'embedded-game') {
254-
switchToSceneEdition({ sceneName: this.props.layout.getName() });
255-
}
256-
}
257251
}
258252
componentWillUnmount() {
259253
unregisterOnResourceExternallyChangedCallback(
@@ -403,10 +397,6 @@ export default class SceneEditor extends React.Component<Props, State> {
403397
selectedObjectFolderOrObjectsWithContext
404398
),
405399
}));
406-
407-
if (this.props.layout && this.state.gameEditorMode === 'embedded-game') {
408-
switchToSceneEdition({ sceneName: this.props.layout.getName() });
409-
}
410400
}
411401
}
412402

0 commit comments

Comments
 (0)