Skip to content

Commit c203291

Browse files
Post Op
1 parent 7d525b9 commit c203291

39 files changed

Lines changed: 1767 additions & 535 deletions

lib/components/inspector/hologram_inspector.dart

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,24 @@ class _HologramInspectorState extends State<HologramInspector> {
5858
]);
5959
}
6060

61-
Widget _header(GlossHologramDoc doc) =>
62-
dom.div(classes: 'hui-inspector-headgroup', <Widget>[
63-
dom.div(classes: 'hui-inspector-header is-hologram', <Widget>[
64-
const HuiEyebrow('Hologram'),
65-
dom.div(classes: 'hui-inspector-title-row', <Widget>[
66-
dom.h2(classes: 'hui-inspector-title', <Widget>[
67-
Text(_store.menuId),
68-
]),
69-
const HuiFieldHelp('hologram.id'),
70-
]),
71-
]),
72-
dom.p(classes: 'hui-inspector-lede', <Widget>[
73-
Text(
74-
'One TextDisplay at a world anchor. Revision ${doc.revision} is '
75-
'server-owned and travels with the file.',
76-
),
61+
Widget _header(GlossHologramDoc doc) => dom.div(
62+
classes: 'hui-inspector-headgroup',
63+
<Widget>[
64+
dom.div(classes: 'hui-inspector-header is-hologram', <Widget>[
65+
const HuiEyebrow('Hologram'),
66+
dom.div(classes: 'hui-inspector-title-row', <Widget>[
67+
dom.h2(classes: 'hui-inspector-title', <Widget>[Text(_store.menuId)]),
68+
const HuiFieldHelp('hologram.id'),
7769
]),
78-
]);
70+
]),
71+
dom.p(classes: 'hui-inspector-lede', <Widget>[
72+
Text(
73+
'One TextDisplay at a world anchor. Revision ${doc.revision} is '
74+
'server-owned and travels with the file.',
75+
),
76+
]),
77+
],
78+
);
7979

8080
Widget _anchor(GlossHologramDoc doc) {
8181
final List<double> position = doc.anchor.position;
@@ -165,13 +165,11 @@ class _HologramInspectorState extends State<HologramInspector> {
165165
else
166166
HuiReorderList(
167167
itemCount: doc.lines.length,
168-
onReorder: (int from, int to) => _store.mutateHologram(
169-
'reorder line',
170-
(GlossHologramDoc edited) {
171-
final String moved = edited.lines.removeAt(from);
172-
edited.lines.insert(to, moved);
173-
},
174-
),
168+
onReorder: (int from, int to) =>
169+
_store.mutateHologram('reorder line', (GlossHologramDoc edited) {
170+
final String moved = edited.lines.removeAt(from);
171+
edited.lines.insert(to, moved);
172+
}),
175173
itemBuilder: (int index) => _lineRow(doc, index),
176174
),
177175
HuiInlineIssues(_issuesFor('lines[')),
@@ -185,7 +183,7 @@ class _HologramInspectorState extends State<HologramInspector> {
185183
value: line,
186184
size: ComponentSize.sm,
187185
fullWidth: true,
188-
placeholder: '&fText, [FFAA00]hex, %papi%, |animation.id|',
186+
placeholder: '&fText, %papi%, |animation.id|, {{ expression }}',
189187
onInput: (String value) => _editLine(index, value),
190188
onFocus: () => _focusedLine = index,
191189
attributes: <String, String>{
@@ -206,22 +204,18 @@ class _HologramInspectorState extends State<HologramInspector> {
206204
HuiIconButton(
207205
label: 'Delete line',
208206
icon: ArcaneIcon.trash2(size: IconSize.sm),
209-
onPressed: () => _store.mutateHologram(
210-
'delete line',
211-
(GlossHologramDoc edited) {
212-
if (index < edited.lines.length) edited.lines.removeAt(index);
213-
},
214-
),
207+
onPressed: () =>
208+
_store.mutateHologram('delete line', (GlossHologramDoc edited) {
209+
if (index < edited.lines.length) edited.lines.removeAt(index);
210+
}),
215211
),
216212
]);
217213
}
218214

219-
void _editLine(int index, String value) => _store.mutateHologram(
220-
'edit line',
221-
(GlossHologramDoc edited) {
222-
if (index < edited.lines.length) edited.lines[index] = value;
223-
},
224-
);
215+
void _editLine(int index, String value) =>
216+
_store.mutateHologram('edit line', (GlossHologramDoc edited) {
217+
if (index < edited.lines.length) edited.lines[index] = value;
218+
});
225219

226220
void _insertPlaceholder(String token) {
227221
final GlossHologramDoc? doc = _doc;

lib/components/inspector/scoreboard_inspector.dart

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,24 @@ class _ScoreboardInspectorState extends State<ScoreboardInspector> {
5959
]);
6060
}
6161

62-
Widget _header(GlossScoreboardDoc doc) =>
63-
dom.div(classes: 'hui-inspector-headgroup', <Widget>[
64-
dom.div(classes: 'hui-inspector-header is-scoreboard', <Widget>[
65-
const HuiEyebrow('Scoreboard'),
66-
dom.div(classes: 'hui-inspector-title-row', <Widget>[
67-
dom.h2(classes: 'hui-inspector-title', <Widget>[
68-
Text(_store.menuId),
69-
]),
70-
const HuiFieldHelp('scoreboard.id'),
71-
]),
72-
]),
73-
dom.p(classes: 'hui-inspector-lede', <Widget>[
74-
Text(
75-
'The right-hand sidebar. Revision ${doc.revision} is '
76-
'server-owned and travels with the file.',
77-
),
62+
Widget _header(GlossScoreboardDoc doc) => dom.div(
63+
classes: 'hui-inspector-headgroup',
64+
<Widget>[
65+
dom.div(classes: 'hui-inspector-header is-scoreboard', <Widget>[
66+
const HuiEyebrow('Scoreboard'),
67+
dom.div(classes: 'hui-inspector-title-row', <Widget>[
68+
dom.h2(classes: 'hui-inspector-title', <Widget>[Text(_store.menuId)]),
69+
const HuiFieldHelp('scoreboard.id'),
7870
]),
79-
]);
71+
]),
72+
dom.p(classes: 'hui-inspector-lede', <Widget>[
73+
Text(
74+
'The right-hand sidebar. Revision ${doc.revision} is '
75+
'server-owned and travels with the file.',
76+
),
77+
]),
78+
],
79+
);
8080

8181
Widget _title(GlossScoreboardDoc doc) => InspectorSection(
8282
title: 'Title',
@@ -173,7 +173,7 @@ class _ScoreboardInspectorState extends State<ScoreboardInspector> {
173173
value: line,
174174
size: ComponentSize.sm,
175175
fullWidth: true,
176-
placeholder: '&fText, %papi%, |animation.id|',
176+
placeholder: '&fText, %papi%, |animation.id|, {{ expression }}',
177177
onInput: (String value) => _editLine(index, value),
178178
onFocus: () => _focusedLine = index,
179179
attributes: const <String, String>{
@@ -202,20 +202,18 @@ class _ScoreboardInspectorState extends State<ScoreboardInspector> {
202202
<Widget>[Text('missing $reference')],
203203
),
204204
if (beyondRender)
205-
const dom.span(
206-
classes: 'hui-gloss-chip is-missing',
207-
<Widget>[Text('past line 15 — not rendered')],
208-
),
205+
const dom.span(classes: 'hui-gloss-chip is-missing', <Widget>[
206+
Text('past line 15 — not rendered'),
207+
]),
209208
]),
210209
HuiIconButton(
211210
label: 'Delete line',
212211
icon: ArcaneIcon.trash2(size: IconSize.sm),
213-
onPressed: () => _store.mutateScoreboard(
214-
'delete line',
215-
(GlossScoreboardDoc edited) {
216-
if (index < edited.lines.length) edited.lines.removeAt(index);
217-
},
218-
),
212+
onPressed: () => _store.mutateScoreboard('delete line', (
213+
GlossScoreboardDoc edited,
214+
) {
215+
if (index < edited.lines.length) edited.lines.removeAt(index);
216+
}),
219217
),
220218
],
221219
);
@@ -296,14 +294,13 @@ class _ScoreboardInspectorState extends State<ScoreboardInspector> {
296294
HuiIconButton(
297295
label: 'Remove group',
298296
icon: ArcaneIcon.trash2(size: IconSize.sm),
299-
onPressed: () => _store.mutateScoreboard(
300-
'remove group',
301-
(GlossScoreboardDoc edited) {
302-
if (index < edited.groups.length) {
303-
edited.groups.removeAt(index);
304-
}
305-
},
306-
),
297+
onPressed: () => _store.mutateScoreboard('remove group', (
298+
GlossScoreboardDoc edited,
299+
) {
300+
if (index < edited.groups.length) {
301+
edited.groups.removeAt(index);
302+
}
303+
}),
307304
),
308305
]),
309306
Button(
@@ -322,12 +319,10 @@ class _ScoreboardInspectorState extends State<ScoreboardInspector> {
322319
],
323320
);
324321

325-
void _editLine(int index, String value) => _store.mutateScoreboard(
326-
'edit line',
327-
(GlossScoreboardDoc edited) {
328-
if (index < edited.lines.length) edited.lines[index] = value;
329-
},
330-
);
322+
void _editLine(int index, String value) =>
323+
_store.mutateScoreboard('edit line', (GlossScoreboardDoc edited) {
324+
if (index < edited.lines.length) edited.lines[index] = value;
325+
});
331326

332327
/// Inserts a picked token at the end of the focused field: the title when
333328
/// it was focused last, otherwise the focused (or last) line.

lib/components/motd/motd_view.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class _MotdViewState extends State<MotdView> {
104104
: entry.lines.take(glossMotdMaxLinesPerEntry).toList();
105105
bool animated = false;
106106
for (final String line in lines) {
107-
if (glossLineAnimationRefs(line, animations).isNotEmpty) {
107+
if (renderGlossLine(line, animations: animations).isAnimated) {
108108
animated = true;
109109
break;
110110
}

lib/components/render/icon_renderers.dart

Lines changed: 22 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -459,92 +459,31 @@ class IconRenderers {
459459
if (width < 0.5 || height < 0.5) return;
460460
final double left = brush.sx(rect.left);
461461
final double top = brush.sy(rect.top);
462-
final String key = item.entityKey.contains(':')
463-
? item.entityKey.substring(item.entityKey.indexOf(':') + 1)
464-
: item.entityKey;
465-
int hash = 0;
466-
for (final int unit in key.codeUnits) {
467-
hash = (hash * 31 + unit) & 0x7fffffff;
462+
final String? texture = item.entityTexture;
463+
final web.HTMLImageElement? sprite = texture == null
464+
? null
465+
: assets.image(texture);
466+
if (sprite == null ||
467+
sprite.naturalWidth <= 0 ||
468+
sprite.naturalHeight <= 0) {
469+
_paintItemPlaceholder(item, left, top, width, height);
470+
return;
468471
}
469-
const List<String> bodyColors = <String>[
470-
'#55b7a5',
471-
'#8c7bd8',
472-
'#d29a52',
473-
'#6aa9d8',
474-
'#c56f91',
475-
'#83ad55',
476-
];
477-
final String bodyColor = bodyColors[hash % bodyColors.length];
478-
final double outline = math.max(1, math.min(2, width / 24));
479-
final double headSize = math.min(width * 0.52, height * 0.34);
480-
final double bodyWidth = math.min(width * 0.46, height * 0.3);
481-
final double bodyHeight = math.min(height * 0.38, width * 0.62);
482-
final double centerX = left + width / 2;
483-
final double headLeft = centerX - headSize / 2;
484-
final double headTop = top + height * 0.08;
485-
final double bodyLeft = centerX - bodyWidth / 2;
486-
final double bodyTop = headTop + headSize + math.max(1, height * 0.03);
487-
final double legWidth = math.max(2, bodyWidth * 0.28);
488-
final double legHeight = math.max(2, top + height - bodyTop - bodyHeight);
489-
brush.save();
490-
brush.fill = 'rgba(0, 0, 0, 0.28)';
491-
brush.fillRectPx(left + width * 0.15, top + height - 2, width * 0.7, 3);
492-
brush.fill = bodyColor;
493-
brush.stroke = brush.palette.label;
494-
brush.lineWidth = outline;
495-
brush.fillRectPx(bodyLeft, bodyTop, bodyWidth, bodyHeight);
496-
brush.strokeRectPx(bodyLeft, bodyTop, bodyWidth, bodyHeight);
497-
brush.fillRectPx(
498-
centerX - bodyWidth * 0.42,
499-
bodyTop + bodyHeight,
500-
legWidth,
501-
legHeight,
502-
);
503-
brush.strokeRectPx(
504-
centerX - bodyWidth * 0.42,
505-
bodyTop + bodyHeight,
506-
legWidth,
507-
legHeight,
508-
);
509-
brush.fillRectPx(
510-
centerX + bodyWidth * 0.14,
511-
bodyTop + bodyHeight,
512-
legWidth,
513-
legHeight,
514-
);
515-
brush.strokeRectPx(
516-
centerX + bodyWidth * 0.14,
517-
bodyTop + bodyHeight,
518-
legWidth,
519-
legHeight,
472+
final double scale = math.min(
473+
width / sprite.naturalWidth,
474+
height / sprite.naturalHeight,
520475
);
521-
brush.fillRectPx(headLeft, headTop, headSize, headSize);
522-
brush.strokeRectPx(headLeft, headTop, headSize, headSize);
523-
final double eyeSize = math.max(1.5, headSize * 0.09);
524-
brush.fill = '#101719';
525-
brush.fillRectPx(
526-
headLeft + headSize * 0.22,
527-
headTop + headSize * 0.34,
528-
eyeSize,
529-
eyeSize,
530-
);
531-
brush.fillRectPx(
532-
headLeft + headSize * 0.68,
533-
headTop + headSize * 0.34,
534-
eyeSize,
535-
eyeSize,
476+
final double drawnWidth = sprite.naturalWidth * scale;
477+
final double drawnHeight = sprite.naturalHeight * scale;
478+
brush.save();
479+
brush.smoothing = false;
480+
brush.ctx.drawImage(
481+
sprite,
482+
left + (width - drawnWidth) / 2,
483+
top + height - drawnHeight,
484+
drawnWidth,
485+
drawnHeight,
536486
);
537-
if (width >= 44 && height >= 36) {
538-
brush.setUiFont(math.min(11, math.max(8, width / 8)), bold: true);
539-
brush.textAlign = 'center';
540-
brush.textBaseline = 'top';
541-
brush.fill = brush.palette.label;
542-
brush.fillTextPx(
543-
brush.ellipsize(key.replaceAll('_', ' '), width - 8),
544-
left + width / 2,
545-
top,
546-
);
547-
}
548487
brush.restore();
549488
}
550489

lib/components/scoreboard/scoreboard_view.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,17 @@ class _ScoreboardViewState extends State<ScoreboardView> {
8282
}
8383

8484
bool _isAnimated(GlossScoreboardDoc doc, GlossAnimationResolver animations) {
85-
if (glossLineAnimationRefs(doc.title, animations).isNotEmpty) return true;
85+
if (renderGlossLine(doc.title, animations: animations).isAnimated) {
86+
return true;
87+
}
8688
final int rendered = doc.lines.length > glossBoardMaxLines
8789
? glossBoardMaxLines
8890
: doc.lines.length;
8991
for (int index = 0; index < rendered; index++) {
90-
if (glossLineAnimationRefs(doc.lines[index], animations).isNotEmpty) {
92+
if (renderGlossLine(
93+
doc.lines[index],
94+
animations: animations,
95+
).isAnimated) {
9196
return true;
9297
}
9398
}

lib/components/tablist/tablist_view.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ class _TablistViewState extends State<TablistView> {
113113

114114
bool _isAnimated(GlossTablistDoc doc, GlossAnimationResolver animations) {
115115
if (doc.useHeaderFooter &&
116-
(glossLineAnimationRefs(doc.header, animations).isNotEmpty ||
117-
glossLineAnimationRefs(doc.footer, animations).isNotEmpty)) {
116+
(renderGlossLine(doc.header, animations: animations).isAnimated ||
117+
renderGlossLine(doc.footer, animations: animations).isAnimated)) {
118118
return true;
119119
}
120120
if (doc.groupListNames) {
121121
for (final String format in doc.effectiveNameFormats.values) {
122-
if (glossLineAnimationRefs(format, animations).isNotEmpty) {
122+
if (renderGlossLine(format, animations: animations).isAnimated) {
123123
return true;
124124
}
125125
}

0 commit comments

Comments
 (0)