Skip to content

Commit

Permalink
fix: Skills can now be rolled, with the selected characteristic's mod…
Browse files Browse the repository at this point in the history
…ifier. Not pretty, but it works.

Still need to figure out how to select the default characteristic for a skill.
  • Loading branch information
xdy committed Jul 21, 2020
1 parent 344810b commit 1a27f1b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 30 deletions.
41 changes: 34 additions & 7 deletions src/module/sheets/TwodsixActorSheet.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/

export class TwodsixActorSheet extends ActorSheet {

/**
Expand Down Expand Up @@ -142,7 +137,10 @@ export class TwodsixActorSheet extends ActorSheet {
});

// Rollable abilities.
html.find('.rollable').on('click', (this._onRollable).bind(this));
html.find('.rollable-characteristic').on('click', (this._onRollableCharacteristic).bind(this));

html.find('.rollable-skill').on('click', (this._onRollableSkill).bind(this));

}

/**
Expand Down Expand Up @@ -177,7 +175,7 @@ export class TwodsixActorSheet extends ActorSheet {
* @param {Event} event The originating click event
* @private
*/
_onRollable(event:{ preventDefault:() => void; currentTarget:any; }):void {
_onRollableCharacteristic(event:{ preventDefault:() => void; currentTarget:any; }):void {
event.preventDefault();
const element = event.currentTarget;
const {dataset} = element;
Expand All @@ -192,6 +190,35 @@ export class TwodsixActorSheet extends ActorSheet {
}
}

/**
* Handle clickable rolls.
* @param {Event} event The originating click event
* @private
*/
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
_onRollableSkill(event:any):void {
event.preventDefault();
const children = event.currentTarget.children;


if (event.originalEvent.target.type === 'select-one') {
//Don't treat select as rollable
return;
}

//Ugly...
const skill:string = children.item(0).innerText;
const skillValue:number = parseInt(children.item(2).textContent);
const characteristicMod = parseInt(this.actor.data.data.characteristics[children.item(1).value].mod);
const roll = new Roll("2d6+" + skillValue + "+" + characteristicMod, this.actor.data.data);
const label = `Rolling ${skill}`;
roll.roll().toMessage({
speaker: ChatMessage.getSpeaker({actor: this.actor}),
flavor: label
});
}


// async _onDrop(event:any):Promise<boolean> {
// event.preventDefault();
//
Expand Down
2 changes: 1 addition & 1 deletion src/module/utils/parseUcf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import {TWODSIX} from "../config";
import {calcModFromString, fromPseudoHex} from "./sheetUtils";

TWODSIX.CHARACTERISTICS = ["STR", "DEX", "END", "INT", "EDU", "SOC", "PSI"];
TWODSIX.CHARACTERISTICS = ["str", "dex", "end", "int", "edu", "soc", "psi"];

//TODO Change so that it modifies the current character's data.

Expand Down
14 changes: 7 additions & 7 deletions static/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,43 @@
"str": {
"value": 0,
"damage": 0,
"short": "STR",
"short": "str",
"label": "Strengh"
},
"dex": {
"value": 0,
"damage": 0,
"short": "DEX",
"short": "dex",
"label": "Dexterity"
},
"end": {
"value": 0,
"damage": 0,
"short": "END",
"short": "end",
"label": "Endurance"
},
"int": {
"value": 0,
"damage": 0,
"short": "INT",
"short": "int",
"label": "Intelligence"
},
"edu": {
"value": 0,
"damage": 0,
"short": "EDU",
"short": "edu",
"label": "Education"
},
"soc": {
"value": 0,
"damage": 0,
"short": "SOC",
"short": "soc",
"label": "Social Status"
},
"psi": {
"value": 0,
"damage": 0,
"short": "PSI",
"short": "psi",
"label": "Psionic Strength"
}
}
Expand Down
29 changes: 14 additions & 15 deletions static/templates/actors/actor-sheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h1 class="charname">
<span data-label="characteristics.{{current}}">{{numberFormat characteristic.current decimals=0}}</span>
<input id="characteristics.{{key}}" type="text" name="damage" value="{{characteristic.value}}"
data-dtype="Number"/>
<span class="characteristic-mod rollable draggable" data-roll="2d6+@characteristics.{{key}}.mod"
<span class="characteristic-mod rollable-characteristic draggable" data-roll="2d6+characteristic.mod"
data-label="{{key}}">{{numberFormat characteristic.mod decimals=0 sign=true}}</span>
</div>
{{/each}}
Expand All @@ -48,7 +48,7 @@ <h1 class="charname">
{{log data.skills}}
{{log data.characteristics}}

<!-- TODO Skill + level + ability dropdown | + 2d6 = output chat-->
<!-- TODO Skill + level + ability dropdown | + 2d6 = output chat-->

<div class="tab skills" data-group="primary" data-tab="skills">
<div class="skills grid grid-2col">
Expand All @@ -58,28 +58,28 @@ <h2 class="clearfix flexbreak">Skills</h2>

<!--TODO Filter out skills from items, I can see items filled, but not data.skills.-->
{{#each items as |skills key|}}
<div class="skills flexrow flex-group-center">
<label class="resource-label">{{skills.name}}</label>
</div>
<!-- TODO Add characteristics dropdown here, with default choice from skill-->
<label>
<div class="rollable-skill">
<div class="skills flexrow flex-group-center">
<label class="resource-label">{{skills.name}}</label>
</div>
<!-- TODO Add characteristics dropdown here, with default choice from skill-->
<select name="data.addskillselect" style="width:200px;">
<!-- TODO Something like the line below, but I get "select doesn't match each"-->
<!-- { { # select skills.data.defaultCharacteristic} }-->
<!-- { { # select skills.data.defaultCharacteristic} }-->
{{log "skills.data.defaultCharacteristic"}}
{{log skills.data.defaultCharacteristic}}
{{log "../skill.defaultCharacteristic"}}
{{log ../skill.defaultCharacteristic}}
{{#each ../data.characteristics as |characteristic ckey|}}
<!-- TODO Also tried handlebar helper for option, same problem.-->
<!-- { { # option ../data.characteristics.{{ckey}}.mod ../data.characteristics.{{ckey}}.short ../skills.data.defaultCharacteristic } }-->
<!-- TODO Also tried handlebar helper for option, same problem.-->
<!-- { { # option ../data.characteristics.{{ckey}}.mod ../data.characteristics.{{ckey}}.short ../skills.data.defaultCharacteristic } }-->
<option value="{{characteristic.short}}" data-value="{{numberFormat characteristic.mod decimals=0 sign=true}}">{{characteristic.short}}</option>
{{/each}}
</select>
</label>
<!-- TODO Somehow, find what has been selected, and add that in the data-roll. Or, do a custom handler, probably better -->
<span class="skill-value rollable draggable" data-roll="2d6+{{skills.data.value}}"
data-label="{{key}}">{{numberFormat skills.data.value decimals=0 sign=true}}</span>
<!-- TODO Somehow, find what has been selected, and add that in the data-roll. Or, do a custom handler, probably better -->
<span class="skill-value draggable" data-roll="2d6+{{skills.data.value}}"
data-label="{{key}}">{{numberFormat skills.data.value decimals=0 sign=true}}</span>
</div>
{{/each}}

<!-- TODO And here I should have all skills from the compendium available-->
Expand Down Expand Up @@ -109,7 +109,6 @@ <h2 class="flexbreak">Add Skill:</h2>
class="fas fa-plus"></i> Add item</a>
</div>
</li>
Owned items should be here...
{{#each actor.items as |item id|}}
<li class="item flexrow" data-item-id="{{item._id}}">
<div class="item-image">
Expand Down

0 comments on commit 1a27f1b

Please sign in to comment.