From 96b18bc38b1eb1905c40e1474048b3a941e2f5dc Mon Sep 17 00:00:00 2001 From: wuxinyi Date: Tue, 20 May 2025 18:30:16 +0800 Subject: [PATCH 1/2] feat(stage): add collisionByShape property and related methods --- spx-gui/src/models/project/index.ts | 1 + spx-gui/src/models/stage.ts | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/spx-gui/src/models/project/index.ts b/spx-gui/src/models/project/index.ts index a3ed6ee7e..302eb25bf 100644 --- a/spx-gui/src/models/project/index.ts +++ b/spx-gui/src/models/project/index.ts @@ -391,6 +391,7 @@ export class Project extends Disposable { exportGameFiles(): Files { const files: Files = {} const [stageConfig, stageFiles] = this.stage.export() + console.log("collisionByShape--->",stageConfig.collisionByShape) const { widgets, ...restStageConfig } = stageConfig const zorderNames = this.zorder.map((id) => { const sprite = this.sprites.find((s) => s.id === id) diff --git a/spx-gui/src/models/stage.ts b/spx-gui/src/models/stage.ts index 344deccf3..dd18ebb3f 100644 --- a/spx-gui/src/models/stage.ts +++ b/spx-gui/src/models/stage.ts @@ -17,6 +17,7 @@ export type StageInits = { mapWidth?: number mapHeight?: number mapMode?: MapMode + collisionByShape?: boolean } export type RawMapConfig = { @@ -30,6 +31,7 @@ export type RawStageConfig = { backdropIndex?: number widgets?: RawWidgetConfig[] map?: RawMapConfig + collisionByShape?: boolean // For compatibility scenes?: RawBackdropConfig[] sceneIndex?: number @@ -53,6 +55,11 @@ export class Stage extends Disposable { setCode(code: string) { this.code = code } + + collisionByShape: boolean = false + setCollisionByShape(value: boolean) { + this.collisionByShape = value + } codeFilePath = stageCodeFilePath backdrops: Backdrop[] @@ -217,6 +224,7 @@ export class Stage extends Disposable { this.mapWidth = inits?.mapWidth ?? defaultMapSize.width this.mapHeight = inits?.mapHeight ?? defaultMapSize.height this.mapMode = inits?.mapMode ?? MapMode.fillRatio + this.collisionByShape = inits?.collisionByShape ?? false return reactive(this) as this } @@ -229,7 +237,8 @@ export class Stage extends Disposable { sceneIndex, costumes: costumeConfigs, currentCostumeIndex, - map + map, + collisionByShape }: RawStageConfig, files: Files ) { @@ -240,8 +249,10 @@ export class Stage extends Disposable { backdropIndex: backdropIndex ?? sceneIndex ?? currentCostumeIndex, mapWidth: map?.width, mapHeight: map?.height, - mapMode: getMapMode(map?.mode) + mapMode: getMapMode(map?.mode), + collisionByShape: collisionByShape }) + console.log('collisionByShape', stage.collisionByShape) const backdrops = (backdropConfigs ?? sceneConfigs ?? costumeConfigs ?? []).map((c) => Backdrop.load(c, files)) for (const backdrop of backdrops) { stage.addBackdrop(backdrop) @@ -262,7 +273,7 @@ export class Stage extends Disposable { backdropConfigs.push(backdropConfig) Object.assign(files, backdropFiles) } - const { backdropIndex, mapWidth, mapHeight, mapMode } = this + const { backdropIndex, mapWidth, mapHeight, mapMode, collisionByShape } = this const widgetsConfig: RawWidgetConfig[] = this.widgetsZorder.map((id) => { const widget = this.widgets.find((w) => w.id === id) if (widget == null) throw new Error(`widget ${id} not found`) @@ -272,7 +283,8 @@ export class Stage extends Disposable { backdrops: backdropConfigs, backdropIndex: backdropIndex, widgets: widgetsConfig, - map: { width: mapWidth, height: mapHeight, mode: mapMode } + map: { width: mapWidth, height: mapHeight, mode: mapMode }, + collisionByShape: collisionByShape } return [config, files] } From afb38dbe963da35407ad52d9f907f6045ee8557e Mon Sep 17 00:00:00 2001 From: wuxinyi Date: Tue, 20 May 2025 18:31:57 +0800 Subject: [PATCH 2/2] refactor(stage): remove debug console logs for collisionByShape --- spx-gui/src/models/project/index.ts | 1 - spx-gui/src/models/stage.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/spx-gui/src/models/project/index.ts b/spx-gui/src/models/project/index.ts index 302eb25bf..a3ed6ee7e 100644 --- a/spx-gui/src/models/project/index.ts +++ b/spx-gui/src/models/project/index.ts @@ -391,7 +391,6 @@ export class Project extends Disposable { exportGameFiles(): Files { const files: Files = {} const [stageConfig, stageFiles] = this.stage.export() - console.log("collisionByShape--->",stageConfig.collisionByShape) const { widgets, ...restStageConfig } = stageConfig const zorderNames = this.zorder.map((id) => { const sprite = this.sprites.find((s) => s.id === id) diff --git a/spx-gui/src/models/stage.ts b/spx-gui/src/models/stage.ts index dd18ebb3f..b20b37e78 100644 --- a/spx-gui/src/models/stage.ts +++ b/spx-gui/src/models/stage.ts @@ -252,7 +252,6 @@ export class Stage extends Disposable { mapMode: getMapMode(map?.mode), collisionByShape: collisionByShape }) - console.log('collisionByShape', stage.collisionByShape) const backdrops = (backdropConfigs ?? sceneConfigs ?? costumeConfigs ?? []).map((c) => Backdrop.load(c, files)) for (const backdrop of backdrops) { stage.addBackdrop(backdrop)