Skip to content

Commit

Permalink
Merge pull request #13419 from clevett/pendragon-v3.3
Browse files Browse the repository at this point in the history
Pendragon 6th Edition v3.3 - Pregens & npc handling
  • Loading branch information
BronsonHall authored Oct 15, 2024
2 parents 1b544d6 + dbf5383 commit 2e9244e
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 219 deletions.
2 changes: 1 addition & 1 deletion Pendragon6thEdition/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pendragon6thedition",
"version": "3.2.1",
"version": "3.3",
"description": "You need to run npm start to get the compilers going.",
"dependencies": {
"20": "^3.1.9",
Expand Down
217 changes: 108 additions & 109 deletions Pendragon6thEdition/pendragon.html

Large diffs are not rendered by default.

106 changes: 106 additions & 0 deletions Pendragon6thEdition/src/js/drag_and_drop/handle_npc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
const handle_npc = (page) => {
const attrs = [
"size",
"dexterity",
"strength",
"constitution",
"appearance",
"type",
"hit_points",
"knockdown",
"major_wound",
"unconscious",
"movement",
"armor_points",
"current_glory",
"healing_rate",
"glory_award",
"description",
"movement ",
"valorous modifier",
];

const update = getStaticUpdate(attrs, page);

update["character_name"] = page.name;
update["sheet_type"] = "npc";
update["flag_description"] = false;

["equipment", "arms", "abilities"].forEach((section) => {
const data = page.data[section];
if (data) {
const sectionUpdate = processDataArrays(data, (data) =>
update_item(data, getRow(section))
);
Object.assign(update, sectionUpdate);
} else update[`hide_${section}`] = "on";
});

if (page.data.attacks) {
const attacks = processDataArrays(page.data.attacks, (data) =>
update_attack(data)
);
Object.assign(update, attacks);

const parsed = parseJSON(page.data.attacks);
const attackSkills = parsed
.filter(({ skill, target_value }) => skill && target_value)
.map(({ skill, target_value }) => ({
name: skill.toLowerCase(),
target_value,
}));

if (attackSkills.length > 0) {
const askills = update_mix_section(attackSkills, "skills", combatSkills);
Object.assign(update, askills);
}
} else {
update["hide_attacks"] = "on";
}

if (page.data.skills) {
const dataSkills = update_mix_section(
page.data.skills,
"skills",
combatSkills
);
Object.assign(update, dataSkills);
} else {
update["hide_skills"] = "on";
}

if (page.data.passions) {
const passions = processDataArrays(
page.data.passions,
updateSection("passions")
);
Object.assign(update, passions);
} else {
update["hide_passions"] = "on";
}

if (page.data.traits) {
const dataTraits = update_mix_section(page.data.traits, "traits", traits);
Object.entries(personalityTraits).forEach(([positive, negative]) => {
const keys = Object.keys(dataTraits);
if (keys.includes(positive) && !keys.includes(negative)) {
const targetValue = dataTraits[positive];
dataTraits[negative] = 20 - targetValue;
} else if (!keys.includes(positive) && keys.includes(negative)) {
const targetValue = dataTraits[negative];
dataTraits[positive] = 20 - targetValue;
} else if (!keys.includes(positive) && !keys.includes(negative)) {
dataTraits[positive] = 10;
dataTraits[negative] = 10;
}
});

Object.assign(update, dataTraits);
} else {
update["hide_personality_traits"] = "on";
}

setAttrs(update, {
silent: true,
});
};
109 changes: 1 addition & 108 deletions Pendragon6thEdition/src/js/drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,113 +9,6 @@ const handle_equipment = (page) => handle_item(page, getRow("equipment"));

const handle_arms = (page) => handle_item(page, getRow("arms"));

const handle_npc = (page) => {
const attrs = [
"size",
"dexterity",
"strength",
"constitution",
"appearance",
"type",
"hit_points",
"knockdown",
"major_wound",
"unconscious",
"movement",
"armor_points",
"current_glory",
"healing_rate",
"glory_award",
"description",
"movement ",
"valorous modifier",
];

const update = getStaticUpdate(attrs, page);

update["character_name"] = page.name;
update["sheet_type"] = "npc";
update["flag_description"] = false;

["equipment", "arms", "abilities"].forEach((section) => {
const data = page.data[section];
if (data) {
const sectionUpdate = processDataArrays(data, (data) =>
update_item(data, getRow(section))
);
Object.assign(update, sectionUpdate);
} else update[`hide_${section}`] = "on";
});

if (page.data.attacks) {
const attacks = processDataArrays(page.data.attacks, (data) =>
update_attack(data)
);
Object.assign(update, attacks);

const parsed = parseJSON(page.data.attacks);
const attackSkills = parsed
.filter(({ skill, target_value }) => skill && target_value)
.map(({ skill, target_value }) => ({
name: skill.toLowerCase(),
target_value,
}));

if (attackSkills.length > 0) {
const askills = update_mix_section(attackSkills, "skills", combatSkills);
Object.assign(update, askills);
}
} else {
update["hide_attacks"] = "on";
}

if (page.data.skills) {
const dataSkills = update_mix_section(
page.data.skills,
"skills",
combatSkills
);
Object.assign(update, dataSkills);
} else {
update["hide_skills"] = "on";
}

if (page.data.passions) {
const passions = processDataArrays(
page.data.passions,
updateSection("passions")
);
Object.assign(update, passions);
} else {
update["hide_passions"] = "on";
}

if (page.data.traits) {
const dataTraits = update_mix_section(page.data.traits, "traits", traits);
Object.entries(personalityTraits).forEach(([positive, negative]) => {
const keys = Object.keys(dataTraits);
if (keys.includes(positive) && !keys.includes(negative)) {
const targetValue = dataTraits[positive];
dataTraits[negative] = 20 - targetValue;
} else if (!keys.includes(positive) && keys.includes(negative)) {
const targetValue = dataTraits[negative];
dataTraits[positive] = 20 - targetValue;
} else if (!keys.includes(positive) && !keys.includes(negative)) {
dataTraits[positive] = 10;
dataTraits[negative] = 10;
}
});

Object.assign(update, dataTraits);
} else {
update["hide_personality_traits"] = "on";
}

setAttrs(update, {
silent: true,
});
};

const handle_character = (page) => {
const attrs = [
"appearance",
Expand Down Expand Up @@ -244,7 +137,7 @@ const handle_drop = () => {
case "Squires":
handle_squire(page);
break;
case "Pre-generated Characters":
case "Pre-gens":
resetRepeatingRows(repeatingSections);
resetSkillList(page.data.skills);
handle_character(page);
Expand Down
3 changes: 2 additions & 1 deletion Pendragon6thEdition/src/pendragon.pug
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//- Semantic Versioning MAJOR.MINORPATCH
input(name='attr_version' type='hidden' value='3.21')
input(name='attr_version' type='hidden' value='3.3')

//- Do not manually change this. Hidden attribute used by versioning script
input(name='attr_latest_versioning_upgrade' type='hidden' value='3')
Expand Down Expand Up @@ -79,6 +79,7 @@ script(type="text/worker")
include js/drag_and_drop/get_static_update.js
include js/drag_and_drop/handle_horse.js
include js/drag_and_drop/handle_item.js
include js/drag_and_drop/handle_npc.js
include js/drag_and_drop/handle_squire.js
include js/drag_and_drop/handle_weapon.js
include js/drag_and_drop/parse_json.js
Expand Down

0 comments on commit 2e9244e

Please sign in to comment.