Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(gates): colour literals are counted as colours, and bank zero

esengine89d9ffef8605
diff --git a/desktop b/desktop
index a559ac3b9..fb736f713 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit a559ac3b9cb5d438676cd0fe9a575779c09f4e13
+Subproject commit fb736f71347666a2fa8b53857aea798fe7a87a9e
diff --git a/tools/baselines/theme-drift.json b/tools/baselines/theme-drift.json
index 8e917939c..9e6059eae 100644
--- a/tools/baselines/theme-drift.json
+++ b/tools/baselines/theme-drift.json
@@ -20,47 +20,8 @@
"viewport.css": 5,
"world.css": 1
},
- "colourLiterals": {
- "app.css": 26,
- "chrome.css": 7,
- "content.css": 7,
- "controllers.css": 5,
- "controls.css": 1,
- "events.css": 3,
- "flipbook.css": 3,
- "inspector.css": 39,
- "launcher.css": 3,
- "log.css": 1,
- "menus.css": 2,
- "nodegraph.css": 1,
- "outliner.css": 8,
- "plugins.css": 9,
- "profiler.css": 11,
- "sequencer.css": 1,
- "settings.css": 1,
- "tilemap.css": 1,
- "tileset.css": 13,
- "viewport.css": 15
- },
- "colourLiteralsInCode": {
- "components/AudioWavePreview.tsx": 2,
- "components/ColorControl.tsx": 3,
- "components/PerfOverlay.tsx": 1,
- "components/SettingsRow.tsx": 3,
- "diagnostics/redact.ts": 2,
- "engine/overlayDraw.ts": 1,
- "panels/BtTreeEditor.tsx": 3,
- "panels/CollisionBrushPalette.tsx": 1,
- "panels/ContentBrowser.tsx": 3,
- "panels/Details.tsx": 1,
- "panels/inspector/controls.tsx": 1,
- "panels/ProfilerPanel.tsx": 1,
- "panels/SpinePreviewPane.tsx": 4,
- "panels/Viewport.tsx": 2,
- "settings/editorSettings.ts": 10,
- "tileset/TilesetCommands.ts": 8,
- "tools/tileMath.ts": 6
- },
+ "colourLiterals": {},
+ "colourLiteralsInCode": {},
"rawFontSize": {},
"iconScale": {
"sizes": [
diff --git a/tools/check-theme.mjs b/tools/check-theme.mjs
index 08aa6dc52..3886fa9de 100644
--- a/tools/check-theme.mjs
+++ b/tools/check-theme.mjs
@@ -273,12 +273,24 @@ const offGridByFile = () => {
/** Colour written where a token belongs. tokens.css is the one place they are
* DEFINED, so it is the one file exempt. */
+/**
+ * Colours that are what a control SHOWS rather than a choice from the palette,
+ * by file then selector, each with the reason. `rgba(var(--x), a)` reads a token
+ * and is not counted; neither is a colour inside a comment.
+ */
+const THEME_NOT_THE_PALETTE = {
+ 'inspector.css': { '.cp-hue': 'the hue slider draws the spectrum itself' },
+};
+
const colourLiteralsByFile = () => {
const out = {};
for (const f of readdirSync(THEME_DIR).filter((n) => n.endsWith('.css') && n !== 'tokens.css')) {
- const text = readFileSync(path.join(THEME_DIR, f), 'utf8');
- const n = (text.match(/#[0-9a-fA-F]{3,8}\b/g)?.length ?? 0)
- + (text.match(/\brgba?\(/g)?.length ?? 0);
+ const text = uncomment(readFileSync(path.join(THEME_DIR, f), 'utf8'));
+ const exempt = THEME_NOT_THE_PALETTE[f] ?? {};
+ let n = 0;
+ for (const m of text.matchAll(/#[0-9a-fA-F]{3,8}\b|\brgba?\((?!\s*var\()/g)) {
+ if (!(selectorAt(text, m.index) in exempt)) n += 1;
+ }
if (n > 0) out[f] = n;
}
return out;
@@ -422,6 +434,14 @@ const handRolledByFile = () => {
* can reach is not one anybody aims at.
*/
const NOT_THE_PALETTE = {
+ 'settings/editorSettings.ts':
+ "the accent setting's default and the swatches it offers are values a person picks from; "
+ + 'tests/theme-tokens.test.ts holds the default to --star',
+ 'tileset/TilesetCommands.ts': "default colours written into a new Wang set's data, which the tileset then owns",
+ 'tools/tileMath.ts': "default colours written into a new terrain's data, which the tileset then owns",
+ 'components/SettingsRow.tsx': "'#00000000' is a colour input's empty value, not a colour anything is drawn in",
+ 'panels/ProfilerPanel.tsx':
+ 'NO_TOKEN is off the palette on purpose: a var() that names nothing paints a grey someone notices',
'components/LoadingScreen.tsx':
'the Estella mark itself (see favicon.svg). Its blue and --star came from the same place,'
+ ' but a logo that moves when the accent moves is not a logo',
@@ -445,9 +465,14 @@ const colourLiteralInCodeByFile = () => {
if (!/\.tsx?$/.test(e.name) || e.name.includes('.generated.')) continue;
const rel = path.relative(path.join(ROOT, 'desktop', 'src'), full).replaceAll(path.sep, '/');
if (rel in NOT_THE_PALETTE) continue;
- const text = readFileSync(full, 'utf8');
+ // Comments out (an issue number is not a colour), then `rgb(var(…))` and
+ // `rgb(${…})` left alone: the first reads a token, the second writes a value
+ // that came from data.
+ const text = readFileSync(full, 'utf8')
+ .replace(/\/\*[\s\S]*?\*\//g, '')
+ .replace(/(^|[^:'"`\w])\/\/.*$/gm, '$1');
const n = (text.match(/#[0-9a-fA-F]{3,8}\b/g)?.length ?? 0)
- + (text.match(/\brgba?\(/g)?.length ?? 0);
+ + (text.match(/\brgba?\((?!\s*var\()(?!\$\{)/g)?.length ?? 0);
if (n > 0) out[rel] = n;
}
};