Skip to content

Commit b691815

Browse files
authored
Save the gameplay test frame position between runs (#9011)
1 parent 533677b commit b691815

3 files changed

Lines changed: 50 additions & 10 deletions

File tree

newIDE/app/src/GameplayTests/GameplayTestFrame.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
isGameplayTestStatusInProgress,
1717
type GameplayTestDisplayStatus,
1818
} from './GameplayTestStatusIndicator';
19+
import PreferencesContext from '../MainFrame/Preferences/PreferencesContext';
1920
import classes from './GameplayTestFrame.module.css';
2021

2122
/** The status of the run displayed on the gameplay test frame. */
@@ -86,10 +87,18 @@ export const GameplayTestFrameLayout = ({
8687
children,
8788
}: GameplayTestFrameLayoutProps): React.Node => {
8889
const containerRef = React.useRef<HTMLDivElement | null>(null);
89-
const [position, setPosition] = React.useState<Position>({
90-
left: windowMargin,
91-
bottom: windowMargin,
92-
});
90+
const { values, setGameplayTestFramePosition } = React.useContext(
91+
PreferencesContext
92+
);
93+
// Restore the last position of the frame (it will be clamped to the window
94+
// as soon as it is rendered, in case the window is now smaller).
95+
const [position, setPosition] = React.useState<Position>(
96+
() =>
97+
values.gameplayTestFramePosition || {
98+
left: windowMargin,
99+
bottom: windowMargin,
100+
}
101+
);
93102
const [isDragging, setIsDragging] = React.useState<boolean>(false);
94103
const dragOrigin = React.useRef<{|
95104
pointerId: number,
@@ -153,13 +162,17 @@ export const GameplayTestFrameLayout = ({
153162
);
154163
}, []);
155164

156-
const onPointerUp = React.useCallback((event: PointerEvent) => {
157-
const origin = dragOrigin.current;
158-
if (!origin || origin.pointerId !== event.pointerId) return;
165+
const onPointerUp = React.useCallback(
166+
(event: PointerEvent) => {
167+
const origin = dragOrigin.current;
168+
if (!origin || origin.pointerId !== event.pointerId) return;
159169

160-
dragOrigin.current = null;
161-
setIsDragging(false);
162-
}, []);
170+
dragOrigin.current = null;
171+
setIsDragging(false);
172+
setGameplayTestFramePosition(position);
173+
},
174+
[position, setGameplayTestFramePosition]
175+
);
163176

164177
const isInProgress = runStatus
165178
? isGameplayTestStatusInProgress(runStatus.status)

newIDE/app/src/MainFrame/Preferences/PreferencesContext.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ export type PreferencesValues = {|
249249
previewCrashReportUploadLevel: string,
250250
gamesDashboardOrderBy: GamesDashboardOrderBy,
251251
takeScreenshotOnPreview: boolean,
252+
gameplayTestFramePosition: {| left: number, bottom: number |} | null,
252253
showAiAskButtonInTitleBar: boolean,
253254
automaticallyUseCreditsForAiRequests: boolean,
254255
automaticallyApplyAiRequestEditsByProjectId: { [string]: boolean },
@@ -375,6 +376,10 @@ export type Preferences = {|
375376
orderBy: 'lastModifiedAt' | 'totalSessions' | 'weeklySessions'
376377
) => void,
377378
setTakeScreenshotOnPreview: (enabled: boolean) => void,
379+
setGameplayTestFramePosition: (position: {|
380+
left: number,
381+
bottom: number,
382+
|}) => void,
378383
setShowAiAskButtonInTitleBar: (enabled: boolean) => void,
379384
setAutomaticallyUseCreditsForAiRequests: (enabled: boolean) => void,
380385
setAutomaticallyApplyAiRequestEditsForProjectId: (
@@ -444,6 +449,7 @@ export const initialPreferences = {
444449
previewCrashReportUploadLevel: 'exclude-javascript-code-events',
445450
gamesDashboardOrderBy: 'lastModifiedAt',
446451
takeScreenshotOnPreview: true,
452+
gameplayTestFramePosition: null,
447453
showAiAskButtonInTitleBar: true,
448454
automaticallyUseCreditsForAiRequests: false,
449455
automaticallyApplyAiRequestEditsByProjectId: {},
@@ -533,6 +539,10 @@ export const initialPreferences = {
533539
orderBy: 'lastModifiedAt' | 'totalSessions' | 'weeklySessions'
534540
) => {},
535541
setTakeScreenshotOnPreview: (enabled: boolean) => {},
542+
setGameplayTestFramePosition: (position: {|
543+
left: number,
544+
bottom: number,
545+
|}) => {},
536546
setShowAiAskButtonInTitleBar: (enabled: boolean) => {},
537547
setAutomaticallyUseCreditsForAiRequests: (enabled: boolean) => {},
538548
setAutomaticallyApplyAiRequestEditsForProjectId: (

newIDE/app/src/MainFrame/Preferences/PreferencesProvider.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export const getInitialPreferences = (): {
134134
showExperimentalExtensions: boolean,
135135
showInAppTutorialDeveloperMode: boolean,
136136
takeScreenshotOnPreview: boolean,
137+
gameplayTestFramePosition: {| left: number, bottom: number |} | null,
137138
themeName: any,
138139
use3DEditor: any,
139140
useBackgroundSerializerForSaving: boolean,
@@ -396,6 +397,10 @@ export default class PreferencesProvider extends React.Component<Props, State> {
396397
this
397398
): any),
398399
// $FlowFixMe[method-unbinding]
400+
setGameplayTestFramePosition: (this._setGameplayTestFramePosition.bind(
401+
this
402+
): any),
403+
// $FlowFixMe[method-unbinding]
399404
setShowAiAskButtonInTitleBar: (this._setShowAiAskButtonInTitleBar.bind(
400405
this
401406
): any),
@@ -1408,6 +1413,18 @@ export default class PreferencesProvider extends React.Component<Props, State> {
14081413
);
14091414
}
14101415

1416+
_setGameplayTestFramePosition(newValue: {| left: number, bottom: number |}) {
1417+
this.setState(
1418+
state => ({
1419+
values: {
1420+
...state.values,
1421+
gameplayTestFramePosition: newValue,
1422+
},
1423+
}),
1424+
() => this._persistValuesToLocalStorage(this.state)
1425+
);
1426+
}
1427+
14111428
_setShowAiAskButtonInTitleBar(newValue: boolean) {
14121429
this.setState(
14131430
state => ({

0 commit comments

Comments
 (0)