Skip to content

Commit

Permalink
fix: Made characterstics editable, calculate current value and mod as…
Browse files Browse the repository at this point in the history
… damage (and value, which really should be locked for edit by default) change. Added dropdown for skill level (still called value, should probably change that.)
  • Loading branch information
xdy committed Jul 25, 2020
1 parent 7a6dc20 commit 5a6c54d
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 46 deletions.
66 changes: 33 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/module/entities/TwodsixActor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export default class TwodsixActor extends Actor {
const {data} = actorData;

for (const cha of Object.values(data.characteristics as Record<any, any>)) {
cha.mod = calcModFor(cha.value)
cha.current = cha.value - cha.damage;
cha.mod = calcModFor(cha.current);
}

}
Expand Down
6 changes: 6 additions & 0 deletions src/module/handlebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,10 @@ export default function registerHandlebarsHelpers():void {
const selectedProperty = value == selectedValue ? 'selected="selected"' : '';
return new Handlebars.SafeString('<option value="' + label + '"' + selectedProperty + ' data-value="' + value + '">' + label + "</option>");
});

Handlebars.registerHelper('select2', function( value, options ){
const $el = $('<select />').html( options.fn(this) );
$el.find('[value="' + value + '"]').attr({'selected':'selected'});
return $el.html();
});
}
3 changes: 2 additions & 1 deletion src/module/sheets/TwodsixActorSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,11 @@ export class TwodsixActorSheet extends ActorSheet {

//Ugly...
const skill:string = children.item(0).innerText;
const skillValue:number = parseInt(children.item(4).textContent);
const characteristicMod = parseInt(this.actor.data.data.characteristics[children.item(1).value].mod);
const dice = Rolltype[children.item(2).value];
const difficulty = children.item(3).value as keyof typeof Difficulties;
// const skillValue:number = parseInt(children.item(4).textContent);
const skillValue:number = children.item(4).value;

//TODO This is for CE, other variants change the target from 8 instead of modifying roll, should read formula from config based on variant
const successValue = 8;
Expand Down
2 changes: 1 addition & 1 deletion src/module/utils/sheetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export function nobleTitle(soc:number, gender:string):string {

export function calcModFor(characteristic:number):number {
// TODO If characteristic is 0 and not cepheus, set mod to -3
return (characteristic - 6) / 3;
return Math.floor((characteristic - 6) / 3);
}

export function calcModFromString(characteristic:string):number {
Expand Down
31 changes: 21 additions & 10 deletions static/templates/actors/actor-sheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ <h1 class="charname">
</div>
{{#each data.characteristics as |characteristic key|}}
<div class="characteristic flexrow flex-group-center">
<label for="characteristics.{{key}}" class="resource-label">{{characteristic.short}}</label>
<span data-label="characteristics.{{value}}">{{numberFormat characteristic.value decimals=0}}</span>
<label class="resource-label">{{characteristic.short}}</label>
<input type="text" min="0" name="data.characteristics.{{key}}.value" value="{{characteristic.value}}" />
<!-- <span data-label="characteristics.{{value}}">{{numberFormat characteristic.value decimals=0}}</span>-->
<!-- <input type="text" name="data.characteristics.{{key}}.current" value="{{characteristic.current}}" />-->
<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-characteristic draggable" data-roll="2d6+characteristic.mod"
data-label="{{key}}">{{numberFormat characteristic.mod decimals=0 sign=true}}</span>
<input type="text" max="{{characteristic.value}}" min="0" name="data.characteristics.{{key}}.damage" value="{{characteristic.damage}}" data-dtype="Number"/>
<span class="characteristic-mod rollable-characteristic draggable" data-label="{{key}}">{{numberFormat characteristic.mod decimals=0 sign=true}}</span>
</div>
{{/each}}
</div>
Expand Down Expand Up @@ -66,8 +66,6 @@ <h2 class="clearfix flexbreak">Skills</h2>
<!-- { { # 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 } }-->
Expand All @@ -80,7 +78,9 @@ <h2 class="clearfix flexbreak">Skills</h2>
<option value="Advantage" data-value="Advantage">Advantage</option>
<option value="Disadvantage" data-value="Disadvantage">Disadvantage</option>
</select>
<!-- Dropdown should default to Average, but still be sorted in correct order -->


<!-- Dropdown should really default to Average, but still be sorted in correct order -->
<select name="difficulty" style="width:200px;">
<option value="Average" data-value="Average">Average</option>
<option value="Simple" data-value="Simple">Simple</option>
Expand All @@ -90,7 +90,18 @@ <h2 class="clearfix flexbreak">Skills</h2>
<option value="Formidable" data-value="Formidable">Formidable</option>
<option value="Impossible" data-value="Impossible">Impossible</option>
</select>
<span class="skill-value draggable" data-label="{{key}}">{{numberFormat skills.data.value decimals=0 sign=true}}</span>
<!-- <span class="skill-value draggable" data-label="{{key}}">{{numberFormat skills.data.value decimals=0 sign=true}}</span>-->

<select name="skill.value" value="{{skill.value}}" style="width:200px;">
<option value=-3 data-value=-3>Untrained</option>
<option value=0 data-value=0>0</option>
<option value=1 data-value=1>1</option>
<option value=2 data-value=1>2</option>
<option value=3 data-value=2>3</option>
<option value=4 data-value=3>4</option>
<option value=5 data-value=3>5</option>
<option value=6 data-value=3>6</option>
</select>
</div>
{{/each}}

Expand Down

0 comments on commit 5a6c54d

Please sign in to comment.