Compare commits

...
2 Commits
Author SHA1 Message Date
Joel Brock f85a6fb9b7 Security hardening: drop npm deps and self-host Outfit font
- Remove package.json / package-lock.json. The only dependency was
  claude-flow (dev tooling, never loaded by the game), which pulled in
  49 known vulnerabilities (2 critical, 28 high) and could be installed
  by the Cloudflare Pages build.
- Self-host the Outfit variable font (latin + latin-ext woff2, SIL OFL)
  in fonts/ instead of loading it from Google Fonts. This removes the
  last third-party origins from the CSP (style-src / font-src are now
  'self' only), stops sending visitor IPs to Google, and makes the font
  work offline.
- Precache the font files in the service worker and bump CACHE_NAME to
  tortugotchi-v18.
2026-10-30 17:43:03 -07:00
Joel Brock fadf1ccd50 Suspend gameplay when unfocused and fix playmate voice mismatches
Pause the ocean decay/aging/hazard loops and ambient audio whenever the tab is
hidden or the window loses focus, and resume untouched on return. Remove the
offline catch-up decay so a turtle left alone freezes instead of dying, letting
turtles live and grow over a long real-world span.

Gate the playmate greeting/farewell voice clips (letsPlay/swimSafe) to the
green species whose text they match; loggerhead and leatherback play silently.
Also keep glub out of the ambient loop while a voice line plays. Bump SW to v17.
2026-06-22 15:14:40 -07:00
10 changed files with 186 additions and 9358 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
/*
Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data:; connect-src 'self'; manifest-src 'self'; worker-src 'self'; frame-ancestors 'none'; base-uri 'self'; form-action 'self'; object-src 'none'; upgrade-insecure-requests
Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; font-src 'self'; img-src 'self' data:; connect-src 'self'; manifest-src 'self'; worker-src 'self'; frame-ancestors 'none'; base-uri 'self'; form-action 'self'; object-src 'none'; upgrade-insecure-requests
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
Referrer-Policy: no-referrer
+65 -32
View File
@@ -148,16 +148,22 @@ document.addEventListener('DOMContentLoaded', () => {
softJellyfish: 'turtvox017_soft_jellyfish.m4a'
};
// The glub clip is a turtle vocalisation, so it must never overlap a voice
// line; the plain water clips are fine to play underneath voices.
const GLUB_SFX = 'turtvox008_glub_glub_glub.m4a';
const WATER_SFX = [
'water_sfx_001.m4a',
'water_sfx_002.m4a',
'water_sfx_003.m4a',
'turtvox008_glub_glub_glub.m4a'
GLUB_SFX
];
// Play a single turtle voice line. Autoplay is allowed because the player has
// already tapped through the start screen before any voice line fires.
let currentVoice = null;
function isVoicePlaying() {
return !!(currentVoice && !currentVoice.paused && !currentVoice.ended);
}
function playVoice(key) {
const file = TURT_VOX[key];
if (!file) return;
@@ -166,6 +172,12 @@ document.addEventListener('DOMContentLoaded', () => {
currentVoice = new Audio(MEDIA_PATH + file);
currentVoice.volume = 0.9;
currentVoice.play().catch(() => {});
// If the ambient loop is currently on the glub clip, skip it forward so
// the glub never plays on top of this voice line.
if (ambientAudio && WATER_SFX[ambientIndex] === GLUB_SFX) {
ambientIndex = (ambientIndex + 1) % WATER_SFX.length;
playAmbientClip();
}
} catch (e) { /* audio unsupported */ }
}
@@ -173,18 +185,28 @@ document.addEventListener('DOMContentLoaded', () => {
// for the whole time the player is in the ocean scene.
let ambientAudio = null;
let ambientIndex = 0;
function playAmbientClip() {
if (!ambientAudio) return;
// Never start the glub clip while a voice line is playing — advance past it.
let guard = 0;
while (WATER_SFX[ambientIndex] === GLUB_SFX && isVoicePlaying() && guard < WATER_SFX.length) {
ambientIndex = (ambientIndex + 1) % WATER_SFX.length;
guard++;
}
ambientAudio.src = MEDIA_PATH + WATER_SFX[ambientIndex];
ambientAudio.play().catch(() => {});
}
function startAmbientWater() {
if (ambientAudio) return;
ambientIndex = 0;
ambientAudio = new Audio(MEDIA_PATH + WATER_SFX[0]);
ambientAudio = new Audio();
ambientAudio.volume = 0.3;
ambientAudio.addEventListener('ended', () => {
if (!ambientAudio) return;
ambientIndex = (ambientIndex + 1) % WATER_SFX.length;
ambientAudio.src = MEDIA_PATH + WATER_SFX[ambientIndex];
ambientAudio.play().catch(() => {});
playAmbientClip();
});
ambientAudio.play().catch(() => {});
playAmbientClip();
}
function stopAmbientWater() {
if (!ambientAudio) return;
@@ -645,6 +667,29 @@ document.addEventListener('DOMContentLoaded', () => {
window.addEventListener('pagehide', saveProgress);
window.addEventListener('beforeunload', saveProgress);
// Suspend gameplay whenever the tab/window loses focus or is hidden, so the
// turtle never decays (or dies) while the player is away. Stats and growth
// simply freeze and resume untouched when the player returns. Only the ocean
// care phase runs the long-lived decay loops, so that is what we pause.
let oceanSuspended = false;
function suspendOcean() {
if (currentState !== STATES.OCEAN || oceanSuspended) return;
oceanSuspended = true;
saveProgress();
clearOceanLoops();
}
function resumeOcean() {
if (!oceanSuspended) return;
oceanSuspended = false;
if (currentState === STATES.OCEAN) startOceanLoops();
}
document.addEventListener('visibilitychange', () => {
if (document.hidden) suspendOcean();
else resumeOcean();
});
window.addEventListener('blur', suspendOcean);
window.addEventListener('focus', resumeOcean);
const ALLOWED_SPECIES = ['green', 'loggerhead', 'leatherback'];
function clampStat(n) {
const v = Number(n);
@@ -689,34 +734,13 @@ document.addEventListener('DOMContentLoaded', () => {
};
isSick = data.isSick === true;
const savedAt = Number(data.savedAt);
if (Number.isFinite(savedAt) && savedAt > 0 && savedAt <= Date.now()) {
const elapsedSec = Math.max(0, (Date.now() - savedAt) / 1000);
const cappedSec = Math.min(elapsedSec, 24 * 60 * 60);
applyOfflineProgression(cappedSec);
}
// No offline catch-up decay: gameplay is suspended whenever the tab is not
// focused (see the visibility/focus handlers), so a turtle left alone — for
// minutes or months — is simply paused and resumes exactly as it was left.
// This is what lets turtles live and grow over a very long real-world span.
return true;
}
function applyOfflineProgression(seconds) {
// Mirror the per-second rates from the decay loop
stats.hunger = Math.max(0, stats.hunger - 0.15 * seconds);
stats.joy = Math.max(0, stats.joy - 0.18 * seconds);
stats.clean = Math.max(0, stats.clean - 0.08 * seconds);
// Approximate health behavior over the elapsed window
const avgEnd = (stats.hunger + stats.joy + stats.clean) / 3;
if (avgEnd < 20) {
stats.health = Math.max(0, stats.health - 0.4 * seconds * 0.5); // gradual neglect damage
} else if (avgEnd > 60) {
stats.health = Math.min(100, stats.health + 0.05 * seconds * 0.2);
}
// Award age progression for the healthy portion of the absence
const offlineDays = computeAgeGain(seconds);
turtleAge += Math.floor(offlineDays);
}
// ==========================================
// AGING & GROWTH HELPERS
// ==========================================
@@ -1536,6 +1560,9 @@ document.addEventListener('DOMContentLoaded', () => {
name: 'shrimp friend',
greeting: "A shrimp friend! Let's chase! 🦐",
farewell: "Bye shrimp pal! 👋",
// No matching voice clip for the shrimp lines.
greetingVoice: null,
farewellVoice: null,
color: 'rgba(255, 140, 120, 0.9)'
};
case 'leatherback':
@@ -1544,6 +1571,9 @@ document.addEventListener('DOMContentLoaded', () => {
name: 'squid buddy',
greeting: "Glowing squid buddy! Deep dive! 🦑",
farewell: "See you in the depths! 🌊",
// No matching voice clip for the squid lines.
greetingVoice: null,
farewellVoice: null,
color: 'rgba(180, 130, 255, 0.95)'
};
case 'green':
@@ -1553,6 +1583,9 @@ document.addEventListener('DOMContentLoaded', () => {
name: 'turtle pal',
greeting: "Another turtle! Let's play! 🐢",
farewell: "Swim safe, friend! 💚",
// The letsPlay/swimSafe clips say "another turtle"/"swim safe friend".
greetingVoice: 'letsPlay',
farewellVoice: 'swimSafe',
color: 'rgba(120, 200, 160, 0.95)'
};
}
@@ -1571,7 +1604,7 @@ document.addEventListener('DOMContentLoaded', () => {
updateStatBars();
setEyeState('happy');
setMouthState('normal');
triggerThoughtBubble(info.greeting, 2200, 'letsPlay');
triggerThoughtBubble(info.greeting, 2200, info.greetingVoice);
// Random darting motion around the playpen
const pen = oceanPlaypen.getBoundingClientRect();
@@ -1639,7 +1672,7 @@ document.addEventListener('DOMContentLoaded', () => {
stats.joy = Math.min(100, stats.joy + Math.min(15, highFives * 2));
updateStatBars();
}
triggerThoughtBubble(info.farewell, 1800, 'swimSafe');
triggerThoughtBubble(info.farewell, 1800, info.farewellVoice);
setTimeout(() => setEyeState('normal'), 1200);
const m = activePlaymate;
activePlaymate = null;
+93
View File
@@ -0,0 +1,93 @@
Copyright 2021 The Outfit Project Authors (https://github.com/Outfitio/Outfit-Fonts)
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
https://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file not shown.
Binary file not shown.
+2 -4
View File
@@ -17,10 +17,8 @@
<meta name="description" content="Help raise awareness for sea turtle conservation! Guard nests, guide hatchlings to the ocean, raise your own sea turtle, and protect it from human and environmental hazards in this interactive Tamagotchi-style game.">
<meta name="keywords" content="sea turtle, conservation, tamagotchi, game, PWA, marine life, endangered species">
<!-- Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@400;600;800&display=swap" rel="stylesheet">
<!-- Fonts (self-hosted Outfit, declared in style.css) -->
<link rel="preload" href="fonts/outfit-latin.woff2" as="font" type="font/woff2" crossorigin>
<link rel="stylesheet" href="style.css">
</head>
-9315
View File
File diff suppressed because it is too large Load Diff
-5
View File
@@ -1,5 +0,0 @@
{
"dependencies": {
"claude-flow": "^3.7.0-alpha.72"
}
}
+22
View File
@@ -1,3 +1,25 @@
/* ==========================================================================
FONTS — self-hosted Outfit variable font (SIL OFL 1.1, see fonts/OFL.txt)
========================================================================== */
/* latin-ext */
@font-face {
font-family: 'Outfit';
font-style: normal;
font-weight: 400 800;
font-display: swap;
src: url('fonts/outfit-latin-ext.woff2') format('woff2');
unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
font-family: 'Outfit';
font-style: normal;
font-weight: 400 800;
font-display: swap;
src: url('fonts/outfit-latin.woff2') format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* ==========================================================================
DESIGN TOKENS & SYSTEM ROOT
========================================================================== */
+3 -1
View File
@@ -1,4 +1,4 @@
const CACHE_NAME = 'tortugotchi-v15';
const CACHE_NAME = 'tortugotchi-v18';
const ASSETS = [
'./',
'./index.html',
@@ -7,6 +7,8 @@ const ASSETS = [
'./manifest.json',
'./icon-192.png',
'./icon-512.png',
'./fonts/outfit-latin.woff2',
'./fonts/outfit-latin-ext.woff2',
'./media/turtvox001_another_day_in_the_deep_blue.m4a',
'./media/turtvox002_best_human_ever.m4a',
'./media/turtvox003_bitten_shell_but_ok.m4a',