Skip to content

Commit

Permalink
Room deletion feature fully implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
ufeike committed Jun 20, 2023
1 parent 513f117 commit bbe9095
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
26 changes: 20 additions & 6 deletions public/class/CharacterEditor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class CharacterEditor extends EventEmitter {
advancedWindow;

_chardata = {};
_roomdata = {};
_editMode = false;

name = {
Expand Down Expand Up @@ -404,11 +405,24 @@ export class CharacterEditor extends EventEmitter {
}

onDelete() {
if(confirm("Delete the character?")) {
this.emit(CharacterEditor.EVENT_DELETE, {
target: this.chardata.filename
});
if(!getIsRoom())
{
if(confirm("Delete the character?")) {
this.emit(CharacterEditor.EVENT_DELETE, {
target: this.chardata.filename
});
}
}
else
{
if(confirm("Delete the room?")) {
let roomFilename = getRoomsInstance().selectedRoom;
getRoomsInstance().editor.emit(RoomEditor.EVENT_DELETE, {
target: roomFilename
});
}
}

}

get editMode() {
Expand Down Expand Up @@ -442,7 +456,7 @@ export class CharacterEditor extends EventEmitter {
this.name.help.innerHTML = "Room name";
this.other.roomCharacterSelect.style.display = null;
this.other.roomScenarioInput.parentElement.style.display = null;
this.button.delete.style.display = "none";
// this.button.delete.style.display = "none";
this.button.export.style.display = "none";
this.button.online.style.display = "none";
} else {
Expand All @@ -457,7 +471,7 @@ export class CharacterEditor extends EventEmitter {
this.name.help.innerHTML = "Character name";
this.other.roomCharacterSelect.style.display = "none";
this.other.roomScenarioInput.parentElement.style.display = "none";
this.button.delete.style.display = null;
// this.button.delete.style.display = null;
this.button.export.style.display = null;
this.button.online.style.display = null;
}
Expand Down
3 changes: 2 additions & 1 deletion public/class/RoomEditor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import {CharacterEditor} from "./CharacterEditor.mjs";

export class RoomEditor extends EventEmitter {
static EVENT_CREATE = "roomedit_create";
static EVENT_SHOWN = "roomedit_shown";
static EVENT_SAVE = "roomedit_save";
static EVENT_DELETE = "roomedit_delete";
static EVENT_SHOWN = "roomedit_shown";

characters;

Expand Down
15 changes: 14 additions & 1 deletion public/class/RoomModel.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {Resizable} from "./Resizable.mjs";
export class RoomModel extends EventEmitter {
static EVENT_ROOM_SELECT = "room_select";
static EVENT_ROOM_UPDATED = "room_updated";
static EVENT_ROOM_DELETED = "room_m_deleted";

selectedIDs = []; // IDs of character
selectedNames = []; // Names of character
Expand All @@ -29,8 +30,9 @@ export class RoomModel extends EventEmitter {
characters: this.characters
});
this.editor.on(RoomEditor.EVENT_CREATE, this.onRoomCreate.bind(this));
this.editor.on(RoomEditor.EVENT_SHOWN, this.onRoomShown.bind(this));
this.editor.on(RoomEditor.EVENT_SAVE, this.onRoomSave.bind(this));
this.editor.on(RoomEditor.EVENT_DELETE, this.onRoomDelete.bind(this));
this.editor.on(RoomEditor.EVENT_SHOWN, this.onRoomShown.bind(this));

this.view = new RoomView({
parent: this
Expand Down Expand Up @@ -83,6 +85,16 @@ export class RoomModel extends EventEmitter {
return id;
}

/**
* Get the selected room metadata, which includes the filename (no extension) and the first line inside a room file.
*/
get selectedRoomMetadata() {
let selectedRoomObject = this.rooms[this.selectedRoomId].chat[0];
// selectedRoomObject.filename = this.rooms[this.selectedRoomId].filename;
selectedRoomObject.filename = this.selectedRoom;
return selectedRoomObject;
}

// Get the index of the character about to speak next, note that this index is NOT the character's ID
get activeCharacterIndex() {
return this.selectedIDs.indexOf(this.activeId);
Expand Down Expand Up @@ -329,6 +341,7 @@ export class RoomModel extends EventEmitter {
// this.emit(RoomModel.EVENT_ROOM_SELECT, {});
this.clearSelected();
this.characters.emit(CharacterModel.EVENT_WIPE_CHAT, {});
this.emit(RoomModel.EVENT_ROOM_DELETED, { filename: event.target })
document.getElementById("chat_header_back_button").click();
}.bind(this)
});
Expand Down
11 changes: 9 additions & 2 deletions public/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,19 @@ $(document).ready(function(){
let filename = event.currentTarget.parentNode.parentNode.getAttribute("filename");
if(!confirm("Delete room \""+filename+"\"?")) { return; }
Rooms.deleteRoom(filename);
event.currentTarget.parentNode.parentNode.remove(); // Remove the HTML node inside the list
setRoomMode(false); // Since removing a room redirects to the default Chloe message, which is a character not a room. Also handles the bug that prevents accessing a character after deleting a room.
// event.currentTarget.parentNode.parentNode.remove(); // Remove the HTML node inside the list
// setRoomMode(false); // Since removing a room redirects to the default Chloe message, which is a character not a room. Also handles the bug that prevents accessing a character after deleting a room.
});

}.bind(this));

// Below is needed currently since the room view class (RoomView) is not implemented yet
Rooms.on(RoomModel.EVENT_ROOM_DELETED, function(event) {
let filename = event.filename; // Remove the HTML node inside the list
$("#rm_print_rooms_block li[filename='"+filename+"']").remove();
setRoomMode(false); // Since removing a room redirects to the default Chloe message, which is a character not a room. Also handles the bug that prevents accessing a character after deleting a room.
});

// Below segment would never be called, since advanced room updating is not implemented
Rooms.on(RoomModel.EVENT_ROOM_UPDATED, function(event) {
clearChat();
Expand Down

0 comments on commit bbe9095

Please sign in to comment.