Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Gimbardo committed Nov 14, 2024
1 parent fb80ab6 commit 5a7fe39
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 153 deletions.
10 changes: 6 additions & 4 deletions _layouts/sheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
</main>
{% include category-modal.html%}
</body>
<script src="/assets/js/stats_sub.js"></script>
<script type="module" src="/assets/js/stats_sub.js"></script>
<script src="/assets/js/spells.js"></script>
<script>
<script type="module">
import { substitute_stats } from '/assets/js/stats_sub.js';

substitute_stats("{{page.title}}")
.then(() => init_tooltip())
.then(() => init_spells())
.then(() => init_tooltip())
.then(() => init_spells())
</script>
</html>
45 changes: 0 additions & 45 deletions all_collections/_sheets/Bababooey.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,6 @@ title_font_color: f6f1f4
categories: [Wizard, Goblin]
---

| Class & Subclass | Background | Race | Alignment | Level |
|:---------------------------------------------------------------------------------------:| :--------: | :-------------------------------------------------------------------------------------------------: | :----------: | :---: |
| [Wizard Chronurgy](https://5e.tools/classes.html#wizard_phb,state:sub-chronurgy-egw=b1) | Sage | [Goblin](https://5e.tools/races.html#goblin_vgm) => [Fairy](https://5e.tools/races.html#fairy_mpmm) | Neutral Good | 9 |

<div align="center">
<img src="/assets/img/Bababooey.webp" alt="Bababooey" title="Bababooey" width="40%">
<img src="/assets/img/GoblinPlushie.png" alt="Plushie" title="Plushie" width="30%">
</div>

---

## Statistics

| | | |
|-------------------| --------------------------------- | ------------- |
| Proficiency: +4 | Passive Perception: 13 | Initative: +3 |
| Hit Points: 41/41 | Armor Class: 9 (+2 BoonOfFriends) | Speed: 30ft |

| Strength | Dexterity | Constitution | Intelligence | Wisdom | Charisma |
| :--------: | :--------: | :----------: | :----------: | :---------: | :--------: |
| **-2** (6) | **-1** (8) | **+1** (12) | **+4** (18) | **+3** (16) | **-2** (7) |

| Saving Throws | Modifier |
| :--------------------- |:--------:|
| Strength | **-2** |
| Dexterity | **-1** |
| Constitution | **+1** |
| **\~ Intelligence \~** | **+8** |
| **\~ Wisdom \~** | **+7** |
| Charisma | **-2** |

| Skills | Modifier | | Skills | Modifier |
| :---------------------- |:--------:| :-: | :----------------- |:--------:|
| Acrobatics | -1 | | **\~ Medicine \~** | +7 |
| Animal Handling | +3 | | Nature | +4 |
| **\~ Arcana \~** | +8 | | Perception | +3 |
| Athletics | -2 | | Performance | -2 |
| Deception | -2 | | Persuasion | -2 |
| **\~ History \~** | +8 | | Religion | +4 |
| Insight | +3 | | Sleight of Hand | -1 |
| Intimidation | -2 | | Stealth | -1 |
| **\~ Investigation \~** | +8 | | Survival | +3 |

---

## Equipment

- **Hat of Wizardry**: (1/1 uses)spellcasting focus (DC 10 Arcana check) You can try to cast a cantrip that you don't know. The cantrip must be on the wizard spell list. Success: you cast the spell. If the check fails, so does the spell, and the action used to cast the spell is wasted. In either case, you can't use this property again until you finish a long rest.
Expand Down
23 changes: 23 additions & 0 deletions assets/js/background_stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export async function background_info(data_file) {
let data = {}
const background_url = `https://2014.5e.tools/data/backgrounds.json`
await fetch(background_url)
.then((response) => response.json())
.then((json) => data = json_background_info(json, data_file))
.catch(function(error) {
console.log("Can't read this background's JSON" + error);
})
return data
}

function json_background_info(json, data_file) {
const background = json["background"].filter((background) => {
return background["name"].toLowerCase() === data_file["BACKGROUND"].toLowerCase()
})[0]

return {
BACKGROUND: background["name"],
BACKGROUND_URL: `https://5e.tools/backgrounds.html#${background["name"].toLowerCase()}_${background["source"].toLowerCase()}`
}
}

25 changes: 25 additions & 0 deletions assets/js/class_stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export async function class_info(data_file) {
let data = {}
const class_url = `https://2014.5e.tools/data/class/fluff-class-${data_file?.CLASS?.toLowerCase()}.json`
await fetch(class_url)
.then((response) => response.json())
.then((json) => data = json_class_info(json, data_file))
.catch(function(error) {
console.log("Can't read this class' JSON" + error);
})
return data
}

function json_class_info(json, data_file) {
const giuseppe = json["classFluff"][0]
const subclass = json["subclassFluff"].filter((subclass) => {
return [subclass["name"].toLowerCase(), subclass["shortName"].toLowerCase()].includes(data_file["SUBCLASS"].toLowerCase())
})[0]

return {
CLASS_URL: `https://5e.tools/classes.html#${giuseppe["name"].toLowerCase()}_${giuseppe["source"].toLowerCase()},state:sub-${subclass["shortName"].toLowerCase()}-${subclass["source"].toLowerCase()}=b1`,
CLASS: giuseppe["name"],
SUBCLASS_SHORT: subclass["shortName"],
SUBCLASS: subclass["name"]
}
}
25 changes: 25 additions & 0 deletions assets/js/race_stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export async function race_info(data_file) {
let data = {}
const race_url = `https://2014.5e.tools/data/races.json`
await fetch(race_url)
.then((response) => response.json())
.then((json) => data = json_race_info(json, data_file))
.catch(function(error) {
console.log("Can't read this race's JSON" + error);
})
return data
}

function json_race_info(json, data_file) {
const race = json["race"].filter((race) => {
let filter_name = race["name"].toLowerCase() === data_file["RACE"].toLowerCase()
if(!data_file["RACE_SOURCE"])
return filter_name
let filter_source = race["source"].toLowerCase() === data_file["RACE_SOURCE"].toLowerCase()
return filter_name && filter_source
})[0]

return {
RACE_URL: `https://2014.5e.tools/races.html#${race["name"].toLowerCase()}_${race["source"].toLowerCase()}`
}
}
142 changes: 38 additions & 104 deletions assets/js/stats_sub.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
stats_map = {
import { race_info } from '/assets/js/race_stats.js';
import { background_info } from '/assets/js/background_stats.js';
import { class_info } from '/assets/js/class_stats.js';

const stats_map = {
"STR": stat("Strength", ["Athletics"]),
"DEX": stat("Dexterity", ["Acrobatics", "SleightOfHand", "Stealth", "Initiative"]),
"CON": stat("Constitution", []),
Expand All @@ -7,41 +11,52 @@ stats_map = {
"CHA": stat("Charisma", ["Performance", "Deception", "Persuasion", "Intimidation"])
}

function stat(name, skills) {
return { "name": name, "skills": skills }
}

let proficiency = 0

async function substitute_stats(title) {
export async function substitute_stats(title) {
try {
const response = await fetch('/assets/json/' + title + ".json");
const data_file = await response.json();
const data_file = await fetch(`/assets/json/${title}.json`).then(r => r.json());

const [class_data, background_data, race_data] = await Promise.all([
class_info(data_file),
background_info(data_file),
race_info(data_file)
]);

const substitution_map = prepare_json(data_file);
const class_map = await class_info(data_file)
const background_map = await background_info(data_file)
const race_map = await race_info(data_file)
json_substitute({...substitution_map, ...class_map, ...background_map, ...race_map});
const merged_data = Object.assign({},
substitution_map,
class_data,
background_data,
race_data
);

json_substitute(merged_data);

} catch (error) {
console.log("Can't read JSON stat file" + error);
}
}

function stat(name, skills) {
return { "name": name, "skills": skills }
}

let proficiency = 0

function prepare_json(data_file){
proficiency = Math.ceil(data_file["LVL"]/4)+1
let substitution_map = {
const proficiency = Math.ceil(data_file["LVL"]/4)+1
const substitution_map = {
"LVL": data_file["LVL"],
"PROF": proficiency,
"CA": data_file["CA"]
}

for(let stat in stats_map) {
base_mod = stat_mod(data_file[stat])
for(const stat in stats_map) {
const base_mod = stat_mod(data_file[stat])
substitution_map[stat] = data_file[stat]
substitution_map[stat+"_MOD"] = base_mod
substitution_map[stat+"_ST"] = st_mod(base_mod, data_file, stat)

for(let skill of stats_map[stat]["skills"]){
for(const skill of stats_map[stat]["skills"]){
substitution_map[skill] = skill_mod(base_mod, data_file, skill)
}
substitution_map
Expand All @@ -50,7 +65,7 @@ function prepare_json(data_file){
substitution_map["HP"] = data_file["HP"] || calc_hp(data_file["LVL"], substitution_map["CON_MOD"], data_file["HITDICE"])

if(data_file["SpellcastingAbility"]) {
stat = data_file["SpellcastingAbility"]
const stat = data_file["SpellcastingAbility"]
substitution_map["SPELL_AB"] = stats_map[stat]["name"]
substitution_map["SPELL_DC"] = 8 + proficiency + substitution_map[stat+"_MOD"]
substitution_map["SPELL_ATK"] = proficiency + substitution_map[stat+"_MOD"]
Expand All @@ -59,8 +74,8 @@ function prepare_json(data_file){
}

function json_substitute(substitution_map){
for(let key in substitution_map) {
value = substitution_map[key]
for(const key in substitution_map) {
const value = substitution_map[key]
document.body.innerHTML = document.body.innerHTML.split(build_keyword(key)).join(value);
}
}
Expand All @@ -86,7 +101,7 @@ function skill_mod(base_mod, stats_file, skill){
}

function calc_hp(lev, con, dice){
medium_roll = (dice/2)+1+con
const medium_roll = (dice/2)+1+con
return (lev-1)*medium_roll + dice + con
}

Expand All @@ -97,84 +112,3 @@ function build_keyword(key) {
function signed(n) {
return (n<=0?"-":"+") + n
}

// Class

async function class_info(data_file){
let data = {}
let class_url = `https://2014.5e.tools/data/class/fluff-class-${data_file?.CLASS?.toLowerCase()}.json`
await fetch(class_url)
.then((response) => response.json())
.then((json) => data = json_class_info(json, data_file))
.catch(function(error) {
console.log("Can't read this class' JSON" + error);
})
return data
}

function json_class_info(json, data_file) {
let giuseppe = json["classFluff"][0]
let subclass = json["subclassFluff"].filter((subclass) => {
return [subclass["name"].toLowerCase(), subclass["shortName"].toLowerCase()].includes(data_file["SUBCLASS"].toLowerCase())
})[0]

return {
CLASS_URL: `https://5e.tools/classes.html#${giuseppe["name"].toLowerCase()}_${giuseppe["source"].toLowerCase()},state:sub-${subclass["shortName"].toLowerCase()}-${subclass["source"].toLowerCase()}=b1`,
CLASS: giuseppe["name"],
SUBCLASS_SHORT: subclass["shortName"],
SUBCLASS: subclass["name"]
}
}

// Background

async function background_info(data_file) {
let data = {}
let background_url = `https://2014.5e.tools/data/backgrounds.json`
await fetch(background_url)
.then((response) => response.json())
.then((json) => data = json_background_info(json, data_file))
.catch(function(error) {
console.log("Can't read this background's JSON" + error);
})
return data
}

function json_background_info(json, data_file) {
let background = json["background"].filter((background) => {
return background["name"].toLowerCase() === data_file["BACKGROUND"].toLowerCase()
})[0]

return {
BACKGROUND: background["name"],
BACKGROUND_URL: `https://5e.tools/backgrounds.html#${background["name"].toLowerCase()}_${background["source"].toLowerCase()}`
}
}

// Race

async function race_info(data_file) {
let data = {}
let race_url = `https://2014.5e.tools/data/races.json`
await fetch(race_url)
.then((response) => response.json())
.then((json) => data = json_race_info(json, data_file))
.catch(function(error) {
console.log("Can't read this race's JSON" + error);
})
return data
}

function json_race_info(json, data_file) {
let race = json["race"].filter((race) => {
filter_name = race["name"].toLowerCase() === data_file["RACE"].toLowerCase()
if(!data_file["RACE_SOURCE"])
return filter_name
filter_source = race["source"].toLowerCase() === data_file["RACE_SOURCE"].toLowerCase()
return filter_name && filter_source
})[0]

return {
RACE_URL: `https://2014.5e.tools/races.html#${race["name"].toLowerCase()}_${race["source"].toLowerCase()}`
}
}
25 changes: 25 additions & 0 deletions assets/json/Bababooey.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"LVL": 9,
"CA": 13,
"HITDICE": 6,
"CLASS": "Wizard",
"SUBCLASS": "Chronurgy",
"BACKGROUND": "Sage",
"ALIGNMENT": "Neutral Good",
"RACE": "Goblin",
"RACE_SOURCE": "VGM",
"SPEED": "30ft",

"HP": 41,

"STR": 6,
"DEX": 8,
"CON": 12,
"INT": 18,
"WIS": 16,
"CHA": 7,
"SkillProf": ["Arcana", "History", "Investigation", "Medicine"],
"STProf": ["INT", "WIS"],
"SpellcastingAbility": "INT"
}

0 comments on commit 5a7fe39

Please sign in to comment.