mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-09 22:08:04 +00:00
050c7604e8
## Description:
Replaces the "Disable alliances" toggle in the host and single-player
lobbies with a "Custom alliances" control: a toggle plus a minutes input
(0 to 15, step 1).
- 0 minutes disables alliances, same behavior as the old toggle.
- 1 to 15 sets the alliance duration in minutes.
How it works:
- Adds one game-config field, `customAllianceDuration` (minutes).
- `Config.allianceDuration()` uses it when set (and falls back to the
existing 5 minute default), and `Config.disableAlliances()` returns true
when it is 0.
- The legacy `disableAlliances` boolean is still read, so older/archived
configs keep working.
- Validation reuses the existing `parseBoundedIntegerFromInput` and
`toggle-input-card` helpers, so it behaves like the other numeric lobby
options (spawn immunity, max timer).
- The join-lobby screen shows "Alliances: {x}m", or "Alliances:
Disabled" at 0.
<img width="279" height="145" alt="image"
src="https://github.com/user-attachments/assets/5a608e18-3811-4eef-a3a6-9344aaf667fe"
/>
<img width="270" height="152" alt="image"
src="https://github.com/user-attachments/assets/9d8a4d30-51e7-4e82-8ce0-121b12af1c61"
/>
<img width="270" height="144" alt="image"
src="https://github.com/user-attachments/assets/a65b20fb-0db5-4657-a964-880fad7c864e"
/>
## 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
## Please put your Discord username so you can be contacted if a bug or
regression is found:
zixer._
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { Config } from "../src/core/configuration/Config";
|
|
import { GameConfig } from "../src/core/Schemas";
|
|
|
|
// The "custom alliances" lobby control writes customAllianceDuration (minutes):
|
|
// 0 disables alliances, 1-15 sets the alliance duration, unset = default.
|
|
function cfg(over: Partial<GameConfig>): Config {
|
|
return new Config(over as unknown as GameConfig, null, false);
|
|
}
|
|
|
|
describe("custom alliance duration", () => {
|
|
it("0 minutes disables alliances", () => {
|
|
expect(cfg({ customAllianceDuration: 0 }).disableAlliances()).toBe(true);
|
|
});
|
|
|
|
it("a positive value keeps alliances on, minutes converted to ticks", () => {
|
|
const c = cfg({ customAllianceDuration: 5 });
|
|
expect(c.disableAlliances()).toBe(false);
|
|
expect(c.allianceDuration()).toBe(5 * 60 * 10);
|
|
});
|
|
|
|
it("15 minutes (the max) converts correctly", () => {
|
|
expect(cfg({ customAllianceDuration: 15 }).allianceDuration()).toBe(
|
|
15 * 60 * 10,
|
|
);
|
|
});
|
|
|
|
it("unset falls back to the 5 minute default with alliances on", () => {
|
|
const c = cfg({});
|
|
expect(c.disableAlliances()).toBe(false);
|
|
expect(c.allianceDuration()).toBe(300 * 10);
|
|
});
|
|
|
|
it("the legacy disableAlliances boolean still disables", () => {
|
|
expect(cfg({ disableAlliances: true }).disableAlliances()).toBe(true);
|
|
});
|
|
});
|