Skip to content

Commit 1cfb762

Browse files
committed
Add custom add item dialog.
1 parent a00ad81 commit 1cfb762

File tree

14 files changed

+220
-80
lines changed

14 files changed

+220
-80
lines changed

css/deathinspace.css

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,12 @@
13481348
text-align: center;
13491349
text-transform: uppercase;
13501350
}
1351-
1351+
.ability-check-dialog {
1352+
border: 2px solid var(--character-background-color);
1353+
}
1354+
.add-item-dialog {
1355+
border: 2px solid var(--character-background-color);
1356+
}
13521357
.deathinspace.app.window-app .window-content {
13531358
background: url(../assets/images/ui/seamless_paper_texture.png) repeat;
13541359
}
@@ -1396,8 +1401,11 @@
13961401
box-shadow: 0 0 5px var(--highlight-background-color);
13971402
text-shadow: 0 0 10px var(--highlight-background-color);
13981403
}
1404+
.deathinspace.app.window-app.dialog {
1405+
background: url(../assets/images/ui/seamless_paper_texture.png) repeat;
1406+
}
1407+
13991408
.custom-dialog {
1400-
border: 2px solid var(--character-background-color);
14011409
color: var(--foreground-color);
14021410
font-family: var(--text-font);
14031411
margin: 0;

lang/en.json

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
2-
"DIS.AbilityBody": "Body",
3-
"DIS.Add": "Add",
42
"DIS.Ability": "Ability",
3+
"DIS.AbilityBody": "Body",
4+
"DIS.AbilityDexterity": "Dexterity",
5+
"DIS.AbilitySavvy": "Savvy",
6+
"DIS.AbilityTech": "Tech",
57
"DIS.AbilityCheck": "Ability Check",
8+
"DIS.Add": "Add",
9+
"DIS.AddItem": "Add Item",
610
"DIS.Ammo": "Ammo",
711
"DIS.Appearance": "Appearance",
812
"DIS.ArmorType": "Armor Type",
@@ -56,11 +60,18 @@
5660
"DIS.HubRegainHelp3": "On a calm night up to maximum",
5761
"DIS.HubSheetTitle": "Hub Data Sheet",
5862
"DIS.ItemBroken": "Item broken",
63+
"DIS.ItemName": "Item Name",
64+
"DIS.ItemType": "Item Type",
65+
"DIS.ItemTypeArmor": "Armor",
66+
"DIS.ItemTypeEquipment": "Equipment",
67+
"DIS.ItemTypeWeapon": "Weapon",
5968
"DIS.LifeSupport": "Life Support",
6069
"DIS.Looks": "Looks",
6170
"DIS.Max": "Max",
6271
"DIS.Modules": "Modules",
6372
"DIS.Morale": "Morale",
73+
"DIS.MoraleFailure": "Parley or flee",
74+
"DIS.MoraleSuccess": "Stands firm",
6475
"DIS.Name": "Name",
6576
"DIS.NpcSheetTitle": "NPC Sheet",
6677
"DIS.Opponent": "Opponent",
@@ -78,17 +89,23 @@
7889
"DIS.PowerTotalHelp1": "The power cost sum should not",
7990
"DIS.PowerTotalHelp2": "exceed the output power.",
8091
"DIS.ProtectsAgainst": "Protects Against",
81-
"DIS.RollType": "Roll Type",
82-
"DIS.RollTypeAdvantage": "Advantage",
83-
"DIS.RollTypeDisadvantage": "Disadvantage",
84-
"DIS.RollTypeNormal": "Normal",
8592
"DIS.Quirks": "Quirks",
93+
"DIS.Reaction": "Reaction",
94+
"DIS.ReactionHelpful": "Helpful",
95+
"DIS.ReactionHostile": "Hostile",
96+
"DIS.ReactionTalkative": "Talkative",
97+
"DIS.ReactionUnfriendly": "Unfriendly",
98+
"DIS.ReactionUncertain": "Uncertain",
8699
"DIS.Regenerate": "Regenerate",
87100
"DIS.RegenerateWarning": "This will destroy your existing character and replace it with a newly generated one. This cannot be undone.",
88101
"DIS.RiskyAttack": "Risky Attack",
89102
"DIS.RiskyAttackFailure": "Risky attack fails! Opponent gets immediate counterattack and chooses next initiative.",
90103
"DIS.RiskyAttackSuccess": "Risky attack adds a die of damage.",
91104
"DIS.Roll": "Roll",
105+
"DIS.RollType": "Roll Type",
106+
"DIS.RollTypeAdvantage": "Advantage",
107+
"DIS.RollTypeDisadvantage": "Disadvantage",
108+
"DIS.RollTypeNormal": "Normal",
92109
"DIS.Section0Name": "Section 0. Name",
93110
"DIS.SheetClassCharacter": "Death in Space Character Sheet",
94111
"DIS.SheetClassHub": "Death in Space Hub Sheet",

module/actor/actor.js

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import AbilityCheckDialog from "../dialog/ability-check-dialog.js";
2+
import AddItemDialog from "../dialog/add-item-dialog.js";
23
import AttackDialog from "../dialog/attack-dialog.js";
34
import { diceSound, showDice } from "../dice.js";
45
import { regenerateCharacter, regenerateNpc } from "../generator.js";
@@ -132,6 +133,12 @@ export class DISActor extends Actor {
132133
return this.showAbilityCheckDialog("tech");
133134
}
134135

136+
async showAddItemDialog() {
137+
const dialog = new AddItemDialog();
138+
dialog.actor = this;
139+
dialog.render(true);
140+
}
141+
135142
async showAbilityCheckDialog(ability) {
136143
const checkDialog = new AbilityCheckDialog();
137144
checkDialog.actor = this;
@@ -375,33 +382,73 @@ export class DISActor extends Actor {
375382
});
376383
}
377384

378-
async rollNpcDamage() {
379-
if (!this.data.data.damage) {
380-
return;
385+
async rollNpcMorale() {
386+
const cardTitle = `${game.i18n.localize("Morale")} ${game.i18n.localize(
387+
"DIS.Check"
388+
)}`;
389+
const moraleText = `2D6 ${game.i18n.localize("Vs")} ${game.i18n.localize(
390+
"Morale"
391+
)}`;
392+
const moraleRoll = new Roll("2d6");
393+
moraleRoll.evaluate({ async: false });
394+
await showDice(moraleRoll);
395+
let moraleOutcome;
396+
if (moraleRoll.total > this.data.data.morale) {
397+
moraleOutcome = game.i18n.localize("DIS.MoraleFailure");
398+
} else {
399+
moraleOutcome = game.i18n.localize("DIS.MoraleSuccess");
381400
}
382-
const roll = new Roll(this.data.data.damage);
383-
roll.toMessage({
384-
user: game.user.id,
385-
speaker: ChatMessage.getSpeaker({ actor: this }),
386-
flavor: `${this.data.data.attack} damage`,
387-
});
388-
}
389401

390-
async rollNpcMorale() {
391-
const roll = new Roll("2d6");
392-
roll.toMessage({
393-
user: game.user.id,
402+
const chatData = {
403+
cardTitle,
404+
moraleOutcome,
405+
moraleText,
406+
moraleRoll,
407+
};
408+
const html = await renderTemplate(
409+
"systems/deathinspace/templates/chat/morale.html",
410+
chatData
411+
);
412+
ChatMessage.create({
413+
content: html,
414+
sound: diceSound(),
394415
speaker: ChatMessage.getSpeaker({ actor: this }),
395-
flavor: `Morale`,
396416
});
397417
}
398418

399419
async rollNpcReaction() {
400-
const roll = new Roll("2d6");
401-
roll.toMessage({
402-
user: game.user.id,
420+
const cardTitle = `${game.i18n.localize("Reaction")}`;
421+
const reactionText = "2D6";
422+
const reactionRoll = new Roll("2d6");
423+
reactionRoll.evaluate({ async: false });
424+
await showDice(reactionRoll);
425+
let reactionOutcome;
426+
if (reactionRoll.total === 2) {
427+
reactionOutcome = game.i18n.localize("DIS.ReactionHostile");
428+
} else if (reactionRoll.total <= 5) {
429+
reactionOutcome = game.i18n.localize("DIS.ReactionUnfriendly");
430+
} else if (reactionRoll.total <= 8) {
431+
reactionOutcome = game.i18n.localize("DIS.ReactionUncertain");
432+
} else if (reactionRoll.total <= 11) {
433+
reactionOutcome = game.i18n.localize("DIS.ReactionTalkative");
434+
} else {
435+
reactionOutcome = game.i18n.localize("DIS.ReactionHelpful");
436+
}
437+
438+
const chatData = {
439+
cardTitle,
440+
reactionOutcome,
441+
reactionText,
442+
reactionRoll,
443+
};
444+
const html = await renderTemplate(
445+
"systems/deathinspace/templates/chat/reaction.html",
446+
chatData
447+
);
448+
ChatMessage.create({
449+
content: html,
450+
sound: diceSound(),
403451
speaker: ChatMessage.getSpeaker({ actor: this }),
404-
flavor: `Reaction`,
405452
});
406453
}
407454

module/actor/sheet/actor-sheet.js

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -63,35 +63,11 @@ export default class DISActorSheet extends ActorSheet {
6363
}
6464

6565
/**
66-
* +Add for belongings tab
66+
* +Add button for belongings tab
6767
*/
6868
async _onAddBelonging(event) {
69-
console.log("_onAddBelonging ****");
7069
event.preventDefault();
71-
const template =
72-
"systems/deathinspace/templates/dialog/add-item-dialog.html";
73-
const dialogData = {
74-
config: CONFIG.DeathInSpace,
75-
};
76-
const html = await renderTemplate(template, dialogData);
77-
return new Promise((resolve) => {
78-
new Dialog({
79-
title: game.i18n.localize("Create New Item"),
80-
content: html,
81-
buttons: {
82-
create: {
83-
icon: '<i class="fas fa-check"></i>',
84-
label: game.i18n.localize("Create New Item"),
85-
callback: (html) =>
86-
resolve(
87-
_createBelongingItem(this.actor, html[0].querySelector("form"))
88-
),
89-
},
90-
},
91-
default: "create",
92-
close: () => resolve(null),
93-
}).render(true);
94-
});
70+
this.actor.showAddItemDialog();
9571
}
9672

9773
_onWeaponRoll(event) {
@@ -157,15 +133,3 @@ export default class DISActorSheet extends ActorSheet {
157133
}
158134
}
159135
}
160-
161-
/**
162-
* Create a new Owned Item for the given actor, based on the name/type from the form.
163-
*/
164-
const _createBelongingItem = (actor, form) => {
165-
const itemData = {
166-
name: form.itemname.value,
167-
type: form.itemtype.value,
168-
data: {},
169-
};
170-
actor.createEmbeddedDocuments("Item", [itemData]);
171-
};

module/dialog/add-item-dialog.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export default class AddItemDialog extends Application {
2+
/** @override */
3+
static get defaultOptions() {
4+
const options = super.defaultOptions;
5+
options.id = "add-item-dialog";
6+
options.classes = ["deathinspace"];
7+
options.title = game.i18n.localize("DIS.AddItem");
8+
options.template =
9+
"systems/deathinspace/templates/dialog/add-item-dialog.html";
10+
options.width = 420;
11+
options.height = "auto";
12+
return options;
13+
}
14+
15+
/** @override */
16+
activateListeners(html) {
17+
super.activateListeners(html);
18+
html.find(".add-item-button").click(this._onAddItem.bind(this));
19+
}
20+
21+
async _onAddItem(event) {
22+
event.preventDefault();
23+
const form = $(event.currentTarget).parents(".add-item-dialog")[0];
24+
const itemData = {
25+
name: form.itemname.value,
26+
type: form.itemtype.value,
27+
data: {},
28+
};
29+
await this.actor.createEmbeddedDocuments("Item", [itemData]);
30+
this.close();
31+
}
32+
}

source/templates/chat/morale.pug

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
form.roll-card.morale-card
2+
.card-title
3+
| {{cardTitle}}
4+
.morale-roll
5+
.roll-title
6+
| {{moraleText}}
7+
.roll-result
8+
span
9+
| {{xtotal moraleRoll}}
10+
.outcome-text
11+
.morale-outcome
12+
| {{moraleOutcome}}

source/templates/chat/reaction.pug

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
form.roll-card.reaction-card
2+
.card-title
3+
| {{cardTitle}}
4+
.reaction-roll
5+
.roll-title
6+
| {{reactionText}}
7+
.roll-result
8+
span
9+
| {{xtotal reactionRoll}}
10+
.outcome-text
11+
.reaction-outcome
12+
| {{reactionOutcome}}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.ability-check-dialog {
2+
border: 2px solid var(--character-background-color);
3+
}
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
form.custom-dialog(action="")
1+
form.custom-dialog.add-item-dialog(action="")
22
.form-group
3-
label Name
4-
input(type="text" name="itemname" value="" placeholder="Name" data-dtype="String")
3+
label {{ localize "DIS.ItemName" }}
4+
input(type="text" name="itemname" value="" placeholder="{{ localize 'DIS.Name' }}" data-dtype="String")
5+
56
.form-group
6-
label Type
7+
label {{ localize "DIS.ItemType" }}
78
select.add-type(name="itemtype")
8-
option armor
9-
option(selected=true) equipment
10-
option weapon
9+
option(value="armor") {{ localize "DIS.ItemTypeArmor" }}
10+
option(value="equipment" selected=true) {{ localize "DIS.ItemTypeEquipment" }}
11+
option(value="weapon") {{ localize "DIS.ItemTypeWeapon" }}
12+
13+
.button-row
14+
button(type="button" class="add-item-button" name="add-item-button")
15+
| {{ localize "DIS.Add" }}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
.add-item-dialog {
3+
border: 2px solid var(--character-background-color);
4+
}

0 commit comments

Comments
 (0)