Skip to content

Commit

Permalink
Merge pull request #22 from Lee-Talman/development
Browse files Browse the repository at this point in the history
Release 0.3.1
  • Loading branch information
Lee-Talman authored May 22, 2024
2 parents 7909b49 + 902c233 commit d4edc48
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 135 deletions.
18 changes: 9 additions & 9 deletions css/knave2e.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"KNAVE2E.DamageDiceSize": "Damage Die",
"KNAVE2E.DamageDiceAmount": "# of Dice",
"KNAVE2E.DamageDiceBonus": "Bonus",
"KNAVE2E.DamageRollFormula" : "Roll Formula",
"KNAVE2E.Melee": "Melee",
"KNAVE2E.Ranged": "Ranged",
"KNAVE2E.Sling": "Sling",
Expand Down
38 changes: 27 additions & 11 deletions module/data/monster-attack.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class Knave2eMonsterAttack extends Knave2eItemType {
schema.damageDiceAmount = new fields.NumberField({ ...requiredInteger, initial: 1, min: 0 });
schema.damageDiceSize = new fields.StringField({ required: false, choices: SYSTEM.DAMAGE_DICE_SIZES, initial: "d6" });
schema.damageDiceBonus = new fields.NumberField({ required: true, nullable: false, integer: false, initial: 0, min: -999 });
// schema.damageRoll = new fields.StringField({required: true, initial: "1d6"});
schema.damageRoll = new fields.StringField({required: true, initial: "1d6"});

return schema;
}
Expand All @@ -23,17 +23,33 @@ export default class Knave2eMonsterAttack extends Knave2eItemType {
}

prepareDerivedData() {
let damageRoll = "";
if (this.damageDiceBonus > 0) {
damageRoll = `${this.damageDiceAmount}${this.damageDiceSize}+${this.damageDiceBonus}`;
const rollDamage = new RegExp("^(\\d*)(d[1-9]\\d*)(?:([+-])(\\d+))?$", "");
const flatDamage = new RegExp("^(\\+?|\\-?)(\\d+)$", "");
let m;

if ((m = rollDamage.exec(this.damageRoll)) !== null) {
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});

this.damageDiceAmount = m[1] === "" ? 1 : m[1];
this.damageDiceSize = m[2];

if (m[3] !== "" && m[3] !== undefined && m[3] !== null) {
this.damageDiceBonus = m[3] === "+" ? +m[4] : +`-${m[4]}`;
} else {
this.damageDiceBonus = 0;
}
} else if ((m = flatDamage.exec(this.damageRoll)) !== null) {
this.damageDiceAmount = 0;
this.damageDiceSize = "d6";

if (m[1] !== "" && m[1] !== undefined && m[1] !== null) {
this.damageDiceBonus = m[1] === "-" ? +`-${m[2]}` : +m[2];
} else {
this.damageDiceBonus = +m[2];
}
}
else if (this.damageDiceBonus === 0) {
damageRoll = `${this.damageDiceAmount}${this.damageDiceSize}`;
}
else {
damageRoll = `${this.damageDiceAmount}${this.damageDiceSize}${this.damageDiceBonus}`;
}
this.damageRoll = damageRoll;
}
}

100 changes: 69 additions & 31 deletions module/data/weapon.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,80 @@ import Knave2eItemType from "./item-type.mjs";
import { SYSTEM } from "../config/system.mjs";

export default class Knave2eWeapon extends Knave2eItemType {
static DEFAULT_CATEGORY = "melee";

static DEFAULT_CATEGORY = "melee";
static defineSchema() {
const fields = foundry.data.fields;
const requiredInteger = { required: true, nullable: false, integer: true };
const schema = super.defineSchema();

static defineSchema() {
const fields = foundry.data.fields;
const requiredInteger = { required: true, nullable: false, integer: true };
const schema = super.defineSchema();
schema.ammoType = new fields.StringField({
required: true,
choices: SYSTEM.AMMO_TYPES,
initial: "none",
});
schema.broken = new fields.BooleanField({ initial: false });
schema.range = new fields.NumberField({
...requiredInteger,
initial: 5,
min: 0,
});
schema.damageDiceAmount = new fields.NumberField({
...requiredInteger,
initial: 1,
min: 0,
});
schema.damageDiceSize = new fields.StringField({
required: false,
initial: "d6",
});
schema.damageDiceBonus = new fields.NumberField({
required: false,
initial: 0,
min: -999,
});
schema.damageRoll = new fields.StringField({
required: true,
initial: "1d6",
});

schema.ammoType = new fields.StringField({ required: true, choices: SYSTEM.AMMO_TYPES, initial: "none" });
schema.broken = new fields.BooleanField({ initial: false });
schema.range = new fields.NumberField({ ...requiredInteger, initial: 5, min: 0 });
schema.damageDiceAmount = new fields.NumberField({ ...requiredInteger, initial: 1, min: 0 });
schema.damageDiceSize = new fields.StringField({ required: false, choices: SYSTEM.DAMAGE_DICE_SIZES, initial: "d6" });
schema.damageDiceBonus = new fields.NumberField({ ...requiredInteger, initial: 0, min: -999 });
// schema.damageRoll = new fields.StringField({required: true, initial: "1d6"});
return schema;
}

return schema;
}
prepareBaseData() {
const categories = SYSTEM.WEAPON.CATEGORIES;
const category =
categories[this.category] ||
categories[this.constructor.DEFAULT_CATEGORY];
}

prepareBaseData() {
const categories = SYSTEM.WEAPON.CATEGORIES;
const category = categories[this.category] || categories[this.constructor.DEFAULT_CATEGORY];
}
prepareDerivedData() {
const rollDamage = new RegExp("^(\\d*)(d[1-9]\\d*)(?:([+-])(\\d+))?$", "");
const flatDamage = new RegExp("^(\\+?|\\-?)(\\d+)$", "");
let m;

if ((m = rollDamage.exec(this.damageRoll)) !== null) {
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});

prepareDerivedData() {
let damageRoll = "";
if (this.damageDiceBonus > 0) {
damageRoll = `${this.damageDiceAmount}${this.damageDiceSize}+${this.damageDiceBonus}`;
}
else if (this.damageDiceBonus === 0) {
damageRoll = `${this.damageDiceAmount}${this.damageDiceSize}`;
}
else {
damageRoll = `${this.damageDiceAmount}${this.damageDiceSize}${this.damageDiceBonus}`;
}
this.damageRoll = damageRoll;
this.damageDiceAmount = m[1] === "" ? 1 : m[1];
this.damageDiceSize = m[2];

if (m[3] !== "" && m[3] !== undefined && m[3] !== null) {
this.damageDiceBonus = m[3] === "+" ? +m[4] : +`-${m[4]}`;
} else {
this.damageDiceBonus = 0;
}
} else if ((m = flatDamage.exec(this.damageRoll)) !== null) {
this.damageDiceAmount = 0;
this.damageDiceSize = "d6";

if (m[1] !== "" && m[1] !== undefined && m[1] !== null) {
this.damageDiceBonus = m[1] === "-" ? +`-${m[2]}` : +m[2];
} else {
this.damageDiceBonus = +m[2];
}
}
}
}

4 changes: 4 additions & 0 deletions module/documents/actor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export default class Knave2eActor extends Actor {
if (game.settings.get('knave2e', 'automaticSpells')) {
systemData.spells.max = systemData.abilities.intelligence.value;
}

if (game.settings.get('knave2e', 'automaticWounds')) {
systemData.wounds.max = 10 + systemData.abilities.constitution.value;
}

}

Expand Down
4 changes: 2 additions & 2 deletions module/sheets/actor-sheet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ export default class Knave2eActorSheet extends ActorSheet {

// Render the item sheet for viewing/editing prior to the editable check.
html.find('.item-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item");
const li = $(ev.currentTarget).parents(".knave-item");
const item = this.actor.items.get(li.data("itemId"));
item.sheet.render(true);
});
Expand All @@ -409,7 +409,7 @@ export default class Knave2eActorSheet extends ActorSheet {

// Delete Inventory Item
html.find('.item-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item");
const li = $(ev.currentTarget).parents(".knave-item");
const item = this.actor.items.get(li.data("itemId"));
item.delete();
li.slideUp(200, () => this.render(false));
Expand Down
39 changes: 18 additions & 21 deletions module/sheets/item-sheet.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export default class Knave2eItemSheet extends ItemSheet {


static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: ["knave2e", "sheet", "item"],
Expand All @@ -10,17 +8,15 @@ export default class Knave2eItemSheet extends ItemSheet {
});
}


get template() {
const path = "systems/knave2e/templates/item";
let specificPath = `${path}/item-${this.item.type}-sheet.hbs`;

return specificPath;
}

/* -------------------------------------------- */


async getData() {
// Retrieve base data structure.
const context = super.getData();
Expand Down Expand Up @@ -67,43 +63,50 @@ export default class Knave2eItemSheet extends ItemSheet {
this._prepareMonsterAttackData(context);
}

context.system.enrichedHTML = await TextEditor.enrichHTML(context.system.description);

context.system.enrichedHTML = await TextEditor.enrichHTML(
context.system.description
);

return context;
}

_prepareWeaponData(context) {
const systemData = context.system;

context.weaponCategories = this._labelOptions(CONFIG.SYSTEM.WEAPON.CATEGORIES);
context.weaponCategories = this._labelOptions(
CONFIG.SYSTEM.WEAPON.CATEGORIES
);
context.ammoCategories = this._labelOptions(CONFIG.SYSTEM.AMMO.CATEGORIES);
context.damageDiceCategories = CONFIG.SYSTEM.DAMAGE_DICE_SIZES;
// context.damageDiceCategories = CONFIG.SYSTEM.DAMAGE_DICE_SIZES;

return context;
}


_prepareSpellbookData(context) {
context.spellbookCategories = this._labelOptions(CONFIG.SYSTEM.SPELLBOOK.CATEGORIES);
context.spellbookCategories = this._labelOptions(
CONFIG.SYSTEM.SPELLBOOK.CATEGORIES
);

return context;
}

_prepareLightSourceData(context) {
const systemData = context.system;

context.lightSourceCategories = this._labelOptions(CONFIG.SYSTEM.LIGHTSOURCE.CATEGORIES);
context.lightSourceCategories = this._labelOptions(
CONFIG.SYSTEM.LIGHTSOURCE.CATEGORIES
);

return context;
}

_prepareEquipmentData(context) {

return context;
}

_prepareArmorData(context) {
context.armorCategories = this._labelOptions(CONFIG.SYSTEM.ARMOR.CATEGORIES);
context.armorCategories = this._labelOptions(
CONFIG.SYSTEM.ARMOR.CATEGORIES
);
}

_prepareMonsterAttackData(context) {
Expand All @@ -126,10 +129,4 @@ export default class Knave2eItemSheet extends ItemSheet {
// Everything below here is only needed if the sheet is editable
if (!this.isEditable) return;
}

// async _onSubmit(event) {
// console.log(event)
// super._onSubmit(event)
// }

}
2 changes: 1 addition & 1 deletion scss/components/_items.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
}

// Individual Item
.item {
.knave-item {
display: grid;
align-items: center;
padding-bottom: 2px;
Expand Down
4 changes: 2 additions & 2 deletions templates/actor/actor-monster-sheet.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
</div>
<div class="items">
<ol class="items-list">
<li class="item grid grid-12col items-header">
<li class="knave-item grid grid-12col items-header">
<div class="resource-label item-name-header grid-span-8">{{localize "KNAVE2E.AttackName"}}
</div>
<div class="resource-label item-slots-header grid-span-2">{{localize "KNAVE2E.Attacks"}}
Expand All @@ -102,7 +102,7 @@
</div>
</li>
{{#each items as |item id|}}
<li class="item grid grid-12col" data-item-id="{{item._id}}">
<li class="knave-item grid grid-12col" data-item-id="{{item._id}}">
<div class="item-image"><a class="item-image item-name grid-span-1"><img src="{{item.img}}"
title="{{item.name}}" width="36" height="36" /></a></div>
<a class="item-name detail grid-span-5" style="margin-left:2px;">{{item.name}}</a>
Expand Down
4 changes: 2 additions & 2 deletions templates/actor/actor-recruit-sheet.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
</div>
<div class="items">
<ol class="items-list">
<li class="item grid grid-12col items-header">
<li class="knave-item grid grid-12col items-header">
<div class="resource-label item-name-header grid-span-9">{{localize "KNAVE2E.ItemName"}}
</div>
<div class="resource-label item-slots-header grid-span-1">{{localize "KNAVE2E.Slots"}}</div>
Expand All @@ -176,7 +176,7 @@
</div>
</li>
{{#each items as |item id|}}
<li class="item grid grid-12col {{#if system.dropped}}dropped{{/if}}"
<li class="knave-item grid grid-12col {{#if system.dropped}}dropped{{/if}}"
data-item-id="{{item._id}}">

<div class="item-image"><a class="item-image item-name grid-span-1"><img src="{{item.img}}"
Expand Down
4 changes: 2 additions & 2 deletions templates/actor/parts/actor-character-items.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<br>

<ol class="items-list">
<li class="item grid grid-12col items-header">
<li class="knave-item grid grid-12col items-header">
<div class="resource-label item-name-header grid-span-9">{{localize "KNAVE2E.ItemName"}}</div>
<div class="resource-label item-slots-header grid-span-1">{{localize "KNAVE2E.Slots"}}</div>
<div class="resource-label item-controls-header grid-span-2">
Expand All @@ -71,7 +71,7 @@
</div>
</li>
{{#each items as |item id|}}
<li class="item grid grid-12col {{#if system.dropped}}dropped{{/if}}" data-item-id="{{item._id}}">
<li class="knave-item grid grid-12col {{#if system.dropped}}dropped{{/if}}" data-item-id="{{item._id}}">

<div class="item-image"><a class="item-image item-name grid-span-1"><img src="{{item.img}}" title="{{item.name}}"
width="36" height="36" /></a></div>
Expand Down
Loading

0 comments on commit d4edc48

Please sign in to comment.