Skip to content

Commit 0c2b0d5

Browse files
authored
feat: add status logging for (most) loadXML methods (#55)
1 parent 3ffcfdc commit 0c2b0d5

File tree

7 files changed

+70
-63
lines changed

7 files changed

+70
-63
lines changed

src/ui/UIContext.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,24 @@ class UIContext {
8282

8383
// TODO: Handle unique factories
8484
frame.preLoadXML(node);
85-
frame.loadXML(node);
85+
frame.loadXML(node, status);
8686
frame.postLoadXML(node, status);
8787

8888
return frame;
8989
}
9090

91-
createFontString(node: XMLNode, frame: Frame) {
91+
createFontString(node: XMLNode, frame: Frame, status = new Status()) {
9292
const fontString = new FontString(frame, DrawLayerType.ARTWORK, true);
9393
fontString.preLoadXML(node);
94-
fontString.loadXML(node);
94+
fontString.loadXML(node, status);
9595
fontString.postLoadXML(node);
9696
return fontString;
9797
}
9898

99-
createTexture(node: XMLNode, frame: Frame) {
99+
createTexture(node: XMLNode, frame: Frame, status = new Status()) {
100100
const texture = new Texture(frame, DrawLayerType.ARTWORK, true);
101101
texture.preLoadXML(node);
102-
texture.loadXML(node);
102+
texture.loadXML(node, status);
103103
texture.postLoadXML(node);
104104
return texture;
105105
}

src/ui/components/abstract/LayoutFrame.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
LinkedListNode,
1515
NDCtoDDCHeight,
1616
NDCtoDDCWidth,
17+
Status,
1718
extractDimensionsFrom,
1819
stringToBoolean,
1920
} from '../../../utils';
@@ -366,7 +367,7 @@ class LayoutFrame {
366367
return rect;
367368
}
368369

369-
loadXML(node: XMLNode) {
370+
loadXML(node: XMLNode, status: Status) {
370371
const size = node.getChildByName('Size');
371372
if (size) {
372373
const { x, y } = extractDimensionsFrom(size);
@@ -387,7 +388,7 @@ class LayoutFrame {
387388
const anchors = node.getChildByName('Anchors');
388389
if (anchors) {
389390
if (setAllPoints) {
390-
// TODO: Error handling
391+
status.warning('setAllPoints set to true in frame with anchors (ignored)');
391392
}
392393

393394
for (const child of anchors.children) {
@@ -398,14 +399,14 @@ class LayoutFrame {
398399
const pointType = stringToFramePointType(pointValue);
399400
let relativePointType = pointType;
400401
if (pointType === undefined) {
401-
// TODO: Error handling
402+
status.warning(`invalid anchor point in frame: ${pointValue}`);
402403
continue;
403404
}
404405

405406
if (relativePointValue) {
406407
relativePointType = stringToFramePointType(relativePointValue);
407408
if (relativePointType === undefined) {
408-
// TODO: Error handling
409+
status.warning(`invalid relative anchor point in frame: ${relativePointValue}`);
409410
continue;
410411
}
411412
}
@@ -415,13 +416,12 @@ class LayoutFrame {
415416
const fqname = this.fullyQualifyName(relativeValue)!;
416417
relative = ScriptRegion.getObjectByName(fqname);
417418
if (!relative) {
418-
// TODO: Error handling
419-
console.warn(`could not find relative frame: ${fqname}`);
419+
status.warning(`could not find relative frame: ${relativeValue}`);
420420
continue;
421421
}
422422

423423
if (relative === this) {
424-
// TODO: Error handling
424+
status.warning(`frame anchored to itself: ${relativeValue}`);
425425
continue;
426426
}
427427
}

src/ui/components/abstract/ScriptRegion.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Frame from '../simple/Frame';
22
import UIRoot from '../UIRoot';
33
import XMLNode from '../../XMLNode';
4-
import { multipleClasses } from '../../../utils';
4+
import { Status, multipleClasses } from '../../../utils';
55

66
import LayoutFrame from './LayoutFrame';
77
import ScriptObject from './ScriptObject';
@@ -40,8 +40,8 @@ class ScriptRegion extends multipleClasses(ScriptObject, LayoutFrame) {
4040
return this.parent;
4141
}
4242

43-
loadXML(node: XMLNode) {
44-
LayoutFrame.prototype.loadXML.call(this, node);
43+
loadXML(node: XMLNode, status: Status) {
44+
super.loadXML(node, status);
4545

4646
const parentKey = node.attributes.get('parentKey');
4747
if (parentKey) {

src/ui/components/simple/Button.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Script from '../../scripting/Script';
33
import UIContext from '../../UIContext';
44
import XMLNode from '../../XMLNode';
55
import { BlendMode } from '../../../gfx/types';
6+
import { Status } from '../../../utils';
67

78
import ButtonState from './ButtonState';
89
import FontString from './FontString';
@@ -52,31 +53,31 @@ class Button extends Frame {
5253
this.state = ButtonState.DISABLED;
5354
}
5455

55-
loadXML(node: XMLNode) {
56-
super.loadXML(node);
56+
loadXML(node: XMLNode, status: Status) {
57+
super.loadXML(node, status);
5758

5859
const ui = UIContext.instance;
5960

6061
for (const child of node.children) {
6162
const iname = child.name.toLowerCase();
6263
switch (iname) {
6364
case 'normaltexture': {
64-
const texture = ui.createTexture(child, this);
65+
const texture = ui.createTexture(child, this, status);
6566
this.setStateTexture(ButtonState.NORMAL, texture);
6667
break;
6768
}
6869
case 'pushedtexture': {
69-
const texture = ui.createTexture(child, this);
70+
const texture = ui.createTexture(child, this, status);
7071
this.setStateTexture(ButtonState.PUSHED, texture);
7172
break;
7273
}
7374
case 'disabledtexture': {
74-
const texture = ui.createTexture(child, this);
75+
const texture = ui.createTexture(child, this, status);
7576
this.setStateTexture(ButtonState.DISABLED, texture);
7677
break;
7778
}
7879
case 'highlighttexture': {
79-
const texture = ui.createTexture(child, this);
80+
const texture = ui.createTexture(child, this, status);
8081
// TODO: Blend mode
8182
this.setHighlight(texture, null);
8283
break;

src/ui/components/simple/Frame.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ class Frame extends ScriptRegion {
254254
}
255255
}
256256

257-
loadXML(node: XMLNode) {
257+
loadXML(node: XMLNode, status: Status) {
258+
// TODO: Group attribute extraction together with usage
258259
const dontSavePosition = node.attributes.get('dontSavePosition');
259260
const frameLevel = node.attributes.get('frameLevel');
260261
const frameStrata = node.attributes.get('frameStrata');
@@ -266,22 +267,22 @@ class Frame extends ScriptRegion {
266267

267268
if (inherits) {
268269
const templates = UIContext.instance.templates.filterByList(inherits);
269-
for (const { template } of templates) {
270+
for (const { name, template } of templates) {
270271
if (template) {
271272
if (template.locked) {
272-
// TODO: Error handling
273+
status.warning(`recursively inherited node: ${name}`);
273274
} else {
274275
template.lock();
275-
this.loadXML(template.node);
276+
this.loadXML(template.node, status);
276277
template.release();
277278
}
278279
} else {
279-
// TODO: Error handling
280+
status.warning(`could not find inherited node: ${name}`);
280281
}
281282
}
282283
}
283284

284-
super.loadXML(node);
285+
super.loadXML(node, status);
285286

286287
if (hidden) {
287288
if (stringToBoolean(hidden)) {
@@ -348,7 +349,7 @@ class Frame extends ScriptRegion {
348349
this.setBackdrop(backdrop);
349350
} break;
350351
case 'layers':
351-
this.loadXMLLayers(child);
352+
this.loadXMLLayers(child, status);
352353
break;
353354
case 'attributes':
354355
// TODO: Load attributes
@@ -360,7 +361,7 @@ class Frame extends ScriptRegion {
360361
}
361362
}
362363

363-
loadXMLLayers(node: XMLNode) {
364+
loadXMLLayers(node: XMLNode, status: Status) {
364365
const ui = UIContext.instance;
365366

366367
for (const layer of node.children) {
@@ -377,7 +378,7 @@ class Frame extends ScriptRegion {
377378
const iname = layerChild.name.toLowerCase();
378379
switch (iname) {
379380
case 'texture': {
380-
const texture = ui.createTexture(layerChild, this);
381+
const texture = ui.createTexture(layerChild, this, status);
381382
texture.setFrame(this, drawLayerType, texture.shown);
382383
} break;
383384
case 'fontstring': {

src/ui/components/simple/ScrollFrame.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Script from '../../scripting/Script';
22
import UIContext from '../../UIContext';
33
import XMLNode from '../../XMLNode';
4+
import { Status } from '../../../utils';
45

56
import Frame from './Frame';
67

@@ -28,20 +29,20 @@ class ScrollFrame extends Frame {
2829
);
2930
}
3031

31-
loadXML(node: XMLNode) {
32-
super.loadXML(node);
32+
loadXML(node: XMLNode, status: Status) {
33+
super.loadXML(node, status);
3334

3435
const scrollChild = node.getChildByName('ScrollChild');
3536
if (scrollChild) {
3637
const child = scrollChild.firstChild;
3738
if (child) {
38-
const frame = UIContext.instance.createFrame(child, this);
39+
const frame = UIContext.instance.createFrame(child, this, status);
3940
if (frame) {
4041
this.scrollChild = frame;
4142
}
4243
} else {
43-
// TODO: Error handling
44-
console.warn('scroll frame created without child');
44+
const name = this.name || '<unnamed>';
45+
status.warning(`frame ${name}: scroll frame created without scroll child`);
4546
}
4647
}
4748
}

src/ui/components/simple/Texture.ts

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { stringToBlendMode } from '../../utils';
1414
import {
1515
NDCtoDDCHeight,
1616
NDCtoDDCWidth,
17+
Status,
1718
maxAspectCompensation,
1819
stringToBoolean,
1920
stringToFloat,
@@ -111,7 +112,8 @@ class Texture extends Region {
111112
super.height = height;
112113
}
113114

114-
loadXML(node: XMLNode) {
115+
loadXML(node: XMLNode, status: Status) {
116+
// TODO: Group attribute extraction together with usage
115117
const alphaMode = node.attributes.get('alphaMode');
116118
const file = node.attributes.get('file');
117119
const hidden = node.attributes.get('hidden');
@@ -123,18 +125,18 @@ class Texture extends Region {
123125
const template = UIContext.instance.templates.get(inherits);
124126
if (template) {
125127
if (template.locked) {
126-
// TODO: Error handling
128+
status.warning(`recursively inherited node: ${inherits}`);
127129
} else {
128130
template.lock();
129-
this.loadXML(template.node);
131+
this.loadXML(template.node, status);
130132
template.release();
131133
}
132134
} else {
133-
// TODO: Error handling
135+
status.warning(`could not find inherited node: ${inherits}`);
134136
}
135137
}
136138

137-
super.loadXML(node);
139+
super.loadXML(node, status);
138140

139141
if (hidden) {
140142
if (stringToBoolean(hidden)) {
@@ -170,31 +172,31 @@ class Texture extends Region {
170172
bottom: 1.0,
171173
};
172174

173-
// TODO: Handle name in error handling
174-
// const name = this.name || '<unnamed>';
175+
const name = this.name || '<unnamed>';
175176

176-
// TODO: Handle rectangle
177177
if (child.getChildByName('Rect')) {
178-
continue;
179-
}
180-
181-
for (const side of Object.keys(rect) as (keyof typeof rect)[]) {
182-
const attr = child.attributes.get(side);
183-
if (attr) {
184-
if (
185-
((side === 'left' || side === 'right') && this.tileHorizontally)
186-
|| ((side === 'top' || side === 'bottom') && this.tileVertically)
187-
) {
188-
// TODO: error handling
189-
valid = false;
190-
}
191-
192-
const value = stringToFloat(attr);
193-
if (value < -10000 || value > 10000) {
194-
// TODO: Error handling
195-
valid = false;
178+
// TODO: Handle rectangle
179+
} else {
180+
for (const side of Object.keys(rect) as (keyof typeof rect)[]) {
181+
const attr = child.attributes.get(side);
182+
if (attr) {
183+
if (
184+
((side === 'left' || side === 'right') && this.tileHorizontally)
185+
|| ((side === 'top' || side === 'bottom') && this.tileVertically)
186+
) {
187+
status.error(
188+
`texture ${name}: invalid TexCoords value (horizTile: ${this.tileHorizontally}; vertTile: ${this.tileVertically}`
189+
);
190+
valid = false;
191+
}
192+
193+
const value = stringToFloat(attr);
194+
if (value < -10000 || value > 10000) {
195+
status.error(`texture ${name}: invalid TexCoords value (out of range)`);
196+
valid = false;
197+
}
198+
rect[side] = value;
196199
}
197-
rect[side] = value;
198200
}
199201
}
200202

@@ -234,7 +236,8 @@ class Texture extends Region {
234236
if (success) {
235237
// TODO: Set colors
236238
} else {
237-
// TODO: Error handling
239+
const name = this.name || '<unnamed>';
240+
status.warning(`texture ${name}: unable to load texture file ${file}`);
238241
}
239242
}
240243

@@ -245,6 +248,7 @@ class Texture extends Region {
245248
}
246249
}
247250

251+
// TODO: Alpha
248252
// TODO: Non-blocking
249253
}
250254

0 commit comments

Comments
 (0)