Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,005 changes: 1,234 additions & 1,771 deletions package-lock.json

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions src/combat-controls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { combatInfo } from "./combatcalc";
import { defineHotkey } from "./hotkey";

declare global {
var NeptunesPride: {
np: {
trigger: (event: string, data?: any) => void;
};
};
}

export const incCombatHandicap = () => {
combatInfo.combatHandicap += 1;
NeptunesPride.np.trigger("map_rebuild");
NeptunesPride.np.trigger("refresh_interface");
};

export const decCombatHandicap = () => {
combatInfo.combatHandicap -= 1;
NeptunesPride.np.trigger("map_rebuild");
NeptunesPride.np.trigger("refresh_interface");
};

export const registerCombatControlHotkeys = () => {
defineHotkey(
".",
incCombatHandicap,
"Change combat calculation to credit your enemies with +1 weapons. Useful " +
"if you suspect they will have achieved the next level of tech before a battle you are investigating." +
"<p>In the lower left of the HUD, an indicator will appear reminding you of the weapons adjustment. If the " +
"indicator already shows an advantage for defenders, this hotkey will reduce that advantage first before crediting " +
"weapons to your opponent.",
"+ Handicap",
);
defineHotkey(
",",
decCombatHandicap,
"Change combat calculation to credit yourself with +1 weapons. Useful " +
"when you will have achieved the next level of tech before a battle you are investigating." +
"<p>In the lower left of the HUD, an indicator will appear reminding you of the weapons adjustment. When " +
"indicator already shows an advantage for attackers, this hotkey will reduce that advantage first before crediting " +
"weapons to you.",
"- Handicap",
);
};
127 changes: 127 additions & 0 deletions src/display-controls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { combatInfo } from "./combatcalc";
import { defineHotkey } from "./hotkey";

export interface Settings {
territoryOn: boolean;
territoryBrightness: number;
autoRulerPower: number;
}

declare global {
var NeptunesPride: {
np: {
trigger: (event: string, data?: any) => void;
};
};
}

let settings: Settings;

export const setSettings = (newSettings: Settings) => {
settings = newSettings;
};

const mapRebuild = () => {
const showingOurOptions = false; // TODO: get this from shared state
if (showingOurOptions) {
NeptunesPride.np.trigger("refresh_interface");
}
NeptunesPride.np.trigger("map_rebuild");
};

const toggleTerritory = () => {
// TODO: implement this function or import it
settings.territoryOn = !settings.territoryOn;
mapRebuild();
};

export const incTerritoryBrightness = () => {
if (!settings.territoryOn) {
toggleTerritory();
return;
}
settings.territoryBrightness = (settings.territoryBrightness + 1) % 4;
mapRebuild();
};

export const decTerritoryBrightness = () => {
if (!settings.territoryOn) {
toggleTerritory();
return;
}
let nextPower = (settings.territoryBrightness - 1) % 4;
if (nextPower < 0) nextPower = 3;
settings.territoryBrightness = nextPower;
mapRebuild();
};

export const incAutoRuler = () => {
settings.autoRulerPower += 1;
mapRebuild();
};

export const decAutoRuler = () => {
let nextPower = settings.autoRulerPower - 1;
if (nextPower < 0) nextPower = 0;
settings.autoRulerPower = nextPower;
mapRebuild();
};

export const incCombatHandicap = () => {
combatInfo.combatHandicap += 1;
NeptunesPride.np.trigger("map_rebuild");
NeptunesPride.np.trigger("refresh_interface");
};

export const decCombatHandicap = () => {
combatInfo.combatHandicap -= 1;
NeptunesPride.np.trigger("map_rebuild");
NeptunesPride.np.trigger("refresh_interface");
};

export const registerDisplayControlHotkeys = () => {
defineHotkey(
"ctrl+8",
decTerritoryBrightness,
"Adjust territory display style.",
"- Territory Brightness",
);
defineHotkey(
"ctrl+9",
incTerritoryBrightness,
"Adjust territory display style.",
"+ Territory Brightness",
);
defineHotkey(
"8",
decAutoRuler,
"Decrease number of distances shown by the auto ruler.",
"- Rulers",
);
defineHotkey(
"9",
incAutoRuler,
"Increase number of distances shown by the auto ruler.",
"+ Rulers",
);
defineHotkey(
".",
incCombatHandicap,
"Change combat calculation to credit your enemies with +1 weapons. Useful " +
"if you suspect they will have achieved the next level of tech before a battle you are investigating." +
"<p>In the lower left of the HUD, an indicator will appear reminding you of the weapons adjustment. If the " +
"indicator already shows an advantage for defenders, this hotkey will reduce that advantage first before crediting " +
"weapons to your opponent.",
"+ Handicap",
);
defineHotkey(
",",
decCombatHandicap,
"Change combat calculation to credit yourself with +1 weapons. Useful " +
"when you will have achieved the next level of tech before a battle you are investigating." +
"<p>In the lower left of the HUD, an indicator will appear reminding you of the weapons adjustment. When " +
"indicator already shows an advantage for attackers, this hotkey will reduce that advantage first before crediting " +
"weapons to you.",
"- Handicap",
);
};
76 changes: 76 additions & 0 deletions src/fleet-routing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { defineHotkey } from "./hotkey";

declare global {
var NeptunesPride: {
universe: {
selectedStar?: {
puid: number;
x: number;
y: number;
uid: number;
st: number;
};
selectedFleet?: {
puid: number;
};
player: any;
galaxy: {
players: { [key: number]: any };
fleets: { [key: number]: any };
};
};
npui: {
trigger: (event: string, data?: any) => void;
};
np: {
onNewFleetResponse: (error: any, fleet: any) => void;
};
};
}

export const routeEnemy = () => {
const universe = NeptunesPride.universe;
const npui = NeptunesPride.npui;
if (universe.selectedStar && universe.selectedStar.puid !== -1) {
const star = universe.selectedStar;
universe.player = universe.galaxy.players[star.puid];
const base = 100000;
let uid = base + 1;
while (universe.galaxy.fleets[uid]) {
uid++;
}
const fakeFleet = {
l: 0,
lx: star.x,
ly: star.y,
x: star.x,
y: star.y,
ouid: star.uid,
n: `Fake Enemy Fleet ${uid - base}`,
o: [] as [number, number, number, number][],
puid: star.puid,
st: star.st,
uid,
w: false,
};
star.st = 0;
NeptunesPride.np.onNewFleetResponse(null, fakeFleet);
} else if (universe.selectedFleet) {
const fleet = universe.selectedFleet;
universe.player = universe.galaxy.players[fleet.puid];
npui.trigger("start_edit_waypoints", { fleet });
}
};

export const registerFleetRoutingHotkeys = () => {
defineHotkey(
"x",
routeEnemy,
"Set fleet orders for an enemy fleet. " +
"These orders won't really happen but you can use them to explore " +
"attack or defense options your opponents have. First, select an " +
"enemy star, then press x to create and set orders for the fleet. You" +
"can then also route any other fleets that player controls.",
"Route Enemy",
);
};
77 changes: 77 additions & 0 deletions src/help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { defineHotkey, getHotkeyCallback, getHotkeys } from "./hotkey";
import type { Stanzas } from "./reports";

declare global {
var NeptunesPride: {
universe: {
helpHTML: string;
};
np: {
trigger: (event: string, data?: any) => void;
};
};
var Crux: {
format: (template: string, data: any) => string;
};
}

export const npaHelp = () => {
const title = "Neptune's Pride Agent";
const help = [`<H1>${title}</H1>`];
help.push(" Neptune's Pride Agent is meant to help you focus on");
help.push(" diplomacy and spend less time doing tedious calculations");
help.push(" or manually sharing information.");
help.push("<h1>Hotkey Reference</h1>");
for (const key of getHotkeys()) {
const action = getHotkeyCallback(key);
let button = Crux.format(`[[goto:${key}]]`, {});
if (key === "?") button = Crux.format(`[[hotkey:${key}]]`, {});
help.push(`<h2>Hotkey: ${key} ${button}</h2>`);
if (action.help) {
help.push(action.help);
} else {
help.push(
`<p>No documentation yet.<p><code>${action.toLocaleString()}</code>`,
);
}
}
NeptunesPride.universe.helpHTML = help.join("");
NeptunesPride.np.trigger("show_screen", "help");
};

export const createNpaControls = (
prepReport: (name: string, stanzas: Stanzas) => void,
) => {
return () => {
const output: Stanzas = [];
output.push("--- Controls ---");
output.push(":--|--|--:");
output.push("Button||Hotkey");
const div = document.createElement("div");
for (let key of getHotkeys()) {
let control = `[[goto:${key}]]`;
if (key === "?") control = `[[hotkey:${key}]]`;
if (key === "<") key = "&lt;";
else if (key === ">") key = "&gt;";
else if (key === "&") key = "&amp;";
else if (key.length === 1) {
key = `&#${key.charCodeAt(0)};`;
} else {
div.innerText = key;
key = div.innerHTML;
}
const partial = `${control}||${key}`;
output.push([partial]);
}
output.push("--- Controls ---");
prepReport("controls", output);
};
};

export const registerHelpHotkeys = (
prepReport: (name: string, stanzas: Stanzas) => void,
) => {
const npaControls = createNpaControls(prepReport);
defineHotkey("?", npaHelp, "Display this help screen.", "help");
defineHotkey("~", npaControls, "Generate NPA Buttons.", "controls");
};
Loading