Skip to content

Commit

Permalink
Add ability to restore scene's default palettes in "Set Background Pa…
Browse files Browse the repository at this point in the history
…lettes"
  • Loading branch information
chrismaltby committed Apr 23, 2024
1 parent 802ae2e commit 8732241
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add ability to provide color PNGs for backgrounds and extract palettes automatically by either clicking "Auto Color" button in brush toolbar or using dropdown on Scene sidebar next to "Background Palettes" label
- Add ability to override tile data for auto colored backgrounds by providing a matching *.mono.png in your assets/backgrounds folder containing a monochrome version of the background. When provided this file will be used for tiles data and the regular image will be used to extract the color palettes (useful for mixed color mode games when auto palettes isn't creating tile data as you'd like automatically)
- Add ability to edit waveforms in music editor using keyboard with ability to copy/paste [@pau-tomas](https://github.com/pau-tomas)
- Add ability to restore scene's default palettes in "Set Background Palettes" (especially useful when using auto palettes)

### Changed

Expand Down
18 changes: 18 additions & 0 deletions src/components/forms/PaletteSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
SingleValueWithPreview,
SelectCommonProps,
} from "ui/form/Select";
import l10n from "shared/lib/lang/l10n";

interface PaletteSelectProps extends SelectCommonProps {
name: string;
Expand All @@ -23,6 +24,7 @@ interface PaletteSelectProps extends SelectCommonProps {
optionalLabel?: string;
optionalDefaultPaletteId?: string;
canKeep?: boolean;
canRestore?: boolean;
keepLabel?: string;
}

Expand All @@ -46,6 +48,7 @@ export const PaletteSelect: FC<PaletteSelectProps> = ({
optionalLabel,
optionalDefaultPaletteId,
canKeep,
canRestore,
keepLabel,
...selectProps
}) => {
Expand All @@ -65,6 +68,14 @@ export const PaletteSelect: FC<PaletteSelectProps> = ({
},
] as PaletteOption[])
: [],
canRestore
? ([
{
value: "restore",
label: l10n("FIELD_RESTORE_DEFAULT"),
},
] as PaletteOption[])
: [],
optional
? ([
{
Expand All @@ -91,6 +102,7 @@ export const PaletteSelect: FC<PaletteSelectProps> = ({
}, [
palettes,
canKeep,
canRestore,
keepLabel,
optional,
optionalDefaultPaletteId,
Expand All @@ -111,6 +123,11 @@ export const PaletteSelect: FC<PaletteSelectProps> = ({
value: "keep",
label: keepLabel || "Keep",
});
} else if (canRestore && value === "restore") {
setCurrentValue({
value: "restore",
label: l10n("FIELD_RESTORE_DEFAULT"),
});
} else if (currentPalette) {
setCurrentValue({
value: currentPalette.id,
Expand Down Expand Up @@ -141,6 +158,7 @@ export const PaletteSelect: FC<PaletteSelectProps> = ({
canKeep,
keepLabel,
value,
canRestore,
]);

const onSelectChange = (newValue: Option) => {
Expand Down
1 change: 1 addition & 0 deletions src/components/script/ScriptEventFormInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ const ScriptEventFormInput = ({
defaultBackgroundPaletteIds[field.paletteIndex || 0] || ""
}
canKeep={field.canKeep}
canRestore={field.canRestore}
keepLabel={l10n("FIELD_DONT_MODIFY")}
type="tile"
/>
Expand Down
16 changes: 14 additions & 2 deletions src/lib/compiler/scriptBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5353,7 +5353,7 @@ extern void __mute_mask_${symbol};
// Palettes

paletteSetBackground = (paletteIds: string[]) => {
const { palettes, settings } = this.options;
const { palettes, settings, scene } = this.options;

let mask = 0;
const writePalettes: Palette[] = [];
Expand All @@ -5363,8 +5363,20 @@ extern void __mute_mask_${symbol};
if (paletteId === "keep") {
continue;
}
let palette = getPalette(palettes, paletteId, defaultPaletteId);
if (paletteId === "restore") {
if (scene.background.autoPalettes) {
// Restore from auto palette
palette = scene.background.autoPalettes[i] ?? palette;
} else {
// Restore from manual palette
const scenePaletteId =
scene.paletteIds[i] ?? settings.defaultBackgroundPaletteIds[i];
palette = getPalette(palettes, scenePaletteId, defaultPaletteId);
}
}
mask += 1 << i;
writePalettes.push(getPalette(palettes, paletteId, defaultPaletteId));
writePalettes.push(palette);
}

if (mask === 0) {
Expand Down
8 changes: 8 additions & 0 deletions src/lib/events/eventPaletteSetBackground.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const fields = [
paletteType: "background",
paletteIndex: 0,
canKeep: true,
canRestore: true,
},
{
key: "palette1",
Expand All @@ -21,6 +22,7 @@ const fields = [
paletteType: "background",
paletteIndex: 1,
canKeep: true,
canRestore: true,
},
{
key: "palette2",
Expand All @@ -29,6 +31,7 @@ const fields = [
paletteType: "background",
paletteIndex: 2,
canKeep: true,
canRestore: true,
},
{
key: "palette3",
Expand All @@ -37,6 +40,7 @@ const fields = [
paletteType: "background",
paletteIndex: 3,
canKeep: true,
canRestore: true,
},
{
key: "palette4",
Expand All @@ -45,6 +49,7 @@ const fields = [
paletteType: "background",
paletteIndex: 4,
canKeep: true,
canRestore: true,
},
{
key: "palette5",
Expand All @@ -53,6 +58,7 @@ const fields = [
paletteType: "background",
paletteIndex: 5,
canKeep: true,
canRestore: true,
},
{
key: "palette6",
Expand All @@ -61,6 +67,7 @@ const fields = [
paletteType: "background",
paletteIndex: 6,
canKeep: true,
canRestore: true,
},
{
key: "palette7",
Expand All @@ -69,6 +76,7 @@ const fields = [
paletteType: "background",
paletteIndex: 7,
canKeep: true,
canRestore: true,
},
];

Expand Down
1 change: 1 addition & 0 deletions src/shared/lib/entities/entitiesTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ export interface ScriptEventFieldSchema {
paletteType?: "background" | "ui" | "emote" | "sprite";
paletteIndex?: number;
canKeep?: boolean;
canRestore?: boolean;
includePlayer?: boolean;
defaultType?: string;
types?: string[];
Expand Down

0 comments on commit 8732241

Please sign in to comment.