Skip to content

Commit c79b54b

Browse files
authored
Merge pull request #281 from NicDoesCode/v1.4-bugfixes
V1.4 bugfixes
2 parents 033e358 + a2ef3a3 commit c79b54b

File tree

4 files changed

+48
-21
lines changed

4 files changed

+48
-21
lines changed

wwwroot/modules/main.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import { DropPosition } from "./types.js";
7272
import TileMapUtil from "./util/tileMapUtil.js";
7373
import PaintUtil from "./util/paintUtil.js";
7474
import PaletteUtil from "./util/paletteUtil.js";
75+
import TileMapList from "./models/tileMapList.js";
7576

7677

7778
/* ****************************************************************************************************
@@ -1744,6 +1745,8 @@ function handleImportPaletteModalDialogueOnConfirm(args) {
17441745
getUIState().importPaletteAssemblyCode = args.paletteData;
17451746
state.saveToLocalStorage();
17461747

1748+
currentProject.nativePalettes = null;
1749+
17471750
paletteEditor.setState({
17481751
paletteList: getRenderPaletteList(),
17491752
selectedPaletteIndex: getProjectUIState().paletteIndex
@@ -1828,6 +1831,8 @@ function paletteSetColourAtIndexWithoutSaving(paletteIndex, colourIndex, colour)
18281831
const newColour = PaletteColourFactory.create(colour.r, colour.g, colour.b);
18291832
palette.setColour(colourIndex, newColour);
18301833

1834+
currentProject.nativePalettes = null;
1835+
18311836
paletteEditor.setState({
18321837
paletteList: getRenderPaletteList(),
18331838
displayNative: getUIState().displayNativeColour
@@ -1916,6 +1921,8 @@ function handleImageImportModalOnConfirm(args) {
19161921

19171922
state.saveToLocalStorage();
19181923

1924+
currentProject.nativePalettes = null;
1925+
19191926
paletteEditor.setState({
19201927
paletteList: getRenderPaletteList(),
19211928
selectedPaletteIndex: getRenderPaletteList().length - 1
@@ -2615,13 +2622,6 @@ function formatForNoProject() {
26152622

26162623
currentProject.nativePalettes = null;
26172624

2618-
const dummyProject = createEmptyProject({ systemType: 'smsgg' });
2619-
while (dummyProject.paletteList.length > 1) {
2620-
dummyProject.paletteList.removeAt(0);
2621-
}
2622-
dummyProject.tileMapList.clear();
2623-
dummyProject.tileSet.clear();
2624-
26252625
projectToolbar.setState({
26262626
enabled: false,
26272627
projectTitle: ' ',
@@ -2680,8 +2680,8 @@ function formatForNoProject() {
26802680
enabled: false
26812681
});
26822682
tileManager.setState({
2683-
tileMapList: dummyProject.tileMapList,
2684-
tileSet: dummyProject.tileSet,
2683+
tileMapList: new TileMapList([]),
2684+
tileSet: new TileSet(),
26852685
palette: null,
26862686
paletteList: null,
26872687
selectedTileMapId: null
@@ -3857,6 +3857,8 @@ function paletteReorder(paletteId, targetPaletteId, position) {
38573857

38583858
state.saveToLocalStorage();
38593859

3860+
currentProject.nativePalettes = null;
3861+
38603862
updatePaletteLists({ skipTileEditor: true });
38613863
}
38623864

@@ -3871,6 +3873,8 @@ function paletteNew() {
38713873

38723874
state.saveToLocalStorage();
38733875

3876+
currentProject.nativePalettes = null;
3877+
38743878
updatePaletteLists({ skipTileEditor: true });
38753879

38763880
paletteSelectById(newPalette.paletteId);
@@ -3894,6 +3898,8 @@ function paletteClone(paletteIndex) {
38943898

38953899
state.saveToLocalStorage();
38963900

3901+
currentProject.nativePalettes = null;
3902+
38973903
updatePaletteLists({ skipTileEditor: true });
38983904

38993905
paletteSelectById(newPalette.paletteId);
@@ -3925,6 +3931,8 @@ function paletteDelete(paletteIndex) {
39253931

39263932
state.saveToLocalStorage();
39273933

3934+
currentProject.nativePalettes = null;
3935+
39283936
updatePaletteLists();
39293937

39303938
const palette = getPaletteList().getPalette(paletteIndex);
@@ -3983,6 +3991,8 @@ function paletteListSort(field) {
39833991
getPaletteList().setPalettes(palettes);
39843992
state.saveProjectToLocalStorage();
39853993

3994+
currentProject.nativePalettes = null;
3995+
39863996
// Set the UI state
39873997
updatePaletteLists();
39883998
}
@@ -4022,6 +4032,8 @@ function changePaletteTitle(paletteIndex, newTitle) {
40224032

40234033
state.saveToLocalStorage();
40244034

4035+
currentProject.nativePalettes = null;
4036+
40254037
paletteEditor.setState({
40264038
paletteList: getRenderPaletteList(),
40274039
displayNative: getUIState().displayNativeColour
@@ -4037,6 +4049,8 @@ function changePaletteSystem(paletteIndex, system) {
40374049
const palette = getPaletteList().getPalette(paletteIndex);
40384050
palette.system = system;
40394051

4052+
currentProject.nativePalettes = null;
4053+
40404054
state.saveToLocalStorage();
40414055

40424056
paletteEditor.setState({
@@ -4076,7 +4090,7 @@ function changePaletteEditorDisplayNativeColours(displayNative) {
40764090
}
40774091

40784092
function updateTileEditorGridColours() {
4079-
const isGameboyProject = getUIState().displayNativeColour && getProject().systemType === 'gb';
4093+
const isGameboyProject = getUIState().displayNativeColour && getProject()?.systemType === 'gb';
40804094
tileEditor.setState({
40814095
pixelGridColour: (isGameboyProject) ? '#98a200' : '#000000',
40824096
pixelGridOpacity: (isGameboyProject) ? 0.5 : 0.2,
@@ -4118,6 +4132,8 @@ function swapColourIndex(sourceColourIndex, targetColourIndex) {
41184132

41194133
state.saveToLocalStorage();
41204134

4135+
currentProject.nativePalettes = null;
4136+
41214137
tileEditor.setState({
41224138
paletteList: getRenderPaletteListToSuitTileMapOrTileSetSelection(),
41234139
tileGrid: getTileGrid(),
@@ -5581,7 +5597,7 @@ window.addEventListener('load', async () => {
55815597
});
55825598

55835599
welcomeScreen.setState({
5584-
version: versionInfo,
5600+
version: versionInfo,
55855601
channel: channelInfo
55865602
});
55875603

wwwroot/modules/state.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ export default class State {
294294
const storageId = `${LOCAL_STORAGE_PROJECTS}${project.id}`;
295295
const serialised = ProjectJsonSerialiser.serialise(project);
296296
localStorage.setItem(storageId, serialised);
297+
// Update project in cached list too
298+
this.#projects.set(project.id, project);
299+
// Raise the event
297300
if (raise) {
298301
this.#dispatcher.dispatch(EVENT_OnEvent, createArgs(events.projectSaved, { projectId: project.id }));
299302
this.#dispatcher.dispatch(EVENT_OnEvent, createArgs(events.projectListChanged));
@@ -323,7 +326,7 @@ export default class State {
323326
this.#dispatcher.dispatch(EVENT_OnEvent, createArgs(events.projectListChanged, { context: contexts.deleted, projectId: projectId }));
324327

325328
if (this.project?.id === projectId) {
326-
this.setProject(null, eventSources.none);
329+
this.setProject(null, contexts.deleted);
327330
}
328331
}
329332
addOrRemoveProjectEntriesBasedOnLocalStorage(this.#projectEntries, this);

wwwroot/modules/ui/paletteEditor.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ export default class PaletteEditor extends ComponentBase {
5656
#selectedPaletteId = null;
5757
/** @type {HTMLButtonElement[]} */
5858
#paletteButtons = [];
59+
/** @type {HTMLSelectElement} */
60+
#uiHiddenPaletteSelect;
5961
/** @type {HTMLElement} */
6062
#uiItemProperties;
6163
/** @type {HTMLInputElement} */
@@ -112,12 +114,18 @@ export default class PaletteEditor extends ComponentBase {
112114
});
113115

114116
this.#uiItemProperties = this.#element.querySelector('[data-smsgfx-id=palette-properties]');
117+
this.#uiHiddenPaletteSelect = this.#element.querySelector(`select[data-command=${commands.paletteSelect}]`);
115118

116119
this.#btnPaletteTitle = this.#element.querySelector('[data-smsgfx-id=editPaletteTitle]');
117120
this.#btnPaletteTitle.addEventListener('click', () => this.#handlePaletteTitleEditClick());
118121

119122
this.#uiPaletteTitle = this.#element.querySelector('[data-smsgfx-id=paletteTitle]');
120123
this.#uiPaletteTitle.addEventListener('blur', () => this.#handlePaletteTitleEditBlur());
124+
this.#uiPaletteTitle.addEventListener('keyup', (ev) => {
125+
if (ev.key === 'Enter') {
126+
this.#handlePaletteTitleEditBlur();
127+
}
128+
});
121129

122130
this.#element.querySelectorAll('button[data-command]').forEach(element => {
123131
element.onclick = () => {
@@ -217,9 +225,7 @@ export default class PaletteEditor extends ComponentBase {
217225
const palette = this.#paletteList.getPalette(index);
218226
this.#selectedPaletteId = palette.paletteId;
219227

220-
this.#element.querySelectorAll(`[data-command=${commands.paletteSelect}]`).forEach((element) => {
221-
element.selectedIndex = index;
222-
});
228+
this.#uiHiddenPaletteSelect.selectedIndex = index;
223229

224230
this.#setPalette(palette);
225231
} else {
@@ -313,7 +319,8 @@ export default class PaletteEditor extends ComponentBase {
313319
#createEventArgs(command) {
314320
return {
315321
command: command,
316-
paletteIndex: this.#element.querySelector(`select[data-command=${commands.paletteSelect}]`)?.selectedIndex,
322+
paletteIndex: this.#uiHiddenPaletteSelect?.selectedIndex,
323+
paletteId: this.#uiHiddenPaletteSelect?.options[this.#uiHiddenPaletteSelect?.selectedIndex]?.getAttribute('data-palette-id') ?? null,
317324
paletteTitle: this.#element.querySelector(`input[type=text][data-command=${commands.paletteTitle}]`)?.value ?? null,
318325
paletteSystem: this.#element.querySelector(`select[data-command=${commands.paletteSystem}]`)?.value ?? null,
319326
displayNative: this.#element.querySelector(`[data-command=${commands.displayNativeColours}]`)?.checked ?? null,
@@ -388,9 +395,10 @@ export default class PaletteEditor extends ComponentBase {
388395
* @param {PaletteList?} paletteList - List of palettes, or null.
389396
*/
390397
#refreshPaletteSelectList(paletteList) {
391-
const select = this.#element.querySelector(`select[data-command=${commands.paletteSelect}]`);
398+
const select = this.#uiHiddenPaletteSelect;
392399
if (select) {
393400
const lastSelectedIndex = select.selectedIndex;
401+
const lastSelectedPaletteId = select.options[lastSelectedIndex]?.getAttribute('data-palette-id');
394402
const optionCount = select.options.length;
395403
for (let i = 0; i < optionCount; i++) {
396404
select.options.remove(0);
@@ -402,7 +410,7 @@ export default class PaletteEditor extends ComponentBase {
402410
option.setAttribute('data-palette-id', palettes[i].paletteId);
403411
option.innerText = `#${i} | ${palettes[i].title}`;
404412
option.value = i.toString();
405-
option.selected = lastSelectedIndex === i;
413+
option.selected = lastSelectedPaletteId === palettes[i].paletteId;
406414
select.options.add(option);
407415
}
408416
if (select.selectedIndex === -1) {
@@ -418,7 +426,7 @@ export default class PaletteEditor extends ComponentBase {
418426
*/
419427
#updatePaletteSelectVirtualList() {
420428
const virtualList = this.#element.querySelector(`[data-linked-command=${commands.paletteSelect}]`);
421-
const select = this.#element.querySelector(`select[data-command=${commands.paletteSelect}]`);
429+
const select = this.#uiHiddenPaletteSelect;
422430

423431
if (virtualList && select) {
424432

@@ -645,7 +653,7 @@ export default class PaletteEditor extends ComponentBase {
645653
* @typedef {Object} PaletteEditorCommandEventArgs
646654
* @property {string} command - The command being invoked.
647655
* @property {number?} paletteIndex - Index of the selected palette.
648-
* @property {number?} paletteId - Unique ID of the selected palette.
656+
* @property {string?} paletteId - Unique ID of the selected palette.
649657
* @property {string?} paletteTitle - Title value for the selected palette.
650658
* @property {string?} paletteSystem - Selected system value for the selected palette, either 'ms', 'gg', 'gb' or 'nes'.
651659
* @property {number?} colourIndex - Index from 0 to 15 for the given colour.

wwwroot/modules/ui/tileManager.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<input data-command="tileMapChange" data-auto-event="change" data-field="title" type="text"
6161
class="form-control visually-hidden mt-2 flex-fill" aria-label="Enter name"
6262
title="Change the title of the tile map.">
63-
<button data-smsgfx-id="editTileMapMenu" class="btn btn-secondary m-0 p-0"
63+
<button data-smsgfx-id="editTileMapMenu" class="btn btn-outline-secondary text-secondary-emphasis border-0 m-0 p-0"
6464
data-bs-toggle="dropdown" aria-expanded="false">
6565
<span class="p-2"><i class="bi bi-three-dots"></i></span>
6666
</button>

0 commit comments

Comments
 (0)