Skip to content

Commit

Permalink
Add styling to equipment section
Browse files Browse the repository at this point in the history
Styles equipmen section with colour coded items. sorts items based
on item type and item name.
  • Loading branch information
StasTserk committed Jul 4, 2020
1 parent d30cda2 commit 1fdaaa4
Show file tree
Hide file tree
Showing 17 changed files with 224 additions and 101 deletions.
31 changes: 25 additions & 6 deletions module/character-sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ export class BWCharacterSheet extends BWActorSheet {

data.beliefs = beliefs;
data.instincts = instincts;
data.skills = skills;
data.training = training;
data.relationships = relationships;
data.equipment = equipment;
data.melee = melee;
data.skills = skills.sort(byName);
data.training = training.sort(byName);
data.relationships = relationships.sort(byName);
data.equipment = equipment.sort(equipmentCompare);
data.melee = melee.sort(weaponCompare);
data.armor = this.getArmorDictionary(armor);
data.ranged = ranged;
data.ranged = ranged.sort(weaponCompare);

const traitLists = { character: [], die: [], callon: [] } as CharacterSheetTraits;

Expand Down Expand Up @@ -243,6 +243,25 @@ async function rollCallback(
});
}

function equipmentCompare(a: Item, b: Item): number {
if (constants.equipmentSheetOrder[a.type] !== constants.equipmentSheetOrder[b.type]) {
return constants.equipmentSheetOrder[a.type] > constants.equipmentSheetOrder[b.type] ? 1 : -1;
}
return a.name.localeCompare(b.name);
}

function weaponCompare(a: Item, b: Item): number {
if (a.name === "Bare Fist") {
return -1;
}
if (b.name === "Bare Fist") {
return 1;
}
return a.name.localeCompare(b.name);
}

const byName = (a: Item, b: Item) => a.name.localeCompare(b.name);

interface CharacterSheetData extends ActorSheetData {
equipment: Item[];
melee: MeleeWeapon[];
Expand Down
10 changes: 9 additions & 1 deletion module/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,12 @@ export const armorLocations = [
"left leg",
"shield"
];
export const armorLocationSelect = toDictionary(armorLocations);
export const armorLocationSelect = toDictionary(armorLocations);

export const equipmentSheetOrder = {
"melee weapon": 1,
"ranged weapon": 1,
"armor": 2,
"posession": 3,
"property": 4
}
8 changes: 7 additions & 1 deletion module/items/armor.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { DisplayClass } from "./item.js";

export class Armor extends Item {
prepareData() {
this.data.data.cssClass = "equipment-armor";
}

data: ArmorRootData;
}

export interface ArmorRootData extends BaseEntityData {
data: ArmorData
}

export interface ArmorData {
export interface ArmorData extends DisplayClass {
quality: string;
location: string;
dice: string; // as number
Expand Down
37 changes: 22 additions & 15 deletions module/items/item.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Armor } from "./armor.js";
import { MeleeWeapon } from "./meleeWeapon.js";
import { Possession } from "./posession.js";
import { Property } from "./property.js";
import { RangedWeapon } from "./rangedWeapon.js";
import { Relationship } from "./relationship.js";
import { ArmorSheet } from "./sheets/armor-sheet.js";
Expand All @@ -17,6 +20,8 @@ export * from "./armor.js";
export * from "./belief.js";
export * from "./instinct.js";
export * from "./meleeWeapon.js";
export * from "./posession.js";
export * from "./property.js";
export * from "./rangedWeapon.js";
export * from "./relationship.js";
export * from "./sheets/armor-sheet.js";
Expand All @@ -34,21 +39,8 @@ export * from "./trait.js";
export class BWItem extends Item {
prepareData() {
super.prepareData();
switch (this.type) {
case "trait":
Trait.prototype.prepareData.bind(this)();
break;
case "skill":
Skill.prototype.prepareData.bind(this)();
break;
case "relationship":
Relationship.prototype.prepareData.bind(this)();
break;
case "melee weapon":
MeleeWeapon.prototype.prepareData.bind(this)();
break;
case "ranged weapon":
RangedWeapon.prototype.prepareData.bind(this)();
if (prototypeList[this.type]) {
prototypeList[this.type].prototype.prepareData.bind(this)();
}
}
}
Expand All @@ -59,6 +51,10 @@ export interface ArthaEarner {
deeds: boolean;
}

export interface DisplayClass {
cssClass?: string;
}

export function RegisterItemSheets() {
Items.unregisterSheet("core", ItemSheet);
Items.registerSheet("burningwheel", BeliefSheet, {
Expand Down Expand Up @@ -105,3 +101,14 @@ export function RegisterItemSheets() {
makeDefault: true
});
}

const prototypeList: { [i: string]: typeof Item} = {
"trait": Trait,
"skill": Skill,
"relationship": Relationship,
"melee weapon": MeleeWeapon,
"ranged weapon": RangedWeapon,
"armor": Armor,
"posession": Possession,
"property": Property
}
4 changes: 3 additions & 1 deletion module/items/meleeWeapon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CharacterData } from "../actor.js";
import { DisplayClass } from "./item.js";

export class MeleeWeapon extends Item {
prepareData() {
Expand All @@ -9,6 +10,7 @@ export class MeleeWeapon extends Item {
this.data.data.mark = baseDmg;
this.data.data.superb = Math.floor(baseDmg * 1.5);
}
this.data.data.cssClass = "equipment-weapon";
}

data: MeleeWeaponRootData;
Expand All @@ -18,7 +20,7 @@ export interface MeleeWeaponRootData extends BaseEntityData {
data: MeleeWeaponData
}

export interface MeleeWeaponData {
export interface MeleeWeaponData extends DisplayClass {
quality: string;
baseOb: string; // as number
power: string; // as number
Expand Down
19 changes: 19 additions & 0 deletions module/items/posession.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { DisplayClass } from "./item.js";

export class Possession extends Item {
prepareData() {
this.data.data.cssClass = "equipment-possession";
}

data: PossessionRootData;
}

export interface PossessionRootData extends BaseEntityData {
data: PossessionData;
}

export interface PossessionData extends DisplayClass {
isToolkit: boolean;
isExpended: boolean;
description: string;
}
18 changes: 18 additions & 0 deletions module/items/property.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { DisplayClass } from "./item.js";

export class Property extends Item {
prepareData() {
this.data.data.cssClass = "equipment-property";
}

data: PropertyRootData;
}

export interface PropertyRootData extends BaseEntityData {
data: PropertyData;
}

export interface PropertyData extends DisplayClass {
isWorkshop: boolean;
description: string;
}
7 changes: 5 additions & 2 deletions module/items/rangedWeapon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CharacterData } from "module/actor";
import { CharacterData } from "../actor.js";
import { DisplayClass } from "./item.js";

export class RangedWeapon extends Item {
prepareData() {
Expand All @@ -15,6 +16,8 @@ export class RangedWeapon extends Item {
this.data.data.incidentalLabel = `1-${incidentalRange}`;
this.data.data.markLabel = (markRange - 1 === incidentalRange) ? `${markRange}` : `${incidentalRange + 1}-${markRange}`;
this.data.data.superbLabel = (markRange === 5 ) ? `6` : `${markRange + 1}-6`;

this.data.data.cssClass = "equipment-weapon";
}

data: RangedWeaponRootData;
Expand All @@ -24,7 +27,7 @@ export interface RangedWeaponRootData extends BaseEntityData{
data: RangedWeaponData
}

export interface RangedWeaponData {
export interface RangedWeaponData extends DisplayClass {
quality: string;
hasGunpowder: boolean;
usePower: boolean;
Expand Down
3 changes: 3 additions & 0 deletions styles/burningwheel.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
@import "./character/bits.scss";
@import "./character/character.scss";
@import "./character/equipment.scss";
@import "./character/learning.scss";
@import "./character/ptgs.scss";
@import "./character/relationships.scss";
@import "./character/weapons.scss";
@import "./items/relationship.scss";
@import "./items/skill.scss";
Expand Down
45 changes: 45 additions & 0 deletions styles/character/bits.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.beliefs, .instincts {
.bits-item {
& > div {
width: 13%;
border-right: 1px solid black;
margin-bottom: 2px;

.bits-item-name {
width: 100%;
}

input[type="checkbox"] {
width: 1em;
height: 1em;
margin: 0;
}
}
& > textarea {
width: 87%;
resize: vertical;
border: 0;
min-height: 3em;
height: 3em;
}
}
}

.traits {
.trait-category {
width: calc(33% - 10px);
margin: 5px;

i {
float: right;
font-size: 12px;
margin-top: 6px;
margin-left: 5px;
color: transparentize($color: black, $amount: 0.25)
}

i:hover {
color: #FF0000;
}
}
}
72 changes: 0 additions & 72 deletions styles/character/character.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,53 +53,6 @@
}
}
}

.beliefs, .instincts {
.bits-item {
& > div {
width: 13%;
border-right: 1px solid black;
margin-bottom: 2px;

.bits-item-name {
width: 100%;
}

input[type="checkbox"] {
width: 1em;
height: 1em;
margin: 0;
}
}
& > textarea {
width: 87%;
resize: vertical;
border: 0;
min-height: 3em;
height: 3em;
}
}
}

.traits {
.trait-category {
width: calc(33% - 10px);
margin: 5px;

i {
float: right;
font-size: 12px;
margin-top: 6px;
margin-left: 5px;
color: transparentize($color: black, $amount: 0.25)
}

i:hover {
color: #FF0000;
}
}
}


.stats, .attributes, .skills {
display: grid;
Expand Down Expand Up @@ -199,29 +152,4 @@
}
}
}

.relationship-section {
.relationships {
width: 40%;

.item-title {
width: calc(95% - 36px);
}

.relationship > i {
width: 18px;

&:hover {
color: red;
}
}
}
.reputations, .affiliations {
width: 30%;
}

.relationship-progress {
@include progress-ticks;
}
}
}
Loading

0 comments on commit 1fdaaa4

Please sign in to comment.