osrs-tools
Version:
A comprehensive TypeScript library for Old School RuneScape (OSRS) data and utilities, including quest data, skill requirements, and game item information
67 lines (66 loc) • 2.49 kB
JavaScript
import demonicPactsResource from '../../resources/leagues/demonicPacts.leagues7.json';
import { CombatStyle, LeaguesSeason, PactNodeSize } from "./DemonicPact.model";
const STYLE_MAP = {
universal: CombatStyle.Universal,
melee: CombatStyle.Melee,
ranged: CombatStyle.Ranged,
magic: CombatStyle.Magic,
};
const NODE_SIZE_MAP = {
node_minor: PactNodeSize.Minor,
node_major: PactNodeSize.Major,
node_capstone: PactNodeSize.Capstone,
};
const RESOURCE = demonicPactsResource;
export const DEMONIC_PACTS_LEAGUES_7 = {
season: LeaguesSeason.Leagues7,
displayName: RESOURCE.displayName,
totalPointsAvailable: RESOURCE.totalPointsAvailable,
rootNodeId: RESOURCE.rootNodeId,
source: RESOURCE.source,
pacts: RESOURCE.nodes.map(mapResourceNode),
};
export const LEAGUES_7_COMBAT_MASTERY_TREE = DEMONIC_PACTS_LEAGUES_7;
function mapResourceNode(resourceNode) {
const description = normalizeDescription(resourceNode.description, resourceNode.effectValue);
const effect = {
key: resourceNode.effectName,
value: resourceNode.effectValue,
description,
};
return {
id: resourceNode.id,
name: createPactName(resourceNode.effectName, description),
description,
rawDescription: resourceNode.description,
style: STYLE_MAP[resourceNode.style],
nodeSize: NODE_SIZE_MAP[resourceNode.nodeSize],
pointCost: resourceNode.pointCost,
linkedNodeIds: [...resourceNode.linkedNodeIds],
effect,
drawCoord: { ...resourceNode.drawCoord },
icon: resourceNode.nodeSprite,
};
}
function normalizeDescription(rawDescription, effectValue) {
const placeholderValue = effectValue === null ? '' : String(effectValue);
const resolvedDescription = rawDescription.replace(/#/g, placeholderValue);
return resolvedDescription
.replace(/<[^>]+>/g, '')
.split('\n')
.map((line) => line.trim())
.filter((line, index, lines) => line.length > 0 || (index > 0 && lines[index - 1].length > 0))
.join('\n');
}
function createPactName(effectName, description) {
if (effectName) {
return effectName
.replace(/^talent_/, '')
.split('_')
.filter((segment) => segment.length > 0)
.map((segment) => segment[0].toUpperCase() + segment.slice(1))
.join(' ');
}
const [firstLine] = description.split('\n');
return firstLine.trim();
}