Skip to content

Commit

Permalink
refactored all JS code into esmodules
Browse files Browse the repository at this point in the history
fixed bugs
  • Loading branch information
Forien committed Jun 15, 2020
1 parent 2aa914c commit c5b76e0
Show file tree
Hide file tree
Showing 22 changed files with 864 additions and 649 deletions.
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# FoundryVTT - Forien's Quest Log
**[Current version]**: v0.1.2-alpha Pre-Release
**[Current version]**: v0.2.0
**[Compatibility]**: *FoundryVTT* 0.6.0+

This module provides Quest Log system for players and Game Masters to use with Foundry Virtual Table Top

Players need `Create Journal Entry` permission to see `Quest Log` button. Will change it in future updates.

***If something doesn't work, make sure you have the NEWEST version. If you do, [submit an issue](https://github.com/Forien/foundryvtt-forien-quest-log/issues) or write me a [Direct Message on Discord](#Contact)!***

**DISCLAIMER:** Module is work-in-progress, everything is subject to change. I ***do not*** guarantee data backwards-compatibility, so you might lose Quests' data in the future. If you intend on using this for gameplay, always backup before updating.


## Installation

Expand All @@ -19,8 +15,23 @@ Players need `Create Journal Entry` permission to see `Quest Log` button. Will c

## Features


## Future plans
* Quest Log windows that lists all quests divided into `In Progress`, `Completed` and `Failed` tabs
* Quest creator with WYSIWYG editors for description and GM notes
* Subtasks
* Draggable Item rewards

## Future plans (current ideas)

* hiding individual tasks
* a toggle "hide future tasks from players"
* draggable EXP/Money rewards (need to wait for FVTT 0.7.0)
* reward button to give all target actors all rewards
* "available quests" tab
* personal quests
* chapters
* quest's splash art/dedicated image
* quest branching
* search/filtering

*If you have **any** suggestion or idea on new contents, hit me up on Discord!*

Expand Down
23 changes: 7 additions & 16 deletions module.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,32 @@
{
"name": "forien-quest-log",
"title": "Forien's Quest Log",
"description": "",
"description": "Provides comprehensive Quest Log system for players and Game Masters",
"author": "Forien — Forien#2130",
"authors": [
{
"name": "Forien",
"url": "https://www.patreon.com/forien"
}
],
"version": "0.1.2-alpha",
"version": "0.2.0",
"minimumCoreVersion": "0.6.0",
"compatibleCoreVersion": "0.6.2",
"url": "https://github.com/Forien/forien-quest-log",
"manifest": "https://raw.githubusercontent.com/Forien/foundryvtt-forien-quest-log/master/module.json",
"download": "https://github.com/Forien/foundryvtt-forien-quest-log/archive/v0.1.2-alpha.zip",
"readme": "https://github.com/Forien/foundryvtt-forien-quest-log/blob/v0.1.2-alpha/README.md",
"changelog": "https://github.com/Forien/foundryvtt-forien-quest-log/blob/v0.1.2-alpha/changelog.md",
"download": "https://github.com/Forien/foundryvtt-forien-quest-log/archive/v0.2.0.zip",
"readme": "https://github.com/Forien/foundryvtt-forien-quest-log/blob/v0.2.0/README.md",
"changelog": "https://github.com/Forien/foundryvtt-forien-quest-log/blob/v0.2.0/changelog.md",
"bugs": "https://github.com/Forien/foundryvtt-forien-quest-log/issues",
"languages": [
{
"lang": "en",
"name": "English",
"path": "lang/en.json"
},
{
"lang": "pl",
"name": "Polski",
"path": "lang/pl.json"
}
],
"scripts": [
"./scripts/init.js",
"./scripts/add-config.js",
"./scripts/quest-log.js",
"./scripts/socket.js",
"./scripts/utils.js"
"esmodules": [
"./scripts/init.js"
],
"styles": [
"./styles/quest-log.css"
Expand Down
21 changes: 21 additions & 0 deletions modules/config.mjs
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();
}
}
});
}
}
56 changes: 56 additions & 0 deletions modules/quest-folder.mjs
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;
}
}
126 changes: 126 additions & 0 deletions modules/quest-form.mjs
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();
});
});
});
}
};
54 changes: 54 additions & 0 deletions modules/quest-log.mjs
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);
});
}
};
Loading

0 comments on commit c5b76e0

Please sign in to comment.