Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI Polish #792

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions @types/module.css.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "*.module.css" {
const styles: Record<string, string>;
export = styles;
}
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default tseslint.config(
project: true,
tsconfigRootDir: import.meta.dirname,
EXPERIMENTAL_useProjectService: true,
warnOnUnsupportedTypeScriptVersion: false,
},
},
rules: {
Expand Down
1 change: 1 addition & 0 deletions packages/kitten-analysts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"esbuild": "0.24.0",
"typescript": "5.7.2",
"vite": "5.4.11",
"vite-plugin-css-injected-by-js": "3.5.2",
"vite-plugin-userscript": "0.1.3"
},
"keywords": [
Expand Down
1 change: 1 addition & 0 deletions packages/kitten-engineers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"devDependencies": {
"typescript": "5.7.2",
"vite": "5.4.11",
"vite-plugin-css-injected-by-js": "3.5.2",
"vite-plugin-userscript": "0.1.3"
},
"keywords": [
Expand Down
1 change: 1 addition & 0 deletions packages/kitten-scientists/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@types/web": "0.0.183",
"typescript": "5.7.2",
"vite": "5.4.11",
"vite-plugin-css-injected-by-js": "3.5.2",
"vite-plugin-userscript": "0.1.3"
},
"keywords": [
Expand Down
42 changes: 23 additions & 19 deletions packages/kitten-scientists/source/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
ActivitySummarySection,
ActivityTypeClass,
} from "./helper/ActivitySummary.js";
import en from "./i18n/en-US.json" assert { type: "json" };
import de from "./i18n/translations/de-DE.json" assert { type: "json" };
import he from "./i18n/translations/he-IL.json" assert { type: "json" };
import zh from "./i18n/translations/zh-CN.json" assert { type: "json" };
import enUS from "./i18n/en-US.json" assert { type: "json" };
import deDE from "./i18n/translations/de-DE.json" assert { type: "json" };
import heIL from "./i18n/translations/he-IL.json" assert { type: "json" };
import zhCN from "./i18n/translations/zh-CN.json" assert { type: "json" };
import { KittenScientists, ksVersion } from "./KittenScientists.js";
import { ReligionManager } from "./ReligionManager.js";
import { ScienceManager } from "./ScienceManager.js";
Expand All @@ -30,11 +30,11 @@ import { TimeControlManager } from "./TimeControlManager.js";
import { TimeManager } from "./TimeManager.js";
import { cdebug, cerror, cinfo, cwarn } from "./tools/Log.js";
import { TradeManager } from "./TradeManager.js";
import { FallbackLanguage } from "./UserScriptLoader.js";
import { FallbackLocale } from "./UserScriptLoader.js";
import { VillageManager } from "./VillageManager.js";
import { WorkshopManager } from "./WorkshopManager.js";

const i18nData = { de, en, he, zh };
const i18nData = { ["de-DE"]: deDE, ["en-US"]: enUS, ["he-IL"]: heIL, ["zh-CN"]: zhCN };

export type FrameContext = {
requestGameUiRefresh: boolean;
Expand Down Expand Up @@ -79,10 +79,10 @@ export type GameLanguage =
| "uk"
| "zh"
| "zht";
export type SupportedLanguage = "de" | "en" | "he" | "zh";
export type SupportedLocale = "de-DE" | "en-US" | "he-IL" | "zh-CN";

export type TranslatedString<TKittenGameLiteral extends `$${string}`> =
| keyof typeof i18nData.en
| keyof (typeof i18nData)["en-US"]
| TKittenGameLiteral;

export class Engine {
Expand Down Expand Up @@ -137,20 +137,24 @@ export class Engine {
this.villageManager = new VillageManager(this._host, this.workshopManager);
}

isLanguageSupported(language: string): boolean {
return language in this._i18nData;
isLocaleSupported(locale: string): boolean {
return locale in this._i18nData;
}

setLanguage(language: GameLanguage | SupportedLanguage, rebuildUI = true) {
localeSupportsFirstLetterSplits(locale = this.settings.language.selected): boolean {
return locale !== "zh-CN";
}

setLanguage(language: GameLanguage | SupportedLocale, rebuildUI = true) {
const previousLanguage = this.settings.language.selected;
if (!this.isLanguageSupported(language)) {
if (!this.isLocaleSupported(language)) {
cwarn(
`Requested language '${language}' is not available. Falling back to '${FallbackLanguage}'.`,
`Requested language '${language}' is not available. Falling back to '${FallbackLocale}'.`,
);
this.settings.language.selected = FallbackLanguage;
this.settings.language.selected = FallbackLocale;
} else {
cinfo(`Selecting language '${language}'.`);
this.settings.language.selected = language as SupportedLanguage;
this.settings.language.selected = language as SupportedLocale;
}

if (previousLanguage !== this.settings.language.selected && rebuildUI) {
Expand Down Expand Up @@ -431,13 +435,13 @@ export class Engine {
value =
value ??
this._i18nData[this.settings.language.selected][
key as keyof (typeof i18nData)[SupportedLanguage]
key as keyof (typeof i18nData)[SupportedLocale]
];

const check: Maybe<string> = value;

if (isNil(check)) {
value = i18nData[FallbackLanguage][key as keyof (typeof i18nData)[SupportedLanguage]];
value = i18nData[FallbackLocale][key as keyof (typeof i18nData)[SupportedLocale]];
if (!value) {
cwarn(`i18n key '${key}' not found in default language.`);
return `$${key}`;
Expand All @@ -451,7 +455,7 @@ export class Engine {
}

iactivity(
i18nLiteral: keyof (typeof i18nData)["en"],
i18nLiteral: keyof (typeof i18nData)["en-US"],
i18nArgs: Array<number | string> = [],
logStyle?: ActivityClass,
): void {
Expand All @@ -465,7 +469,7 @@ export class Engine {
}

imessage(
i18nLiteral: keyof (typeof i18nData)["en"],
i18nLiteral: keyof (typeof i18nData)["en-US"],
i18nArgs: Array<number | string> = [],
): void {
this._printOutput("ks-default", "#aa50fe", this.i18n(i18nLiteral, i18nArgs));
Expand Down
4 changes: 2 additions & 2 deletions packages/kitten-scientists/source/KittenScientists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { WorkshopSettings } from "./settings/WorkshopSettings.js";
import { cdebug, cinfo, cwarn } from "./tools/Log.js";
import { Game, I18nEngine } from "./types/index.js";
import { UserInterface } from "./ui/UserInterface.js";
import { FallbackLanguage, UserScriptLoader } from "./UserScriptLoader.js";
import { UserScriptLoader } from "./UserScriptLoader.js";

declare global {
const KS_RELEASE_CHANNEL: ReleaseChannel;
Expand Down Expand Up @@ -41,7 +41,7 @@ export class KittenScientists {
constructor(
game: Game,
i18nEngine: I18nEngine,
gameLanguage: GameLanguage = FallbackLanguage,
gameLanguage: GameLanguage = "en",
engineState?: EngineState,
) {
cinfo(`Kitten Scientists ${ksVersion("v")} constructed.`);
Expand Down
4 changes: 2 additions & 2 deletions packages/kitten-scientists/source/TimeControlManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ export class TimeControlManager {
const res = mustExist(this._host.game.resPool.get(name));
checkedList.push({
name: this._host.engine.i18n(`$resources.${entry.resource}.title`),
trigger: entry.stock,
trigger: entry.trigger,
val: res.value,
});
if (res.value < entry.stock) {
if (res.value < entry.trigger) {
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/kitten-scientists/source/TradeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ export class TradeManager implements Automation {

const currentCoin = this._host.game.resPool.get("blackcoin").value;
coinsExchanged = Math.round(currentCoin - coinsInitial);
this._host.engine.iactivity("blackcoin.buy", [
this._host.engine.iactivity("act.blackcoin.buy", [
this._host.game.getDisplayValueExt(coinsExchanged),
]);
} else if (
Expand All @@ -547,7 +547,7 @@ export class TradeManager implements Automation {
const relicsCurrent = mustExist(this._host.game.resPool.get("relic")).value;
relicsExchanged = Math.round(relicsCurrent - relicsInitial);

this._host.engine.iactivity("blackcoin.sell", [
this._host.engine.iactivity("act.blackcoin.sell", [
this._host.game.getDisplayValueExt(relicsExchanged),
]);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/kitten-scientists/source/UserScriptLoader.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { sleep } from "@oliversalzburg/js-utils/async/async.js";
import { ConstructorOf } from "@oliversalzburg/js-utils/core.js";
import { isNil, mustExist } from "@oliversalzburg/js-utils/data/nil.js";
import { EngineState, GameLanguage, SupportedLanguage } from "./Engine.js";
import { EngineState, GameLanguage, SupportedLocale } from "./Engine.js";
import { cdebug, cinfo } from "./tools/Log.js";

export const FallbackLanguage: GameLanguage & SupportedLanguage = "en";
export const FallbackLocale: SupportedLocale = "en-US";

// How long to wait for KG to load, in milliseconds.
const TIMEOUT_DEFAULT = 2 * 60 * 1000;
Expand Down
86 changes: 66 additions & 20 deletions packages/kitten-scientists/source/i18n/en-US.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"act.accelerate": "Accelerate time!",
"act.adore": "Adore the galaxy! Accumulated {0} worship to {1} epiphany",
"act.blackcoin.buy": "Kittens sold your Relics and bought {0} Blackcoins",
"act.blackcoin.sell": "Kittens sold your Blackcoins and bought {0} Relics",
"act.build": "Kittens have built a new {0}",
"act.builds": "Kittens have built a new {0} {1} times",
"act.craft": "Kittens have crafted {0} {1}",
Expand All @@ -24,11 +26,17 @@
"act.time.skip": "Kittens combust a time crystal, {0} years skipped!",
"act.trade": "Kittens have traded {0} times with {1}",
"act.transcend": "Spent {0} epiphany, Transcended to T-level: {1}",
"blackcoin.buy.threshold": "Buy Blackcoins below this price:",
"blackcoin.buy.prompt": "Enter at which price you want to stop buying blackcoins.",
"blackcoin.buy.promptExplainer": "Blackcoin price always rises from 800 to 1100 (roughly), then it crashes. You usually want to buy until shortly before you sell.",
"blackcoin.buy.promptTitle": "Buy Limit for Blackcoins (Current: {0})",
"blackcoin.buy.title": "Buy Blackcoins until price reaches {0}",
"blackcoin.buy.trigger": "buying Blackcoins (in relics)",
"blackcoin.buy": "Kittens sold your Relics and bought {0} Blackcoins",
"blackcoin.sell.threshold": "Sell Blackcoins above this price:",
"blackcoin.sell": "Kittens sold your Blackcoins and bought {0} Relics",
"blackcoin.buy": "Buy Limit: {0}",
"blackcoin.sell.prompt": "Enter at which price you want to sell all your blackcoins.",
"blackcoin.sell.promptExplainer": "Blackcoin price always rises from 800 to 1100 (roughly), then it crashes. You usually want to sell close to the highest possible price.",
"blackcoin.sell.promptTitle": "Sell Order for Blackcoins (Current: {0})",
"blackcoin.sell.title": "Sell Blackcoins when price reaches {0}",
"blackcoin.sell": "Sell Order: {0}",
"build.embassies": "Built {0} embassies for {1}",
"build.embassy": "Built {0} embassy for {1}",
"copy": "Copy to clipboard",
Expand Down Expand Up @@ -111,30 +119,43 @@
"reset.tip": "You can cancel this reset by disabling \"Enable Kitten Scientists\" at the top of the settings.",
"reset": "Reset",
"resources.consume.set": "Consume rate for {0}",
"resources.consume.title": "Consuming {0} of {1}",
"resources.consume.titleZero": "Not consuming {0}",
"resources.consume": "Consume: {0}",
"resources.stock.set": "Stock for {0}",
"resources.stock": "Stock: {0}",
"resources.consume.prompt": "Enter how much of the resource you want automations to consume as a percentage between 0.0 and 100.0.",
"resources.consume.promptExplainer": "If you submit an empty value, or an invalid value, it will be treated as if you hit Cancel.",
"resources.consume.promptTitle": "Consumption Share for {0} (Current: {1})",
"resources.stock.title": "Keeping {0} {1} in stock",
"resources.stock.titleInfinite": "Keeping all {0} in stock",
"resources.stock.titleZero": "Not keeping any {0} in stock",
"resources.stock.prompt": "Enter how much of the resource you always want to keep in stock.",
"resources.stock.promptExplainer": "You can enter large values with SI notation, like \"15.7T\". If you submit an empty value, or a negative value, the limit will be set to infinity. If you set the limit to 0, this option will be automatically disabled. If you submit an invalid value, it will be treated as if you hit Cancel.",
"resources.stock.promptTitle": "Stock value for {0} (Current: {1})",
"state.compress": "Compress copied Kittens Game saves",
"state.confirmDestruction": "Are you sure?",
"state.copied.game": "Save '{0}' copied to clipboard.",
"state.copied.gameCurrent": "Current save copied to clipboard.",
"state.copied.state": "State '{0}' copied to clipboard.",
"state.copied.stateCurrent": "Current state copied to clipboard.",
"state.copy.game": "Copy the entire Kittens Game save (includes KS settings) to the clipboard.",
"state.copy.state": "Copy the current Kitten Scientists settings to the clipboard.",
"state.copy": "Copy",
"state.copy.game": "Copy this save to the clipboard.",
"state.copy.gameCurrent": "Copy the entire Kittens Game save (includes KS settings) to the clipboard.",
"state.copy.state": "Copy these settings to the clipboard.",
"state.copy.stateCurrent": "Copy the current Kitten Scientists settings to the clipboard.",
"state.delete.game": "Delete this save.",
"state.delete.state": "Delete these settings.",
"state.deleted.game": "Save '{0}' deleted.",
"state.deleted.state": "State '{0}' deleted.",
"state.edit": "Rename",
"state.edit.game": "Change the name of this save.",
"state.edit.state": "Change the name of these settings.",
"state.exportAll": "Backup",
"state.exportAllTitle": "Stores all local states in a single file and downloads it.",
"state.import": "Import settings/saves",
"state.imported.game": "Save imported.",
"state.imported.state": "State imported.",
"state.importTitle": "Paste a save game or settings from your clipboard.\nContents will be automatically detected and handled accordingly.",
"state.importTitle": "Paste a save or settings from your clipboard.\nContents will be automatically detected and handled accordingly.",
"state.loaded.game": "Save '{0}' loaded.",
"state.loaded.state": "State '{0}' loaded.",
"state.loadPrompt": "Paste your (un/compressed) save game or settings here:",
"state.loadPrompt": "Paste your (un/compressed) save or settings here:",
"state.local": "Local storage management",
"state.localGames": "Kittens Game Saves",
"state.localStates": "Kitten Scientists Settings",
Expand All @@ -149,8 +170,10 @@
"state.storeState.prompt": "Provide a label for this state:",
"state.storeState": "Create a new state from current settings.",
"state.title": "State Management",
"state.unlabledGame": "unlabeled game",
"state.unlabledGame": "unlabeled save",
"state.unlabledState": "unlabeled state",
"state.update.game": "Save the current game into this slot.",
"state.update.state": "Save the current settings into this slot.",
"state.updated.game": "Save '{0}' updated.",
"state.updated.state": "State '{0}' updated.",
"status.auto.disable": "Disable Auto {0}",
Expand Down Expand Up @@ -209,48 +232,71 @@
"trade.unlimited": "Trading with {0}: unlimited",
"ui.additional": "Additional options",
"ui.build": "Bonfire",
"ui.buy": "Buy Limit: {0}",
"ui.close": "close",
"ui.craft.resources": "Resources",
"ui.craft": "Workshop",
"ui.cycles": "cycles",
"ui.disable.all": "disable all",
"ui.disable.all": "Disable all options in this list.",
"ui.distribute": "Village",
"ui.enable.all": "enable all",
"ui.enable.all": "Enable all options in this list.",
"ui.engine": "Enable Kitten Scientists",
"ui.faith": "Religion",
"ui.filter": "Log Filters",
"ui.infinity": "∞",
"ui.internals.interval.input": "Enter a new interval at which KS should run (in milliseconds):",
"ui.internals.interval": "Interval: {0}",
"ui.internals": "Internals",
"ui.itemsHide": "Hide options",
"ui.itemsShow": "Show options",
"ui.itemsHide": "Collapse section",
"ui.itemsShow": "Expand section",
"ui.ksColumn": "Display KS in fourth column in UI",
"ui.language": "Language",
"ui.limit": "Limited",
"ui.limited.off": "Unlimited",
"ui.limited.on": "Eco Mode",
"ui.max.build.prompt": "Limit for {0} (Current: {1})",
"ui.max.build.promptExplainer": "You can enter large values with SI notation, like \"15.7T\". If you submit an empty value, or a negative value, the limit will be set to infinity. If you set the limit to 0, this option will be automatically disabled. If you submit an invalid value, it will be treated as if you hit Cancel.",
"ui.max.build.title": "Build {0} {1}",
"ui.max.build.titleInfinite": "Never stop building {0}",
"ui.max.build.titleZero": "Don't build {0}",
"ui.max.embassy.title": "Build {0} embassy for {1}",
"ui.max.embassy.titleInfinite": "Never stop building embassies for {0}",
"ui.max.embassy.titleZero": "Don't build embassies for {0}",
"ui.max.prompt.absolute": "Enter the new limit as an absolute value between 0.0 and Infinity.",
"ui.max.set": "Maximum for {0}",
"ui.max": "Max: {0}",
"ui.maximum": "Maximum",
"ui.min": "Min: {0}",
"ui.options": "Options",
"ui.reset": "reset to defaults",
"ui.reset": "Reset list options to default configuration.",
"ui.resources": "Resource Control",
"ui.sell": "Sell Order: {0}",
"ui.space": "Space",
"ui.time": "Time",
"ui.timeCtrl": "Time Control",
"ui.trade": "Trade",
"ui.trigger.activeHeatTransfer.prompt": "Enter the new temporal heat storage level at which to enable heat transfer as a percentage between 0.0 and 100.0.",
"ui.trigger.activeHeatTransfer.promptExplainer": "If you submit an empty value, or an invalid value, it will be treated as if you hit Cancel.",
"ui.trigger.activeHeatTransfer.promptTitle": "Trigger for Heat Transfer (Current: {0})",
"ui.trigger.build.blocked": "∞\n🛈 The {0} section has no trigger set. This build will not be triggered!",
"ui.trigger.build.inherited": "inherited from section",
"ui.trigger.build.prompt": "Trigger for {0} (Current: {1})",
"ui.trigger.build.promptExplainer": "If you submit an empty value, or a negative value, the section trigger is used instead. If you submit an invalid value, it will be treated as if you hit Cancel.",
"ui.trigger.hunt.prompt": "Trigger for Hunting (Current: {0})",
"ui.trigger.hunt.promptExplainer": "If you submit a negative value, hunting will be disabled. If you submit an empty value, or an invalid value, it will be treated as if you hit Cancel.",
"ui.trigger.prompt.absolute": "Enter the new trigger value as an absolute value between 0.0 and Infinity.",
"ui.trigger.prompt.percentage": "Enter the new trigger value as a percentage between 0.0 and 100.0.",
"ui.trigger.inactive": "inactive",
"ui.trigger.reset.promptExplainer": "If you submit a negative value, the item will be disabled. If you submit an empty value, or an invalid value, it will be treated as if you hit Cancel.",
"ui.trigger.section.inactive": "∞ (nothing is built automatically)",
"ui.trigger.section.prompt": "Trigger for section {0} (Current: {1})",
"ui.trigger.section.promptExplainer": "If you submit an empty value, or a negative value, the section trigger will be set to infinity (∞), which disables all builds, unless they have their own trigger set.\nIf you submit an invalid value, it will be treated as if you hit Cancel.",
"ui.trigger.section": "Section default trigger: {0}",
"ui.trigger.setinteger": "Enter a new trigger value for {0}. Should be in the range from 0 up to any number. -1 means infinity.",
"ui.trigger.setinteger.promptExplainer": "If you submit an empty value, or an invalid value, it will be treated as if you hit Cancel.",
"ui.trigger.setpercentage": "Enter a new trigger value for {0}. Should be in the range from 0 to 100.",
"ui.trigger.setpercentage.promptExplainer": "If you submit an empty value, or an invalid value, it will be treated as if you hit Cancel.",
"ui.trigger.timeSkip.prompt": "Enter the new amount of Time Crystals at which to skip time as an absolute value between 1 and Infinity.",
"ui.trigger.timeSkip.promptExplainer": "If you submit a negative value, time skipping will be disabled. If you submit an empty value, or an invalid value, it will be treated as if you hit Cancel.",
"ui.trigger.timeSkip.promptTitle": "Trigger for Time Skip (Current: {0})",
"ui.trigger": "Trigger: {0}",
"ui.upgrade.buildings": "Upgrade buildings",
"ui.upgrade.missions": "Start missions",
Expand Down
Loading
Loading