mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 13:30:43 +00:00
Build bar (#2059)
## Description: Make the unit display bar a proper unit build bar Add shortcuts for all structures and units Add ranges for ranged structures and units Changed the shortcuts to use the key instead of the code for internationalization purposes  <img width="285" height="517" alt="image" src="https://github.com/user-attachments/assets/91bb01e6-e48c-4255-ace1-306af9cdc25b" /> ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: Mr.Box --------- Co-authored-by: evanpelle <evanpelle@gmail.com> Co-authored-by: icslucas <carolinacarazolli@gmail.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
@@ -36,7 +36,11 @@ describe("InputHandler AutoUpgrade", () => {
|
||||
|
||||
eventBus = new EventBus();
|
||||
|
||||
inputHandler = new InputHandler(mockCanvas, eventBus);
|
||||
inputHandler = new InputHandler(
|
||||
{ attackRatio: 20, ghostStructure: null },
|
||||
mockCanvas,
|
||||
eventBus,
|
||||
);
|
||||
});
|
||||
|
||||
describe("Middle Mouse Button Handling", () => {
|
||||
@@ -397,4 +401,58 @@ describe("InputHandler AutoUpgrade", () => {
|
||||
expect(mockListener).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Keybinds JSON parsing", () => {
|
||||
beforeEach(() => {
|
||||
localStorage.removeItem("settings.keybinds");
|
||||
});
|
||||
|
||||
test("parses nested object values and flattens them to strings", () => {
|
||||
const nested = {
|
||||
moveUp: { key: "moveUp", value: "KeyZ" },
|
||||
};
|
||||
localStorage.setItem("settings.keybinds", JSON.stringify(nested));
|
||||
|
||||
inputHandler.initialize();
|
||||
|
||||
expect((inputHandler as any).keybinds.moveUp).toBe("KeyZ");
|
||||
});
|
||||
|
||||
test("accepts legacy string values", () => {
|
||||
localStorage.setItem(
|
||||
"settings.keybinds",
|
||||
JSON.stringify({ moveUp: "KeyX" }),
|
||||
);
|
||||
|
||||
inputHandler.initialize();
|
||||
|
||||
expect((inputHandler as any).keybinds.moveUp).toBe("KeyX");
|
||||
});
|
||||
|
||||
test("ignores non-string and 'Null' values and preserves defaults", () => {
|
||||
const mixed = {
|
||||
moveUp: { key: "moveUp", value: null },
|
||||
moveLeft: "Null",
|
||||
};
|
||||
localStorage.setItem("settings.keybinds", JSON.stringify(mixed));
|
||||
|
||||
inputHandler.initialize();
|
||||
|
||||
// defaults from InputHandler should remain
|
||||
expect((inputHandler as any).keybinds.moveUp).toBe("KeyW");
|
||||
expect((inputHandler as any).keybinds.moveLeft).toBe("KeyA");
|
||||
});
|
||||
|
||||
test("handles invalid JSON gracefully and warns", () => {
|
||||
const spy = jest.spyOn(console, "warn").mockImplementation(() => {});
|
||||
localStorage.setItem("settings.keybinds", "not a json");
|
||||
|
||||
inputHandler.initialize();
|
||||
|
||||
expect(spy).toHaveBeenCalled();
|
||||
// default remains when parsing fails
|
||||
expect((inputHandler as any).keybinds.moveUp).toBe("KeyW");
|
||||
spy.mockRestore();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user