Skip to content

Commit

Permalink
Item support added
Browse files Browse the repository at this point in the history
  • Loading branch information
constant-null committed Mar 29, 2024
1 parent 9eb7517 commit 654a292
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 88 deletions.
6 changes: 4 additions & 2 deletions lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
},
"Item": {
"Name": "Название",
"Modifier": "Модификатор",
"DefaultName": "Новый Предмет"
"Dice": "Кубик",
"DefaultName": "Новый Предмет",
"NoDice": "Нет"
},
"Ranks": {
"1": "Агент 3-го разряда",
Expand Down Expand Up @@ -46,6 +47,7 @@
"Uses": "Использует",
"InHeroicMoment": "В свой <b>Героический Момент</b>",
"SkillCheck": "Совершает проверку навыка",
"ItemUsed": "Использует \"{item}\"",
"DifficultyX": "Сложность {diff}"
},
"HeroicMoment": "Героический Момент",
Expand Down
57 changes: 57 additions & 0 deletions module/sheets/efs-character-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ export default class EFSCharacterSheet extends ActorSheet {
html.find(".clickable.approach").click(this._approachClicked.bind(this));
html.find(".heroic-mode").click(this._heroicModeClicked.bind(this));
html.find(".clickable#extra").click(this._showExtra.bind(this));

html.find(".skill-4").click(this._skill4Click.bind(this));
html.find(".skill-8").click(this._skill8Click.bind(this));
html.find(".skill-12").click(this._skill12Click.bind(this));
html.find(".skill-16").click(this._skill16Click.bind(this));

html.find(".edit-item").click(this._onEditItem.bind(this))
html.find(".delete-item").click(this._onDeleteItem.bind(this))
html.find(".add-item").click(this._onAddItem.bind(this))
html.find(".item").click(this._onClickItem.bind(this))
}

async _skill4Click(event) {
Expand Down Expand Up @@ -55,6 +61,57 @@ export default class EFSCharacterSheet extends ActorSheet {
});
}

async _onClickItem(event) {
event.preventDefault();
const itemId = event.target.dataset.id;
const item = this.actor.getEmbeddedDocument("Item", itemId);

let r = await new Roll(`1d`+item._system.dice).evaluate({async: true});
let message = "<b>"+game.i18n.localize("EFS.Message.ItemUsed").replace("{item}", item.name)+"</b>"

await r.toMessage({
flavor: message,
speaker: ChatMessage.getSpeaker({actor: this.actor})
});
}

_onEditItem(event) {
event.preventDefault();

const item = this.actor.getEmbeddedDocument("Item", event.target.dataset.id);
if (!item) {
return;
}
item.sheet.render(true);
}

async _onDeleteItem(event) {
event.preventDefault();
const itemId = event.target.dataset.id;
const item = this.actor.getEmbeddedDocument("Item", itemId);

new Dialog({
title: game.i18n.localize("EFS.Dialog.ActionConfirm"),
content: game.i18n.localize("EFS.Dialog.ConfirmDeletion")+"<b>"+item.name+"</b>?",
buttons: {
yes: {
label: game.i18n.localize("EFS.Dialog.Yes"),
callback: () => {this.actor.deleteEmbeddedDocuments("Item", [event.target.dataset.id])},
},
no: {
label: game.i18n.localize("EFS.Dialog.No"),
callback: () => {}
}
}
}).render(true);
}

async _onAddItem(event) {
event.preventDefault();
const items = await this.actor.createEmbeddedDocuments("Item", [{name:game.i18n.localize("EFS.Item.DefaultName"), type:"item"}])
await items[0].sheet.render(true);
}

async _showExtra(event) {
new EFSCharacterExtraSheet(this.actor).render(true);
}
Expand Down
2 changes: 1 addition & 1 deletion template.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"item"
],
"item": {
"modifier": 0,
"dice": 0,
"description": ""
}
}
Expand Down
147 changes: 89 additions & 58 deletions templates/sheets/efs-character-sheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,91 +35,122 @@
<span class="label">{{ localize 'EFS.Character.Skills' }}</span>
<div class="flex row">
<span class="skill skill-4 clickable">4:</span>
{{editor data.skills.four target="system.skills.four" class="skill-4 clickable regular skill-desc" button=true editable=true engine="prosemirror"}}
{{editor data.skills.four target="system.skills.four" class="skill-4 clickable regular
skill-desc" button=true editable=true engine="prosemirror"}}
</div>
<div class="flex row">
<span class="skill skill-8 clickable">8:</span>
{{editor data.skills.eight target="system.skills.eight" class="skill-8 clickable regular skill-desc" button=true editable=true engine="prosemirror"}}
{{editor data.skills.eight target="system.skills.eight" class="skill-8 clickable regular
skill-desc" button=true editable=true engine="prosemirror"}}
</div>
<div class="flex row">
<span class="skill skill-12 clickable">12:</span>
{{editor data.skills.twelve target="system.skills.twelve" class="skill-12 clickable regular skill-desc" button=true editable=true engine="prosemirror"}}
<span class="skill skill-12 clickable">12:</span>
{{editor data.skills.twelve target="system.skills.twelve" class="skill-12 clickable regular
skill-desc" button=true editable=true engine="prosemirror"}}
</div>
<div class="flex row">
<span class="skill skill-16 clickable">16:</span>
{{editor data.skills.sixteen target="system.skills.sixteen" class="skill-16 clickable regular skill-desc" button=true editable=true engine="prosemirror"}}
{{editor data.skills.sixteen target="system.skills.sixteen" class="skill-16 clickable
regular skill-desc" button=true editable=true engine="prosemirror"}}
</div>
</div>
</div>
<div class="flex photo">
<div class="flex">
<img src="{{actor.img}}" data-edit="img" title="{{actor.name}}" width="128" class="picture"/>
</div>
<div class="photo-info">
<div class="dp">
<div class="flex right-column">
<div class="flex photo">
<div class="flex">
<img src="{{actor.img}}" data-edit="img" title="{{actor.name}}" width="128"
class="picture"/>
</div>
<div class="photo-info">
<div class="dp">
<span class="label">
{{ localize 'EFS.Character.DP' }} ({{ localize 'EFS.Max' }}<input name="data.dp.max"
class="text-input short"
value="{{data.dp.max}}"/>)
</span>
<input name="data.defeatPoints" class="text-input short" value="{{data.defeatPoints}}"/>
</div>
<div class="approaches">
<div>
<div class="flex row">
<div>
<span id="brutal" class="clickable approach">{{ localize 'EFS.Approaches.Short.Brutal' }}</span>
<select class="select" name="data.approaches.brutal">
{{#select data.approaches.brutal}}
<option value="6">{{ localize 'EFS.DicePrefix' }}6</option>
<option value="8">{{ localize 'EFS.DicePrefix' }}8</option>
<option value="10">{{ localize 'EFS.DicePrefix' }}10</option>
<option value="12">{{ localize 'EFS.DicePrefix' }}12</option>
{{/select}}
</select>
</div>
<div>
<input name="data.defeatPoints" class="text-input short" value="{{data.defeatPoints}}"/>
</div>
<div class="approaches">
<div>
<div class="flex row">
<div>
<span id="brutal" class="clickable approach">{{ localize 'EFS.Approaches.Short.Brutal' }}</span>
<select class="select" name="data.approaches.brutal">
{{#select data.approaches.brutal}}
<option value="4">{{ localize 'EFS.DicePrefix' }}4</option>
<option value="6">{{ localize 'EFS.DicePrefix' }}6</option>
<option value="8">{{ localize 'EFS.DicePrefix' }}8</option>
<option value="10">{{ localize 'EFS.DicePrefix' }}10</option>
<option value="12">{{ localize 'EFS.DicePrefix' }}12</option>
{{/select}}
</select>
</div>
<div>
<span id="skillful"
class="clickable approach">{{ localize 'EFS.Approaches.Short.Skillful' }}</span>
<select class="select" name="data.approaches.skillful">
{{#select data.approaches.skillful}}
<option value="6">{{ localize 'EFS.DicePrefix' }}6</option>
<option value="8">{{ localize 'EFS.DicePrefix' }}8</option>
<option value="10">{{ localize 'EFS.DicePrefix' }}10</option>
<option value="12">{{ localize 'EFS.DicePrefix' }}12</option>
{{/select}}
</select>
<select class="select" name="data.approaches.skillful">
{{#select data.approaches.skillful}}
<option value="4">{{ localize 'EFS.DicePrefix' }}4</option>
<option value="6">{{ localize 'EFS.DicePrefix' }}6</option>
<option value="8">{{ localize 'EFS.DicePrefix' }}8</option>
<option value="10">{{ localize 'EFS.DicePrefix' }}10</option>
<option value="12">{{ localize 'EFS.DicePrefix' }}12</option>
{{/select}}
</select>
</div>
</div>
</div>
<div class="flex row">
<div class="flex row">

<div>
<span id="smart" class="clickable approach">{{ localize 'EFS.Approaches.Short.Smart' }}</span>
<select class="select" name="data.approaches.smart">
{{#select data.approaches.smart}}
<option value="6">{{ localize 'EFS.DicePrefix' }}6</option>
<option value="8">{{ localize 'EFS.DicePrefix' }}8</option>
<option value="10">{{ localize 'EFS.DicePrefix' }}10</option>
<option value="12">{{ localize 'EFS.DicePrefix' }}12</option>
{{/select}}
</select>
</div>
<div>
<div>
<span id="smart" class="clickable approach">{{ localize 'EFS.Approaches.Short.Smart' }}</span>
<select class="select" name="data.approaches.smart">
{{#select data.approaches.smart}}
<option value="4">{{ localize 'EFS.DicePrefix' }}4</option>
<option value="6">{{ localize 'EFS.DicePrefix' }}6</option>
<option value="8">{{ localize 'EFS.DicePrefix' }}8</option>
<option value="10">{{ localize 'EFS.DicePrefix' }}10</option>
<option value="12">{{ localize 'EFS.DicePrefix' }}12</option>
{{/select}}
</select>
</div>
<div>
<span id="charismatic"
class="clickable approach">{{ localize 'EFS.Approaches.Short.Charismatic' }}</span>
<select class="select" name="data.approaches.charismatic">
{{#select data.approaches.charismatic}}
<option value="6">{{ localize 'EFS.DicePrefix' }}6</option>
<option value="8">{{ localize 'EFS.DicePrefix' }}8</option>
<option value="10">{{ localize 'EFS.DicePrefix' }}10</option>
<option value="12">{{ localize 'EFS.DicePrefix' }}12</option>
{{/select}}
</select>
<select class="select" name="data.approaches.charismatic">
{{#select data.approaches.charismatic}}
<option value="4">{{ localize 'EFS.DicePrefix' }}4</option>
<option value="6">{{ localize 'EFS.DicePrefix' }}6</option>
<option value="8">{{ localize 'EFS.DicePrefix' }}8</option>
<option value="10">{{ localize 'EFS.DicePrefix' }}10</option>
<option value="12">{{ localize 'EFS.DicePrefix' }}12</option>
{{/select}}
</select>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="items">
<h2 class="control-header">{{localize 'EFS.Items'}} <span
class="fa fa-plus add-item clickable"></span></h2>
<div class="item-list">
{{#each items as |item|}}
<div class="item-name">
<span class="item clickable regular" data-id="{{item._id}}">
{{item.name}} {{#if (gt item.data.dice 0)}}{{ localize 'EFS.DicePrefix'
}}{{item.data.dice}}{{/if}}</span>
<span class="item-control">
<span data-id="{{item._id}}" class="edit-item clickable fa fa-edit"></span>
<span data-id="{{item._id}}" class="delete-item clickable fa fa-trash"></span>
</span>
</div>

<div class="item-description">{{{item._system.description}}}</div>
<hr/>
{{/each}}
</div>
</div>
</div>
</div>
</div>
Expand Down
19 changes: 9 additions & 10 deletions templates/sheets/efs-item-sheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@
<input name="name" class="efs text-input" value="{{item.name}}"/>
</div>
<div>
<span class="efs label">{{ localize 'EFS.Item.Modifier' }}</span>
<select class="efs select" name="data.modifier">
{{#select data.modifier}}
<option value="0">+0</option>
<option value="1">+1</option>
<option value="2">+2</option>
<option value="3">+3</option>
<span class="efs label">{{ localize 'EFS.Item.Dice' }}</span>
<select class="efs select" name="data.dice">
{{#select data.dice}}
<option value="0">{{ localize 'EFS.Item.NoDice' }}</option>
<option value="4">{{ localize 'EFS.DicePrefix' }}4</option>
<option value="6">{{ localize 'EFS.DicePrefix' }}6</option>
<option value="8">{{ localize 'EFS.DicePrefix' }}8</option>
<option value="10">{{ localize 'EFS.DicePrefix' }}10</option>
<option value="12">{{ localize 'EFS.DicePrefix' }}12</option>
{{/select}}
</select>
</div>
</div>
<div class="flex">
<img src="{{item.img}}" data-edit="img" title="{{item.name}}" height="128"/>
</div>
</div>
<h2>{{ localize 'EFS.Description' }}</h2>
{{editor data.description target="system.description" button=true editable=true}}
Expand Down
17 changes: 0 additions & 17 deletions templates/sheets/extra-dialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,5 @@ <h2>{{localize 'EFS.Description'}}</h2>
{{editor data.extra.description target="system.extra.description" button=true editable=true}}
</div>
</div>
<div class="items">
<h2 class="control-header">{{localize 'EFS.Items'}} <span class="fa fa-plus add-item clickable"></span></h2>
<div class="item-list">
{{#each items as |item|}}
<div class="item-name">
<b>{{item.name}} {{#if (gt item._system.modifier 0)}}+{{item._system.modifier}}{{/if}}</b>
<span class="item-control">
<span data-id="{{item._id}}" class="edit-item clickable fa fa-edit"></span>
<span data-id="{{item._id}}" class="delete-item clickable fa fa-trash"></span>
</span>
</div>

<div class="item-description">{{{item._system.description}}}</div>
<hr/>
{{/each}}
</div>
</div>
</section>
</form>

0 comments on commit 654a292

Please sign in to comment.