Skip to content

Commit

Permalink
chore: npm run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Geczy committed Feb 19, 2025
1 parent 72882a4 commit e87433b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 30 deletions.
4 changes: 2 additions & 2 deletions tasks/newpatch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'node:fs';
import patches from '../json/patch.json';
import fs from "node:fs";
import patches from "../json/patch.json";

const last = patches.slice(-1)[0];

Expand Down
66 changes: 45 additions & 21 deletions tasks/updateconstants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'node:fs';
import vdfparser from 'vdf-parser';
import { cleanupArray } from './util.ts';
import fs from "node:fs";
import vdfparser from "vdf-parser";
import { cleanupArray } from "./util.ts";

const extraStrings = {
DOTA_ABILITY_BEHAVIOR_NONE: "None",
Expand Down Expand Up @@ -878,7 +878,7 @@ async function start() {
let keys = Object.keys(respObj[1].DOTAHeroes).filter(
(name) => !badNames.has(name),
);
let sortedHeroes: { name: string, id: number }[] = [];
let sortedHeroes: { name: string; id: number }[] = [];
keys.forEach((name) => {
const hero = respObj[1].DOTAHeroes[name];
sortedHeroes.push({ name, id: hero.HeroID });
Expand Down Expand Up @@ -925,7 +925,11 @@ async function start() {
heroKey != "npc_dota_hero_base" &&
heroKey != "npc_dota_hero_target_dummy"
) {
const newHero = { abilities: [] as any[], talents: [] as any[], facets: [] };
const newHero = {
abilities: [] as any[],
talents: [] as any[],
facets: [],
};
let talentCounter = 2;
Object.keys(heroes[heroKey]).forEach(function (key) {
let talentIndexStart =
Expand Down Expand Up @@ -1133,9 +1137,12 @@ async function start() {
key: "patchnotes",
url: "https://raw.githubusercontent.com/dotabuff/d2vpkr/master/dota/resource/localization/patchnotes/patchnotes_english.txt",
transform: (respObj) => {

let items = Object.keys(JSON.parse(fs.readFileSync("./build/items.json").toString()));
let heroes = Object.keys(JSON.parse(fs.readFileSync("./build/hero_lore.json").toString()));
let items = Object.keys(
JSON.parse(fs.readFileSync("./build/items.json").toString()),
);
let heroes = Object.keys(
JSON.parse(fs.readFileSync("./build/hero_lore.json").toString()),
);
const data = respObj.patch;

let result = {};
Expand Down Expand Up @@ -1376,8 +1383,17 @@ async function start() {
);
});
// Reference built files in index.js
const files = fs.readdirSync("./build").filter(filename => filename.endsWith('.json'));
const code = files.map((filename) => `export { default as ${filename.split(".")[0]} } from './build/${filename.split(".")[0]}.json';`).join('\n');
const files = fs
.readdirSync("./build")
.filter((filename) => filename.endsWith(".json"));
const code = files
.map(
(filename) =>
`export { default as ${filename.split(".")[0]} } from './build/${
filename.split(".")[0]
}.json';`,
)
.join("\n");
fs.writeFileSync("./index.ts", code);
process.exit(0);
}
Expand Down Expand Up @@ -1420,16 +1436,18 @@ function getSpecialAttrs(entity) {
}));
}
} else {
specialAttr = Object.entries(specialAttr).map(([key, val]: [string, any]) => {
// val looks like the following, so just take the value of the second key
/*
specialAttr = Object.entries(specialAttr).map(
([key, val]: [string, any]) => {
// val looks like the following, so just take the value of the second key
/*
{
"var_type" "FIELD_INTEGER"
"bonus_movement" "20"
}
*/
return { [Object.keys(val)[1]]: val[Object.keys(val)[1]] };
});
return { [Object.keys(val)[1]]: val[Object.keys(val)[1]] };
},
);
}
return specialAttr;
}
Expand Down Expand Up @@ -1615,12 +1633,18 @@ function replaceSValues(template, attribs, key) {
const bonusKey = `bonus_${key}`;
// Get the bonus value, handling both string and object cases
let specialBonusVal;
if (typeof val[specialBonusKey] === 'string') {
if (typeof val[specialBonusKey] === "string") {
specialBonusVal = val[specialBonusKey];
} else if (typeof val[specialBonusKey] === 'object' && val[specialBonusKey].special_bonus_scepter) {
} else if (
typeof val[specialBonusKey] === "object" &&
val[specialBonusKey].special_bonus_scepter
) {
specialBonusVal = val[specialBonusKey].special_bonus_scepter;
} else {
console.warn(`Unexpected special bonus value type for ${key}:`, val[specialBonusKey]);
console.warn(
`Unexpected special bonus value type for ${key}:`,
val[specialBonusKey],
);
continue;
}

Expand Down Expand Up @@ -1812,7 +1836,8 @@ function replaceSpecialAttribs(

if (isItem) {
const hint: string[] = [];
const abilities: { type: string, title: string, description: string}[] = [];
const abilities: { type: string; title: string; description: string }[] =
[];
const desc = cleanupArray(template.split("\\n"));
desc.forEach((line) => {
const ability = line.match(
Expand Down Expand Up @@ -1844,7 +1869,7 @@ function replaceSpecialAttribs(
function formatBehavior(string) {
if (!string) return false;
if (Array.isArray(string)) {
string = string.join(' | ');
string = string.join(" | ");
}
let split = string
.split(" | ")
Expand Down Expand Up @@ -1954,7 +1979,6 @@ function parseNameFromArray(array, names) {
const getNeutralItemNameTierMap = (neutrals) => {
let ret = {};
Object.keys(neutrals.neutral_tiers).forEach((tier) => {

let items = neutrals.neutral_tiers[tier].items;
Object.keys(items).forEach((itemName) => {
ret[itemName] = ret[itemName.replace(/recipe_/gi, "")] = parseInt(tier);
Expand Down
18 changes: 11 additions & 7 deletions tasks/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ export const HTML_REGEX = /(<([^>]+)>)/gi;
export const mapAbilities = (tokens) => {
const tokenKeys = Object.keys(tokens);
tokenKeys.forEach(
(key) => (tokens[key] = tokens[key].replace(HTML_REGEX, ""))
(key) => (tokens[key] = tokens[key].replace(HTML_REGEX, "")),
);
return tokens;
};

export const removeExtraneousWhitespacesFromString = (string) => {
if (!string) { return ''; }
if (!string) {
return "";
}

return string.replace(/\s+/g, ' ').trim();
}
return string.replace(/\s+/g, " ").trim();
};

export const cleanupArray = (array) => {
if (!array) { return []; }
if (!array) {
return [];
}

return array.filter(n => removeExtraneousWhitespacesFromString(n));
}
return array.filter((n) => removeExtraneousWhitespacesFromString(n));
};

0 comments on commit e87433b

Please sign in to comment.