Skip to content

Commit

Permalink
Background items and migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Muttley committed Sep 23, 2023
1 parent 108e7a9 commit 273b64d
Show file tree
Hide file tree
Showing 33 changed files with 252 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"value": 3
}
},
"background": "Sailor",
"background": "Compendium.shadowdark.backgrounds.Item.4QQNmFHKVIY6aOpW",
"bonuses": {
"acBonus": 0,
"advantage": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"value": 7
}
},
"background": "Jeweler",
"background": "Compendium.shadowdark.backgrounds.Item.2bf6cUSTzdI7CMHE",
"bonuses": {
"acBonus": 0,
"advantage": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
"value": 5
}
},
"background": "Urchin",
"background": "Compendium.shadowdark.backgrounds.Item.jkZbwzeer9YNCf29",
"bonuses": {
"acBonus": 0,
"advantage": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
"value": 10
}
},
"background": "Soldier",
"background": "Compendium.shadowdark.backgrounds.Item.UlC61DRdwHpl8dpt",
"bonuses": {
"acBonus": 0,
"advantage": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
"value": 3
}
},
"background": "Noble",
"background": "Compendium.shadowdark.backgrounds.Item.sBbHjpCaF0iIoDNM",
"bonuses": {
"acBonus": 0,
"advantage": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"value": 3
}
},
"background": "Scout",
"background": "Compendium.shadowdark.backgrounds.Item.FRz7qiokf1r9BcjJ",
"bonuses": {
"acBonus": 0,
"advantage": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
"value": 8
}
},
"background": "Ranger",
"background": "Compendium.shadowdark.backgrounds.Item.lFoVSBNURSvYTb4U",
"bonuses": {
"acBonus": 0,
"advantage": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
"value": 3
}
},
"background": "Wanted",
"background": "Compendium.shadowdark.backgrounds.Item.eRi9oX0cqwQwV7tk",
"bonuses": {
"acBonus": 0,
"advantage": [
Expand Down
2 changes: 1 addition & 1 deletion i18n/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ SHADOWDARK.sheet.npc.tab.description: Beschreibung
SHADOWDARK.sheet.player.active_effect_override: This value is being modified by an Active Effect and cannot be edited. Disable the effect to edit it.
SHADOWDARK.sheet.player.ancestry.label: Abstammung
SHADOWDARK.sheet.player.available_spells: Verfügbare Zauber
SHADOWDARK.sheet.player.background: Hintergrund
SHADOWDARK.sheet.player.background.label: Hintergrund
SHADOWDARK.sheet.player.class: Klasse
SHADOWDARK.sheet.player.deity: Gottheit
SHADOWDARK.sheet.player.languages: Sprachen
Expand Down
5 changes: 4 additions & 1 deletion i18n/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ SHADOWDARK.dialog.select_ancestry.prompt: Select Ancestry...
SHADOWDARK.dialog.select_ancestry.title: Choose Ancestry
SHADOWDARK.dialog.select_armor_property.prompt: Select Armor Property...
SHADOWDARK.dialog.select_armor_property.title: Choose Armor Properties
SHADOWDARK.dialog.select_background.prompt: Select Background...
SHADOWDARK.dialog.select_background.title: Choose Background
SHADOWDARK.dialog.select_class.prompt: Select Class...
SHADOWDARK.dialog.select_class.title: Choose Class
SHADOWDARK.dialog.select_languages.prompt: Select Language...
Expand Down Expand Up @@ -504,7 +506,8 @@ SHADOWDARK.sheet.player.active_effect_override: This value is being modified by
SHADOWDARK.sheet.player.ancestry.label: Ancestry
SHADOWDARK.sheet.player.ancestry.tooltip: Your character's job
SHADOWDARK.sheet.player.available_spells: Available Spells
SHADOWDARK.sheet.player.background: Background
SHADOWDARK.sheet.player.background.label: Background
SHADOWDARK.sheet.player.background.tooltip: Your history and past experience. You are adept at tasks related to your background.
SHADOWDARK.sheet.player.class.label: Class
SHADOWDARK.sheet.player.class.tooltip: Your character's cultural and ancestral heritage
SHADOWDARK.sheet.player.deity: Deity
Expand Down
2 changes: 1 addition & 1 deletion i18n/es.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ SHADOWDARK.sheet.npc.tab.description: Descripción
SHADOWDARK.sheet.player.active_effect_override: Este valor está siendo modificado por un efecto activo y no puede ser editado. Deshabilita el efecto para editarlo.
SHADOWDARK.sheet.player.ancestry.label: Ancestría
SHADOWDARK.sheet.player.available_spells: Hechizos disponibles
SHADOWDARK.sheet.player.background: Trasfondo
SHADOWDARK.sheet.player.background.label: Trasfondo
SHADOWDARK.sheet.player.class: Clase
SHADOWDARK.sheet.player.deity: Deidad
SHADOWDARK.sheet.player.languages: Idiomas
Expand Down
2 changes: 1 addition & 1 deletion i18n/fi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ SHADOWDARK.sheet.npc.tab.description: Kuvaus
SHADOWDARK.sheet.player.active_effect_override: Tähän arvoon vaikuttaa aktiivinen efekti, eikä sitä pystytä juuri nyt muokkamaan. Disabloi kyseinen efekti muokataksesi arvoa.
SHADOWDARK.sheet.player.ancestry.label: Laji
SHADOWDARK.sheet.player.available_spells: Saatavilla olevat loitsut
SHADOWDARK.sheet.player.background: Tausta
SHADOWDARK.sheet.player.background.label: Tausta
SHADOWDARK.sheet.player.class: Hahmoluokka
SHADOWDARK.sheet.player.deity: Jumala
SHADOWDARK.sheet.player.languages: Kielet
Expand Down
2 changes: 1 addition & 1 deletion i18n/fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ SHADOWDARK.sheet.npc.tab.description: Description
SHADOWDARK.sheet.player.active_effect_override: This value is being modified by an Active Effect and cannot be edited. Disable the effect to edit it.
SHADOWDARK.sheet.player.ancestry.label: Ascendance
SHADOWDARK.sheet.player.available_spells: Available Spells
SHADOWDARK.sheet.player.background: Historique
SHADOWDARK.sheet.player.background.label: Historique
SHADOWDARK.sheet.player.class: Classe
SHADOWDARK.sheet.player.deity: Croyance
SHADOWDARK.sheet.player.languages: Langues
Expand Down
2 changes: 1 addition & 1 deletion i18n/ko.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ SHADOWDARK.sheet.npc.tab.description: 설명
SHADOWDARK.sheet.player.active_effect_override: 이것은 현재 활성화된 효과에 의해 변경된 것이며 수정할 수 없습니다. 수정하려면 해당 효과를 비활성화하세요.
SHADOWDARK.sheet.player.ancestry.label: 선조
SHADOWDARK.sheet.player.available_spells: 시전 가능한 주문
SHADOWDARK.sheet.player.background: 배경
SHADOWDARK.sheet.player.background.label: 배경
SHADOWDARK.sheet.player.class: 클래스
SHADOWDARK.sheet.player.deity:
SHADOWDARK.sheet.player.languages: 언어
Expand Down
2 changes: 1 addition & 1 deletion i18n/sv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ SHADOWDARK.sheet.npc.tab.description: Beskrivning
SHADOWDARK.sheet.player.active_effect_override: Detta värde ändras av en aktiv effekt och kan inte redigeras. Inaktivera effekten för att redigera den.
SHADOWDARK.sheet.player.ancestry.label: Ursprung
SHADOWDARK.sheet.player.available_spells: Tillgängliga besvärjelser
SHADOWDARK.sheet.player.background: Bakgrund
SHADOWDARK.sheet.player.background.label: Bakgrund
SHADOWDARK.sheet.player.class: Klass
SHADOWDARK.sheet.player.deity: Gud
SHADOWDARK.sheet.player.languages: Språk
Expand Down
10 changes: 8 additions & 2 deletions scss/sheets/actors/_player.scss
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,18 @@
}

.pc_ancestry,
.pc_background,
.pc_class,
.pc_languages {
.pc_languages{
grid-template-columns: min-content min-content 1fr;
align-items: center;
}

.pc_title {
grid-template-columns: min-content 1fr;
align-items: center;
}

.detail-value {
text-align: left;
}
Expand Down Expand Up @@ -708,7 +714,7 @@

.uuid-link {
margin: 4px;
text-align: center;
// text-align: center;
}

.xp-score {
Expand Down
15 changes: 15 additions & 0 deletions scss/ui/_compendium-item-selector.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,18 @@
}

}

.fake-uuid-link {
background: #DDD;
padding: 1px 4px;
border: 1px solid var(--color-border-dark-tertiary);
margin: 4px;
border-radius: 2px;
white-space: nowrap;
word-break: break-all;

&:hover {
cursor: auto;
text-shadow: none;
}
}
34 changes: 34 additions & 0 deletions system/src/apps/CompendiumItemSelectors/BackgroundSelector.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import CompendiumItemSelector from "../CompendiumItemSelector";

export default class BackgroundSelector extends CompendiumItemSelector {

closeOnSelection = true;

maxChoices = 1;

get prompt() {
return game.i18n.localize("SHADOWDARK.dialog.select_background.prompt");
}

get title() {
return game.i18n.localize("SHADOWDARK.dialog.select_background.title");
}

async getAvailableItems() {
return await shadowdark.compendiums.backgrounds();
}

async getUuids() {
const uuid = this.object?.system?.background;

return uuid !== "" ? [uuid] : [];
}

async saveUuids(uuids) {
const uuid = uuids[0] ?? "";

return this.object.update({
"system.background": uuid,
});
}
}
1 change: 1 addition & 0 deletions system/src/apps/CompendiumItemSelectors/_module.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export {default as AncestrySelector} from "./AncestrySelector.mjs";
export {default as ArmorPropertySelector} from "./ArmorPropertySelector.mjs";
export {default as BackgroundSelector} from "./BackgroundSelector.mjs";
export {default as ClassSelector} from "./ClassSelector.mjs";
export {default as LanguageSelector} from "./LanguageSelector.mjs";
export {default as WeaponPropertySelector} from "./WeaponPropertySelector.mjs";
1 change: 1 addition & 0 deletions system/src/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ SHADOWDARK.DEFAULTS = {
ITEM_IMAGES: {
Ancestry: "icons/environment/people/group.webp",
Armor: "icons/equipment/chest/breastplate-banded-steel-gold.webp",
Background: "icons/environment/people/commoner.webp",
Basic: "icons/containers/bags/pouch-simple-brown.webp",
Class: "icons/sundries/documents/document-sealed-brown-red.webp",
Effect: "icons/commodities/tech/cog-brass.webp",
Expand Down
27 changes: 16 additions & 11 deletions system/src/documents/ActorSD.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export default class ActorSD extends Actor {
this.update({"system.ancestry": item.uuid});
}

async addClass(item) {
this.update({"system.class": item.uuid});
}

async addLanguage(item) {
let languageFound = false;
for (const language of await this.languageItems()) {
Expand Down Expand Up @@ -495,16 +499,6 @@ export default class ActorSD extends Actor {
return characterClass && spellcastingAbility !== "" ? true : false;
}

/** @inheritDoc */
// prepareBaseData() {
// switch (this.type) {
// case "Player":
// return this._preparePlayerData();
// case "NPC":
// return this._prepareNPCData();
// }
// }

/** @inheritDoc */
prepareData() {
super.prepareData();
Expand Down Expand Up @@ -976,7 +970,18 @@ export default class ActorSD extends Actor {
}
}

console.log("done");
this.backgroundItems.title = "";
if (this.backgroundItems.class && this.system.alignment !== "") {
const titles = this.backgroundItems.class.system.titles ?? [];
const level = this.system.level?.value ?? 0;

for (const title of titles) {
if (level >= title.from && level <= title.to) {
this.backgroundItems.title = title[this.system.alignment];
break;
}
}
}
}

_preparePlayerData() {
Expand Down
4 changes: 4 additions & 0 deletions system/src/documents/CompendiumsSD.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export default class CompendiumsSD {
return CompendiumsSD.properties("armor", sources);
}

static async backgrounds(sources=[]) {
return CompendiumsSD._documents("Item", "Background", sources);
}

static async baseArmor(sources=[]) {
const documents = await CompendiumsSD._documents("Item", "Armor", sources);

Expand Down
2 changes: 1 addition & 1 deletion system/src/migrations/updates/Update_230920_1.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class Update_230920_1 extends UpdateBaseSD {

const updateData = {
"system.class": "",
"system.=-spellcastingAbility": null,
"system.-=spellcastingAbility": null,
};

const currentValue = actorData.system?.class ?? "";
Expand Down
11 changes: 11 additions & 0 deletions system/src/migrations/updates/Update_230922_1.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { UpdateBaseSD } from "../UpdateBaseSD.mjs";

export default class Update_230922_1 extends UpdateBaseSD {
static version = 230922.1;

async updateActor(actorData) {
if (actorData.type !== "Player") return;

return {"system.-=title": null};
}
}
48 changes: 48 additions & 0 deletions system/src/migrations/updates/Update_230923_1.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { UpdateBaseSD } from "../UpdateBaseSD.mjs";

// Migrates a character actor's Ancesty from a free text field to a uuid
// compendium link
//
// Attempts to match any current value to a uuid compendium link if there is
// a match on the slugified names

export default class Update_230923_1 extends UpdateBaseSD {
static version = 230923.1;

async updateActor(actorData) {
if (actorData.type !== "Player") return;

const updateData = {
"system.background": "",
};

const currentValue = actorData.system?.background ?? "";

if (currentValue !== "") {
const itemLut = {};
(await shadowdark.compendiums.backgrounds()).forEach(
item => itemLut[item.name.slugify()] = item.uuid
);

const matchingItem = itemLut[currentValue.slugify()];

if (matchingItem) {
updateData["system.background"] = matchingItem;
}
else {
ui.notifications.warn(
game.i18n.format(
"Background '{itemName}' for Character '{name}' does not exist in a compendium; you will need to create this Item and update the Character manually.",
{
itemName: currentValue,
name: actorData.name,
}
),
{permanent: true}
);
}
}

return updateData;
}
}
2 changes: 2 additions & 0 deletions system/src/migrations/updates/_module.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export {default as Update_230915_1} from "./Update_230915_1.mjs";
export {default as Update_230915_2} from "./Update_230915_2.mjs";
export {default as Update_230916_1} from "./Update_230916_1.mjs";
export {default as Update_230920_1} from "./Update_230920_1.mjs";
export {default as Update_230922_1} from "./Update_230922_1.mjs";
export {default as Update_230923_1} from "./Update_230923_1.mjs";
3 changes: 3 additions & 0 deletions system/src/sheets/ActorSheetSD.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ export default class ActorSheetSD extends ActorSheet {
case "ancestry":
new select.AncestrySelector(this.actor).render(true);
break;
case "background":
new select.BackgroundSelector(this.actor).render(true);
break;
case "class":
new select.ClassSelector(this.actor).render(true);
break;
Expand Down
Loading

0 comments on commit 273b64d

Please sign in to comment.