Image picker: tiles are containers, not graphics with children
game-maker / suite (push) Successful in 9m14s

The twin of the font picker fixed earlier today: every tile was a Graphics
carrying its sprite and caption, which Pixi v8 answers with "addChild:
Only Containers will be allowed to add children". The background moves
into its own Graphics inside a Container, and the step watches the console
while the picker opens, as the font one does.

Editor suite: 784 checks.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
rootandClaude Opus 5 committed 2026-09-13 21:17:26 +02:00
1 parent 4f240a50fd
commit 03c4323794
3 files changed
+18 -8

No files matched your search

+10 -7
View File
@@ -1,4 +1,4 @@
import { type FederatedPointerEvent, Graphics, Sprite, Text } from 'pixi.js';
import { Container, type FederatedPointerEvent, Graphics, Sprite, Text } from 'pixi.js';
import type { StoredTexture } from '../../core/store/TextureStore';
import {
Button,
@@ -37,7 +37,7 @@ interface PickerItem extends StoredTexture {
*/
class ImageGrid extends Widget {
private items: PickerItem[] = [];
private tiles: { box: Graphics; sprite: Sprite; caption: Text }[] = [];
private tiles: { box: Container; background: Graphics; sprite: Sprite; caption: Text }[] = [];
private metrics: GridMetrics = gridMetrics(GRID_WIDTH, 0);
private selectedFile: string | null = null;
private readonly empty = new Text({ text: '', style: textStyle('muted') });
@@ -57,12 +57,15 @@ class ImageGrid extends Widget {
this.items = items;
for (const tile of this.tiles) tile.box.destroy({ children: true });
this.tiles = items.map(() => {
const box = new Graphics();
// A Container holding the background, not a Graphics with children: Pixi v8 only lets
// containers have them (`addChild: Only Containers will be allowed to add children`).
const box = new Container();
const background = new Graphics();
const sprite = new Sprite();
const caption = new Text({ style: textStyle('small') });
box.addChild(sprite, caption);
box.addChild(background, sprite, caption);
this.addChild(box);
return { box, sprite, caption };
return { box, background, sprite, caption };
});
if (!items.some((item) => item.file === this.selectedFile)) this.selectedFile = null;
this.layout();
@@ -128,8 +131,8 @@ class ImageGrid extends Widget {
const item = this.items[index];
if (!item) return;
const selected = item.file === this.selectedFile;
node.box.clear();
drawControlBox(node.box, side, side, {
node.background.clear();
drawControlBox(node.background, side, side, {
fill: selected ? Theme.colors.selection : Theme.colors.control,
border: selected ? Theme.colors.accent : Theme.colors.border,
});