forked from hamcha/tghandbook
Fix chemistry and food/drinks
This commit is contained in:
parent
5074d6180f
commit
960c1ff7b8
6 changed files with 92 additions and 55 deletions
|
@ -8,7 +8,8 @@ import unknown from "~/assets/images/tab-icons/unknown.svg";
|
|||
import { bindFunctions } from "./scripts/index";
|
||||
|
||||
// Enable single page mode for developing scripts
|
||||
const devSinglePage = null; // ["Other", "Guide_to_food_and_drinks"];
|
||||
// const devSinglePage = ["Medical", "Guide_to_chemistry"];
|
||||
const devSinglePage = null;
|
||||
|
||||
async function load() {
|
||||
const sectionListContainer = document.getElementById("section-list");
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { chemistryScript, processChemistry } from "./pages/chemistry";
|
||||
import { processVirology, virologyScript } from "./pages/virology";
|
||||
import { processFood, foodScript } from "./pages/food";
|
||||
import { processDrinks, drinkScript } from "./pages/drinks";
|
||||
import { genericScript } from "./pages/generic";
|
||||
import { processGlobal } from "./pages/global";
|
||||
import { welcomeScript } from "./pages/welcome";
|
||||
|
@ -10,8 +11,8 @@ import { welcomeScript } from "./pages/welcome";
|
|||
export const PAGE_VERSIONS = {
|
||||
Infections: "fcebeda2fddb46d924f4538cd9c0daeb55aa4c9b",
|
||||
Guide_to_food_and_drinks: "131e010df66ed689d31df53c3ca17ad16635a827",
|
||||
Guide_to_chemistry: "8583fc3b707920eb5cc3a814ec934cfff88803a5",
|
||||
$DEFAULT: "bb7abd544a19369d4b6b7e3dde3eb3cc34c023d4",
|
||||
Guide_to_chemistry: "5074d6180fc8b283bac00b99c6aa2325b797da6b",
|
||||
$DEFAULT: "5074d6180fc8b283bac00b99c6aa2325b797da6b",
|
||||
};
|
||||
|
||||
const MAX_WIDTH = 440;
|
||||
|
@ -26,9 +27,12 @@ export function processHTML(root: HTMLElement, docname: string): void {
|
|||
case "Infections":
|
||||
processVirology(root);
|
||||
break;
|
||||
case "Guide_to_food_and_drinks":
|
||||
case "Guide_to_food":
|
||||
processFood(root);
|
||||
break;
|
||||
case "Guide_to_drinks":
|
||||
processDrinks(root);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
@ -69,10 +73,14 @@ export function bindFunctions(root: HTMLElement, docname: string): void {
|
|||
case "$Welcome":
|
||||
welcomeScript(root);
|
||||
break;
|
||||
case "Guide_to_food_and_drinks":
|
||||
case "Guide_to_food":
|
||||
genericScript(root, docname);
|
||||
foodScript(root);
|
||||
break;
|
||||
case "Guide_to_drinks":
|
||||
genericScript(root, docname);
|
||||
drinkScript(root);
|
||||
break;
|
||||
default:
|
||||
genericScript(root, docname);
|
||||
break;
|
||||
|
|
|
@ -76,6 +76,8 @@ export function processChemistry(root: HTMLElement): void {
|
|||
return;
|
||||
}
|
||||
const rows = Array.from(row.querySelectorAll("td")).slice(1);
|
||||
let conditions: HTMLTableCellElement = null;
|
||||
let explosive: HTMLTableCellElement = null;
|
||||
let ph: HTMLTableCellElement = null;
|
||||
let treatment: HTMLTableCellElement = null;
|
||||
let desc: HTMLTableCellElement = null;
|
||||
|
@ -83,7 +85,6 @@ export function processChemistry(root: HTMLElement): void {
|
|||
let overdose: HTMLTableCellElement = null;
|
||||
let addiction: HTMLTableCellElement = null;
|
||||
// Handle special cases
|
||||
console.log(section);
|
||||
switch (section) {
|
||||
case "Components":
|
||||
[ph, desc] = rows;
|
||||
|
@ -98,6 +99,8 @@ export function processChemistry(root: HTMLElement): void {
|
|||
[ph, desc, metabolism] = rows;
|
||||
break;
|
||||
case "Explosive Strength":
|
||||
[conditions, desc, explosive] = rows;
|
||||
break;
|
||||
case "Mutation Toxins":
|
||||
[desc, metabolism] = rows;
|
||||
break;
|
||||
|
@ -113,6 +116,12 @@ export function processChemistry(root: HTMLElement): void {
|
|||
if (metabolism) {
|
||||
content += `<p class="metabolism">${metabolism.innerHTML}</p>`;
|
||||
}
|
||||
if (conditions) {
|
||||
content += `<p class="conditions">${conditions.innerHTML}</p>`;
|
||||
}
|
||||
if (explosive) {
|
||||
content += `<p class="explosive">${explosive.innerHTML}</p>`;
|
||||
}
|
||||
if (addiction && addiction.innerHTML.trim() !== "N/A") {
|
||||
content += `<p class="addiction">${addiction.innerHTML}</p>`;
|
||||
}
|
||||
|
@ -130,6 +139,8 @@ export function processChemistry(root: HTMLElement): void {
|
|||
if (desc) desc.parentElement.removeChild(desc);
|
||||
if (treatment) treatment.parentElement.removeChild(treatment);
|
||||
if (metabolism) metabolism.parentElement.removeChild(metabolism);
|
||||
if (conditions) conditions.parentElement.removeChild(conditions);
|
||||
if (explosive) explosive.parentElement.removeChild(explosive);
|
||||
if (overdose) overdose.parentElement.removeChild(overdose);
|
||||
if (addiction) addiction.parentElement.removeChild(addiction);
|
||||
if (ph) ph.parentElement.removeChild(ph);
|
||||
|
|
50
src/scripts/pages/drinks.ts
Normal file
50
src/scripts/pages/drinks.ts
Normal file
|
@ -0,0 +1,50 @@
|
|||
import { parseTable, makeTable } from "../utils";
|
||||
import { registerSearchEntries } from "../search";
|
||||
|
||||
export function processDrinks(root: HTMLElement): void {
|
||||
const drinkTables = ["#Basic_Drink_Ingredients", "#Mixed_Drinks"];
|
||||
drinkTables.forEach((selector) => {
|
||||
const table = root.querySelector<HTMLElement>(`${selector} .wikitable`);
|
||||
const drinks = parseTable(table).map((row) => {
|
||||
const foodBlock = document.createElement("td");
|
||||
foodBlock.innerHTML = `
|
||||
<div class="food-pic">${row["Picture"].innerHTML}</div>
|
||||
<div class="food-name">${row["Cocktail"].innerHTML}</div>
|
||||
<p class="strength">${row["Strength"].innerHTML}</p>
|
||||
<p class="description">${row["Drink Description"].innerHTML}</p>
|
||||
<p class="notes">${row["Notes"].innerHTML}</p>
|
||||
`;
|
||||
const ingredients = row["Ingredients"].innerHTML
|
||||
.split(/,|\+/gi)
|
||||
.map((s) => `<p>${s.trim()}</p>`);
|
||||
row["Ingredients"].innerHTML = ingredients.join("");
|
||||
return { Drink: foodBlock, Ingredients: row["Ingredients"] };
|
||||
});
|
||||
const betterTable = makeTable(["Drink", "Ingredients"], drinks);
|
||||
betterTable.className = "drink-ext wikitable";
|
||||
table.replaceWith(betterTable);
|
||||
});
|
||||
}
|
||||
|
||||
export function drinkScript(root: HTMLElement): void {
|
||||
// Init fuzzy search with elements
|
||||
const foodEntries = Array.from(
|
||||
root.querySelectorAll<HTMLElement>(
|
||||
".drink-ext tr:not(:first-child), .food-base-ext tr:not(:first-child), .food-ext tr:not(:first-child)"
|
||||
)
|
||||
);
|
||||
registerSearchEntries(
|
||||
foodEntries.map((element, id) => ({
|
||||
page: "Guide_to_drinks",
|
||||
name: element.querySelector(".food-name").textContent.trim(),
|
||||
element,
|
||||
alignment: "center",
|
||||
id,
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
export default {
|
||||
processDrinks,
|
||||
drinkScript,
|
||||
};
|
|
@ -2,29 +2,6 @@ import { parseTable, makeTable } from "../utils";
|
|||
import { registerSearchEntries } from "../search";
|
||||
|
||||
export function processFood(root: HTMLElement): void {
|
||||
const drinkTables = ["#Basic_Drink_Ingredients", "#Mixed_Drinks"];
|
||||
drinkTables.forEach((selector) => {
|
||||
const table = root.querySelector<HTMLElement>(`${selector} .wikitable`);
|
||||
const drinks = parseTable(table).map((row) => {
|
||||
const foodBlock = document.createElement("td");
|
||||
foodBlock.innerHTML = `
|
||||
<div class="food-pic">${row["Picture"].innerHTML}</div>
|
||||
<div class="food-name">${row["Cocktail"].innerHTML}</div>
|
||||
<p class="strength">${row["Strength"].innerHTML}</p>
|
||||
<p class="description">${row["Drink Description"].innerHTML}</p>
|
||||
<p class="notes">${row["Notes"].innerHTML}</p>
|
||||
`;
|
||||
const ingredients = row["Ingredients"].innerHTML
|
||||
.split(/,|\+/gi)
|
||||
.map((s) => `<p>${s.trim()}</p>`);
|
||||
row["Ingredients"].innerHTML = ingredients.join("");
|
||||
return { Drink: foodBlock, Ingredients: row["Ingredients"] };
|
||||
});
|
||||
const betterTable = makeTable(["Drink", "Ingredients"], drinks);
|
||||
betterTable.className = "drink-ext wikitable";
|
||||
table.replaceWith(betterTable);
|
||||
});
|
||||
|
||||
const baseFoodTables = [
|
||||
{
|
||||
selector: "#Butchering",
|
||||
|
@ -56,16 +33,6 @@ export function processFood(root: HTMLElement): void {
|
|||
title: "Dispenses",
|
||||
process: "Description",
|
||||
},
|
||||
{
|
||||
selector: "#Junk_Drinks",
|
||||
title: "Dispenses",
|
||||
process: "Description",
|
||||
},
|
||||
{
|
||||
selector: "#Hot_Drinks",
|
||||
title: "Dispenses",
|
||||
process: "Description",
|
||||
},
|
||||
{
|
||||
selector: "#Other_food",
|
||||
title: "Item",
|
||||
|
@ -123,22 +90,21 @@ export function processFood(root: HTMLElement): void {
|
|||
const foodRecipesTables = [
|
||||
"#Burgers",
|
||||
"#Breads",
|
||||
"#Sandwiches",
|
||||
"#Pizzas",
|
||||
"#Pastas",
|
||||
"#Soups_\\.26_Stews",
|
||||
"#Seafood",
|
||||
"#Meat",
|
||||
"#Misc\\._Food",
|
||||
"#Frozen",
|
||||
"#Pies",
|
||||
"#Salads",
|
||||
"#Cakes",
|
||||
"#Side_Dishes",
|
||||
"#Pastries",
|
||||
"#Sweets",
|
||||
"#Egg-Based_Food",
|
||||
"#Snowcones",
|
||||
"#Lizard_Cuisine",
|
||||
"#Seafood",
|
||||
"#Mexican",
|
||||
"#Savory",
|
||||
"#Waffles",
|
||||
"#Pies",
|
||||
"#Pizzas",
|
||||
"#Salads",
|
||||
"#Sandwiches",
|
||||
"#Soups_\\.26_Stews",
|
||||
"#Spaghettis",
|
||||
"#Icecream_Vat",
|
||||
"#Exotic",
|
||||
];
|
||||
foodRecipesTables.forEach((selector) => {
|
||||
const table = root.querySelector<HTMLElement>(`${selector} .wikitable`);
|
||||
|
@ -175,7 +141,7 @@ export function foodScript(root: HTMLElement): void {
|
|||
);
|
||||
registerSearchEntries(
|
||||
foodEntries.map((element, id) => ({
|
||||
page: "Guide_to_food_and_drinks",
|
||||
page: "Guide_to_food",
|
||||
name: element.querySelector(".food-name").textContent.trim(),
|
||||
element,
|
||||
alignment: "center",
|
||||
|
|
|
@ -198,7 +198,8 @@ const sections: SectionInfo[] = [
|
|||
},
|
||||
{ page: "Critters", icon: critter },
|
||||
{ page: "Guide_to_races", icon: races },
|
||||
{ page: "Guide_to_food_and_drinks", text: "food", icon: food },
|
||||
{ page: "Guide_to_food", text: "food", icon: food },
|
||||
{ page: "Guide_to_drinks", text: "drnk", icon: food },
|
||||
{ page: "Guide_to_hydroponics", icon: hydro },
|
||||
{ page: "Songs", icon: song },
|
||||
{ page: "Supply_crates", icon: crate },
|
||||
|
|
Loading…
Reference in a new issue