-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored all JS code into esmodules
fixed bugs
- Loading branch information
Showing
22 changed files
with
864 additions
and
649 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export default class ModuleSettings { | ||
static register() { | ||
game.settings.register("forien-quest-log", "showTasks", { | ||
name: "ForienQuestLog.showTasks.Enable", | ||
hint: "ForienQuestLog.showTasks.EnableHint", | ||
scope: "world", | ||
config: true, | ||
default: "default", | ||
type: String, | ||
choices: { | ||
"default": "ForienQuestLog.showTasks.default", | ||
"onlyCurrent": "ForienQuestLog.showTasks.onlyCurrent", | ||
"no": "ForienQuestLog.showTasks.no" | ||
}, onChange: value => { | ||
if (game.questlog && game.questlog.rendered) { | ||
game.questlog.render(); | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
export default class QuestFolder { | ||
static questDirName = { | ||
root: '_fql_quests', | ||
active: '_fql_active', | ||
completed: '_fql_completed', | ||
failed: '_fql_failed', | ||
hidden: '_fql_hidden' | ||
}; | ||
|
||
static _questDirIds = { | ||
root: null, | ||
active: null, | ||
completed: null, | ||
failed: null, | ||
hidden: null | ||
}; | ||
|
||
/** | ||
* Returns true if quest directory has been created | ||
* | ||
* @param folder | ||
* @returns {boolean} | ||
*/ | ||
static folderExists(folder = 'root') { | ||
let result = game.journal.directory.folders.find(f => f.name === this.questDirName[folder]); | ||
|
||
return result !== undefined; | ||
} | ||
|
||
static async initializeJournals() { | ||
let dirExists = this.folderExists(); | ||
|
||
if (!dirExists) { | ||
let rootFolder = await Folder.create({name: this.questDirName.root, type: "JournalEntry", parent: null}); | ||
|
||
for (let [key, value] of Object.entries(this.questDirName)) { | ||
if (key === 'root') continue; | ||
await Folder.create({name: value, type: "JournalEntry", parent: rootFolder._id}); | ||
} | ||
} | ||
|
||
for (let key in this.questDirName) { | ||
let folder = await game.journal.directory.folders.find(f => f.name === this.questDirName[key]); | ||
this._questDirIds[key] = folder._id; | ||
} | ||
} | ||
|
||
static get(target) { | ||
return game.journal.directory.folders.find(f => f.name === this.questDirName[target]); | ||
} | ||
|
||
|
||
static get questDirIds() { | ||
return this._questDirIds; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import QuestFolder from "./quest-folder.mjs"; | ||
import Utils from "./utils.mjs"; | ||
import Task from "./task.mjs"; | ||
import Quest from "./quest.mjs"; | ||
import Socket from "./socket.mjs"; | ||
|
||
export default class QuestForm extends FormApplication { | ||
static get defaultOptions() { | ||
return mergeObject(super.defaultOptions, { | ||
id: "forien-quest-log-form", | ||
template: "modules/forien-quest-log/templates/quest-log-form.html", | ||
title: "Add new Quest", | ||
width: 940, | ||
height: 640, | ||
closeOnSubmit: true | ||
}); | ||
} | ||
|
||
async getData(options = {}) { | ||
return mergeObject(super.getData(), { | ||
options: options, | ||
isGM: game.user.isGM | ||
}); | ||
} | ||
|
||
getHiddenFolder() { | ||
return QuestFolder.get('hidden'); | ||
} | ||
|
||
async _updateObject(event, formData) { | ||
let actor = Utils.findActor(formData.actor); | ||
|
||
if (actor !== false) { | ||
actor = actor._id; | ||
} | ||
|
||
let title = formData.title; | ||
if (title.length === 0) | ||
title = 'New Quest'; | ||
|
||
let tasks = []; | ||
if (formData.tasks !== undefined) { | ||
if (!Array.isArray(formData.tasks)) { | ||
formData.tasks = [formData.tasks]; | ||
} | ||
tasks = formData.tasks.filter(t => t.length > 0).map(t => { | ||
return new Task({name: t}); | ||
}); | ||
} | ||
|
||
let description = (formData.description !== undefined && formData.description.length) ? formData.description : this.description; | ||
let gmnotes = (formData.gmnotes !== undefined && formData.gmnotes.length) ? formData.gmnotes : this.gmnotes; | ||
|
||
let data = { | ||
actor: actor, | ||
title: title, | ||
description: description, | ||
gmnotes: gmnotes, | ||
tasks: tasks | ||
}; | ||
|
||
data = new Quest(data); | ||
|
||
let folder = this.getHiddenFolder(); | ||
|
||
console.log(data); | ||
console.log(description); | ||
console.log(gmnotes); | ||
console.log(JSON.stringify(data)); | ||
|
||
JournalEntry.create({ | ||
name: title, | ||
content: JSON.stringify(data), | ||
folder: folder._id | ||
}).then(() => { | ||
game.questlog.render(true); | ||
// players don't see Hidden tab, but assistant GM can, so emit anyway | ||
Socket.refreshQuestLog(); | ||
}); | ||
} | ||
|
||
async _onEditorSave(target, element, content) { | ||
this[target] = content; | ||
|
||
// keep function to override parent function | ||
// we don't need to submit form on editor save | ||
} | ||
|
||
activateListeners(html) { | ||
super.activateListeners(html); | ||
|
||
html.on("change", "#actor", (event) => { | ||
let actorId = $(event.currentTarget).val(); | ||
|
||
let actor = Utils.findActor(actorId); | ||
|
||
if (actor !== false) { | ||
html.find('.actor-portrait').attr('src', actor.img).removeClass('hidden'); | ||
html.find('.actor-name').text(actor.name).removeClass('hidden'); | ||
} | ||
}); | ||
|
||
html.on("drop", ".actor-data-fieldset", (event) => { | ||
event.preventDefault(); | ||
let data = JSON.parse(event.originalEvent.dataTransfer.getData('text/plain')); | ||
if (data.type === 'Actor') { | ||
html.find('#actor').val(data.id).change(); | ||
} | ||
}); | ||
|
||
html.on("click", ".add-new-task", () => { | ||
renderTemplate('modules/forien-quest-log/templates/partials/quest-log-form-task.html', {}).then(el => { | ||
console.log(el); | ||
|
||
console.log($(el)); | ||
html.find('.list').append(el); | ||
html.find('.del-btn').unbind(); | ||
html.on("click", ".del-btn", (event) => { | ||
console.log(event); | ||
console.log($(event)); | ||
$(event.target).parent().remove(); | ||
}); | ||
}); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import Quest from "./quest.mjs"; | ||
import QuestPreview from "./quest-preview.mjs"; | ||
import QuestForm from "./quest-form.mjs"; | ||
|
||
export default class QuestLog extends Application { | ||
static get defaultOptions() { | ||
return mergeObject(super.defaultOptions, { | ||
id: "forien-quest-log", | ||
classes: ["forien-quest-log"], | ||
template: "modules/forien-quest-log/templates/quest-log.html", | ||
width: 700, | ||
height: 480, | ||
minimizable: true, | ||
resizable: true, | ||
title: "Quest Log", | ||
tabs: [{navSelector: ".log-tabs", contentSelector: ".log-body", initial: "progress"}] | ||
}); | ||
} | ||
|
||
getData(options = {}) { | ||
return mergeObject(super.getData(), { | ||
options: options, | ||
isGM: game.user.isGM, | ||
showTasks: game.settings.get("forien-quest-log", "showTasks"), | ||
questTypes: Quest.getQuestTypes(), | ||
quests: Quest.getQuests() | ||
}); | ||
} | ||
|
||
activateListeners(html) { | ||
super.activateListeners(html); | ||
|
||
html.on("click", ".new-quest-btn", () => { | ||
new QuestForm({}).render(true); | ||
}); | ||
|
||
html.on("click", ".actions i", event => { | ||
let questId = $(event.target).data('quest-id'); | ||
let classList = $(event.target).attr('class'); | ||
if (classList.includes('move')) { | ||
let target = $(event.target).data('target'); | ||
Quest.move(questId, target); | ||
} else if (classList.includes('delete')) { | ||
Quest.delete(questId); | ||
} | ||
}); | ||
|
||
html.on("click", ".title", event => { | ||
let questId = $(event.target).data('quest-id'); | ||
let questPreview = new QuestPreview(questId); | ||
questPreview.render(true); | ||
}); | ||
} | ||
}; |
Oops, something went wrong.