This commit is contained in:
Renan LE CARO 2025-04-20 10:58:26 +02:00
parent 70f3c2307a
commit 1ba55bf2a6
13 changed files with 122 additions and 114 deletions

View file

@ -1,5 +1,5 @@
// The version of the cache.
const VERSION = "29085573";
const VERSION = "29085612";
// The name of the cache
const CACHE_NAME = `breakout-71-${VERSION}`;

View file

@ -1 +1 @@
"29085573"
"29085612"

View file

@ -23,6 +23,7 @@ import {
describeLevel,
getRowColIndex,
highScoreText,
isInWebView,
levelsListHTMl,
max_levels,
pickedUpgradesHTMl,
@ -36,7 +37,7 @@ import { getCurrentLang, languages, t } from "./i18n/i18n";
import {
commitSettingsChangesToLocalStorage,
cycleMaxCoins,
getCurrentMaxCoins,
getCurrentMaxCoins, getCurrentMaxParticles,
getSettingValue,
getTotalScore,
setSettingValue,
@ -113,7 +114,12 @@ export async function play() {
export function pause(playerAskedForPause: boolean) {
if (!gameState.running) return;
if (gameState.pauseTimeout) return;
if (gameState.startParams.computer_controlled) return;
if (gameState.startParams.computer_controlled) {
if (gameState.startParams?.computer_controlled) {
play();
}
return;
}
const stop = () => {
gameState.running = false;
@ -475,17 +481,12 @@ export function tick() {
FPSCounter++;
}
let FPSCounter = 0;
export let lastMeasuredFPS = 60;
setInterval(() => {
lastMeasuredFPS = FPSCounter;
FPSCounter = 0;
}, 1000);
const stats = document.getElementById("stats") as HTMLDivElement;
let total = {};
let lastTick = performance.now();
let doing = "idle";
let FPSCounter = 0;
export let lastMeasuredFPS = 60;
export function startWork(what) {
if (!gameState.startParams.stress) return;
const newNow = performance.now();
@ -496,6 +497,10 @@ export function startWork(what) {
doing = what;
}
setInterval(() => {
lastMeasuredFPS = FPSCounter;
FPSCounter = 0;
if (!gameState.startParams.stress) {
stats.style.display = "none";
return;
@ -506,10 +511,12 @@ setInterval(() => {
stats.innerHTML =
`
<div>
<strong>Coins ${liveCount(gameState.coins)} / ${getCurrentMaxCoins()} - Particles : ${liveCount(gameState.particles) + liveCount(gameState.lights) + liveCount(gameState.texts)}</strong>
</div>
${lastMeasuredFPS} FPS -
${liveCount(gameState.coins)} / ${getCurrentMaxCoins()} Coins -
${liveCount(gameState.particles) + liveCount(gameState.lights) + liveCount(gameState.texts)} / ${getCurrentMaxParticles()*3} particles
</div>
` +
@ -519,7 +526,7 @@ setInterval(() => {
(t) =>
` <div>
<div style="transform: scale(${clamp(t[1] / totalTime, 0, 1)},1)"></div>
<strong>${t[0]} : ${t[1]} ms</strong>
<strong>${t[0]} : ${Math.floor(t[1])} ms</strong>
</div>
`,
)
@ -694,6 +701,7 @@ async function openSettingsMenu() {
"precise_lighting",
"probabilistic_lighting",
].includes(key)) ||
(isInWebView && key == "record") ||
false,
value: () => {
toggleOption(key);

View file

@ -421,3 +421,5 @@ export function getCornerOffset(gameState: GameState) {
gameState.perks.unbounded * gameState.brickWidth
);
}
export const isInWebView = !!window.location.href.includes("isInWebView=true");

View file

@ -1,5 +1,5 @@
import { gameCanvas } from "./render";
import { max_levels } from "./game_utils";
import { isInWebView, max_levels } from "./game_utils";
import { getAudioRecordingTrack } from "./sounds";
import { t } from "./i18n/i18n";
import { GameState } from "./types";
@ -12,7 +12,7 @@ let mediaRecorder: MediaRecorder | null,
recordCanvasCtx: CanvasRenderingContext2D;
export function recordOneFrame(gameState: GameState) {
if (!isOptionOn("record")) {
if (!isOptionOn("record") || isInWebView) {
return;
}
// if (!gameState.running) return;
@ -59,7 +59,7 @@ export function drawMainCanvasOnSmallCanvas(gameState: GameState) {
}
export function startRecordingGame(gameState: GameState) {
if (!isOptionOn("record")) {
if (!isOptionOn("record") || isInWebView) {
return;
}
if (mediaRecorder) return;
@ -124,11 +124,8 @@ export function startRecordingGame(gameState: GameState) {
const a = document.createElement("a");
a.download = captureFileName("webm");
a.target = "_blank";
if (window.location.href.endsWith("index.html?isInWebView=true")) {
a.href = await blobToBase64(blob);
} else {
a.href = video.src;
}
a.href = video.src;
a.textContent = t("settings.record_download", {
size: (blob.size / 1000000).toFixed(2),
@ -137,22 +134,6 @@ export function startRecordingGame(gameState: GameState) {
};
}
function blobToBase64(blob: Blob): Promise<string> {
return new Promise((resolve, reject) => {
let reader = new FileReader();
reader.onload = function () {
resolve(reader.result);
};
reader.onerror = function (e) {
console.error(e);
reject(new Error("Failed to readAsDataURL of the video "));
};
reader.readAsDataURL(blob);
});
}
export function pauseRecording() {
if (!isOptionOn("record")) {
return;