mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-28 04:14:16 +00:00
dd9ad7472f
## Description: 1. Remove SpawnAds and replace it with AdTimer which will delete the in-game ad after the first minute. 2. remove login blocker UI, we don't use it anymore 3. convert TerritoryPatternsModal & GutterAds to use event based when checking for flares 4. remove window.PageOS.session.newPageView(); because it was throwing an exception 5. Convert SpawnTimer to a lit element to give it a higher z-index to stay above the header ad ## 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: evan
118 lines
2.9 KiB
TypeScript
118 lines
2.9 KiB
TypeScript
import { LitElement, html } from "lit";
|
|
import { customElement } from "lit/decorators.js";
|
|
import { GameMode, Team } from "../../../core/game/Game";
|
|
import { GameView } from "../../../core/game/GameView";
|
|
import { TransformHandler } from "../TransformHandler";
|
|
import { Layer } from "./Layer";
|
|
|
|
@customElement("spawn-timer")
|
|
export class SpawnTimer extends LitElement implements Layer {
|
|
public game: GameView;
|
|
public transformHandler: TransformHandler;
|
|
|
|
private ratios = [0];
|
|
private colors = ["rgba(0, 128, 255, 0.7)", "rgba(0, 0, 0, 0.5)"];
|
|
|
|
private isVisible = false;
|
|
|
|
createRenderRoot() {
|
|
this.style.position = "fixed";
|
|
this.style.top = "0";
|
|
this.style.left = "0";
|
|
this.style.width = "100%";
|
|
this.style.height = "7px";
|
|
this.style.zIndex = "1000";
|
|
this.style.pointerEvents = "none";
|
|
return this;
|
|
}
|
|
|
|
init() {
|
|
this.isVisible = true;
|
|
}
|
|
|
|
tick() {
|
|
if (this.game.inSpawnPhase()) {
|
|
// During spawn phase, only one segment filling full width
|
|
this.ratios = [
|
|
this.game.ticks() / this.game.config().numSpawnPhaseTurns(),
|
|
];
|
|
this.colors = ["rgba(0, 128, 255, 0.7)"];
|
|
this.requestUpdate();
|
|
return;
|
|
}
|
|
|
|
this.ratios = [];
|
|
this.colors = [];
|
|
|
|
if (this.game.config().gameConfig().gameMode !== GameMode.Team) {
|
|
this.requestUpdate();
|
|
return;
|
|
}
|
|
|
|
const teamTiles: Map<Team, number> = new Map();
|
|
for (const player of this.game.players()) {
|
|
const team = player.team();
|
|
if (team === null) throw new Error("Team is null");
|
|
const tiles = teamTiles.get(team) ?? 0;
|
|
teamTiles.set(team, tiles + player.numTilesOwned());
|
|
}
|
|
|
|
const theme = this.game.config().theme();
|
|
const total = sumIterator(teamTiles.values());
|
|
if (total === 0) {
|
|
this.requestUpdate();
|
|
return;
|
|
}
|
|
|
|
for (const [team, count] of teamTiles) {
|
|
const ratio = count / total;
|
|
this.ratios.push(ratio);
|
|
this.colors.push(theme.teamColor(team).toRgbString());
|
|
}
|
|
this.requestUpdate();
|
|
}
|
|
|
|
shouldTransform(): boolean {
|
|
return false;
|
|
}
|
|
|
|
render() {
|
|
if (!this.isVisible) {
|
|
return html``;
|
|
}
|
|
|
|
if (this.ratios.length === 0 || this.colors.length === 0) {
|
|
return html``;
|
|
}
|
|
|
|
if (
|
|
!this.game.inSpawnPhase() &&
|
|
this.game.config().gameConfig().gameMode !== GameMode.Team
|
|
) {
|
|
return html``;
|
|
}
|
|
|
|
return html`
|
|
<div class="w-full h-full flex z-[999]">
|
|
${this.ratios.map((ratio, i) => {
|
|
const color = this.colors[i] || "rgba(0, 0, 0, 0.5)";
|
|
return html`
|
|
<div
|
|
class="h-full transition-all duration-100 ease-in-out"
|
|
style="width: ${ratio * 100}%; background-color: ${color};"
|
|
></div>
|
|
`;
|
|
})}
|
|
</div>
|
|
`;
|
|
}
|
|
}
|
|
|
|
function sumIterator(values: MapIterator<number>) {
|
|
let total = 0;
|
|
for (const value of values) {
|
|
total += value;
|
|
}
|
|
return total;
|
|
}
|