Skip to content

Commit

Permalink
Merge pull request #16 from stian-svedenborg/v10-compatability
Browse files Browse the repository at this point in the history
Add support for Core v10
  • Loading branch information
RaySSharma authored Jan 17, 2023
2 parents 4f0e4aa + dc82438 commit 4b72988
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 74 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## 5E Encounter Builder

* **Author**: RaySSharma#4736
* **Version**: 0.3.0
* **Foundry VTT Compatibility**: 0.9.0+
* **Version**: 0.4.0
* **Foundry VTT Compatibility**: 10+
* **System Compatibility (If applicable)**: D&D5E
* **Translation Support**: en

Expand Down
Binary file modified encounter-builder.zip
Binary file not shown.
File renamed without changes.
51 changes: 36 additions & 15 deletions encounter-builder/module.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
{
"name": "encounter-builder",
"id": "encounter-builder",
"title": "5e Encounter Builder",
"description": "Adds an application to determine encounter difficulty, based on the Kobold Fight Club.",
"version": "0.3.0",
"minimumCoreVersion": "9",
"compatibleCoreVersion": "9",
"author": "RaySSharma",
"scripts": ["./src/encounter-builder.js", "./src/builder-form.js"],
"styles": ["./css/encounter-builder.css"],
"description": "Adds an application to determine encounter difficulty, based on the Kobold Fight Club. [Fork]",
"version": "0.4.0",
"compatibility": {
"minimum": "10",
"verified": "10.291"
},
"authors": [
{
"name": "RaySSharma"
}
],
"scripts": [
"./src/encounter-builder.js",
"./src/builder-form.js"
],
"styles": [
"./css/encounter-builder.css"
],
"languages": [
{
"lang": "en",
"name": "English",
"path": "lang/en.json"
"lang": "en",
"name": "English",
"path": "lang/en.json"
},
{
"lang": "pt",
Expand All @@ -24,10 +35,20 @@
"name": "Castellano",
"path": "lang/es-ES.json"
}
],
"system": "dnd5e",
],
"relationships": {
"systems": [
{
"id": "dnd5e",
"type": "system",
"manifest": "https://raw.githubusercontent.com/foundryvtt/dnd5e/master/system.json",
"compatibility": {
"verified": "2.0.3"
}
}]
},
"url": "https://github.com/RaySSharma/fvtt-encounter-builder",
"manifest": "https://raw.githubusercontent.com/RaySSharma/fvtt-encounter-builder/master/encounter-builder/module.json",
"download": "https://github.com/RaySSharma/fvtt-encounter-builder/archive/v0.3.0.zip",
"readme": "https://raw.githubusercontent.com/RaySSharma/fvtt-encounter-builder/master/README.md"
"download": "https://github.com/RaySSharma/fvtt-encounter-builder/archive/v0.4.0.zip",
"readme": "https://github.com/RaySSharma/fvtt-encounter-builder/blob/master/README.md"
}
109 changes: 52 additions & 57 deletions encounter-builder/src/builder-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ class EncounterBuilderApplication extends Application {
this.allies.forEach(function (ally, index) {

let level;
if (ally.data.type === "character") {
level = parseInt(ally.data.data.details.level);
if (ally.type === "character") {
level = parseInt(ally.system.details.level);
if (level === 0) {
level = 1;
}
}
else if (ally.data.type === "npc") {
let xp = EB.CRtoXP[ally.data.data.details.cr];
else if (ally.type === "npc") {
let xp = EB.CRtoXP[ally.system.details.cr];
level = EB.xpThresholds.deadly.findIndex(e => e >= xp)
if (level < 0) {
level = 19;
Expand All @@ -127,15 +127,15 @@ class EncounterBuilderApplication extends Application {
});
this.opponents.forEach(function (opponent, index) {
let xp;
if (opponent.data.type === "character") {
let level = opponent.data.data.details.level
if (opponent.type === "character") {
let level = opponent.system.details.level
if (level === 0) {
level = 1;
}
xp = EB.xpThresholds[EB.difficultyToTreatPC][level - 1]
}
else if (opponent.data.type === "npc") {
xp = opponent.data.data.details.xp.value;
else if (opponent.type === "npc") {
xp = opponent.system.details.xp.value;
}
totalXP += xp;
});
Expand Down Expand Up @@ -211,21 +211,33 @@ class EncounterBuilderApplication extends Application {
* @memberof EncounterBuilderApplication
*/
async _onDropGeneral(event) {
let data;
data = JSON.parse(event.dataTransfer.getData("text/plain"));
if (data.type !== game.actors.documentName) {
throw new Error(game.i18n.localize("EB.EntityError"));
const data = JSON.parse(event.dataTransfer.getData("text/plain"));
const actors = []

function recur_folder(folder) {
const actors = folder.contents
const subfolders = folder.getSubfolders()
for (let i = 0; i < subfolders.length; i++) {
actors.push(...recur_folder(subfolders[i]))
}

return actors
}

const app = game.users.apps.find(e => e.id === game.i18n.localize("EB.id"));
let actor;
if (data.pack) {
actor = await Actor.fromDropData(data);
if (data.type === "Folder" && data.documentName === "Actor") {
const folder = await Folder.fromDropData(data)
actors.push(...recur_folder(folder))
}
else if (data.type === game.actors.documentName) {
const actor = await Actor.fromDropData(data);
actors.push(actor)
}
else {
actor = game.actors.get(data.id);
throw new Error(game.i18n.localize("EB.EntityError"));
}
return [app, actor]

const app = game.users.apps.find(e => e.id === game.i18n.localize("EB.id"));
return [app, actors]
}

/**
Expand All @@ -236,32 +248,11 @@ class EncounterBuilderApplication extends Application {
*/
async _onDropAlly(event) {
event.preventDefault();

let [app, actor] = await this._onDropGeneral(event);

let actorExists;
let actorExistsOpposing;
if (actor.data.type === "character") {
actorExists = app.allies.find(e => e.id === actor.id)
actorExistsOpposing = app.opponents.find(e => e.id === actor.id);

if (actorExistsOpposing) {
let ix = this.opponents.findIndex(e => e.id === actor.id);
this.opponents.splice(ix, 1);
}
if (!actorExists) {
app.allies.push(actor)
}
}
else if (actor.data.type === "npc") {
app.allies.push(actor);
}

app.calcXPThresholds();
app.calcRating();
app.render();
let [app, actors] = await this._onDropGeneral(event);
await this.processDrop(event, app.allies, app.opponents, app, actors)
}


/**
* Ondrop for opponents. Cannot have a playable character multiple times. Can have monsters/npcs multiple times.
*
Expand All @@ -270,27 +261,31 @@ class EncounterBuilderApplication extends Application {
*/
async _onDropOpponent(event) {
event.preventDefault();
let [app, actors] = await this._onDropGeneral(event);
await this.processDrop(event, app.opponents, app.allies, app, actors)
}

let [app, actor] = await this._onDropGeneral(event)
async processDrop(event, currentDropZone, opposingDropZone, app, actors) {

let actorExists;
let actorExistsOpposing;
if (actor.data.type === "character") {
actorExists = app.opponents.find(e => e.id === actor.id);
actorExistsOpposing = app.allies.find(e => e.id === actor.id);

if (actorExistsOpposing) {
let ix = this.allies.findIndex(e => e.id === actor.id);
this.allies.splice(ix, 1);
actors.forEach(function (actor) {
if (actor.type === "character") {
actorExists = currentDropZone.find(e => e.id === actor.id)
actorExistsOpposing = opposingDropZone.find(e => e.id === actor.id);

if (actorExistsOpposing) {
let ix = opposingDropZone.findIndex(e => e.id === actor.id);
opposingDropZone.splice(ix, 1);
}
if (!actorExists) {
currentDropZone.push(actor)
}
}
if (!actorExists) {
app.opponents.push(actor)
else if (actor.type === "npc") {
currentDropZone.push(actor);
}

}
else if (actor.data.type === "npc") {
app.opponents.push(actor);
}
})

app.calcXPThresholds();
app.calcRating();
Expand Down

0 comments on commit 4b72988

Please sign in to comment.