Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions spx-gui/src/models/stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type StageInits = {
mapWidth?: number
mapHeight?: number
mapMode?: MapMode
collisionByShape?: boolean
}

export type RawMapConfig = {
Expand All @@ -30,6 +31,7 @@ export type RawStageConfig = {
backdropIndex?: number
widgets?: RawWidgetConfig[]
map?: RawMapConfig
collisionByShape?: boolean
// For compatibility
scenes?: RawBackdropConfig[]
sceneIndex?: number
Expand All @@ -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[]
Expand Down Expand Up @@ -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
}

Expand All @@ -229,7 +237,8 @@ export class Stage extends Disposable {
sceneIndex,
costumes: costumeConfigs,
currentCostumeIndex,
map
map,
collisionByShape
}: RawStageConfig,
files: Files
) {
Expand All @@ -240,7 +249,8 @@ 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
})
const backdrops = (backdropConfigs ?? sceneConfigs ?? costumeConfigs ?? []).map((c) => Backdrop.load(c, files))
for (const backdrop of backdrops) {
Expand All @@ -262,7 +272,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`)
Expand All @@ -272,7 +282,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]
}
Expand Down
Loading