Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add status logging for (most) loadXML methods #55

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/ui/UIContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,24 @@ class UIContext {

// TODO: Handle unique factories
frame.preLoadXML(node);
frame.loadXML(node);
frame.loadXML(node, status);
frame.postLoadXML(node, status);

return frame;
}

createFontString(node: XMLNode, frame: Frame) {
createFontString(node: XMLNode, frame: Frame, status = new Status()) {
const fontString = new FontString(frame, DrawLayerType.ARTWORK, true);
fontString.preLoadXML(node);
fontString.loadXML(node);
fontString.loadXML(node, status);
fontString.postLoadXML(node);
return fontString;
}

createTexture(node: XMLNode, frame: Frame) {
createTexture(node: XMLNode, frame: Frame, status = new Status()) {
const texture = new Texture(frame, DrawLayerType.ARTWORK, true);
texture.preLoadXML(node);
texture.loadXML(node);
texture.loadXML(node, status);
texture.postLoadXML(node);
return texture;
}
Expand Down
14 changes: 7 additions & 7 deletions src/ui/components/abstract/LayoutFrame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
LinkedListNode,
NDCtoDDCHeight,
NDCtoDDCWidth,
Status,
extractDimensionsFrom,
stringToBoolean,
} from '../../../utils';
Expand Down Expand Up @@ -366,7 +367,7 @@ class LayoutFrame {
return rect;
}

loadXML(node: XMLNode) {
loadXML(node: XMLNode, status: Status) {
const size = node.getChildByName('Size');
if (size) {
const { x, y } = extractDimensionsFrom(size);
Expand All @@ -387,7 +388,7 @@ class LayoutFrame {
const anchors = node.getChildByName('Anchors');
if (anchors) {
if (setAllPoints) {
// TODO: Error handling
status.warning('setAllPoints set to true in frame with anchors (ignored)');
}

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

if (relativePointValue) {
relativePointType = stringToFramePointType(relativePointValue);
if (relativePointType === undefined) {
// TODO: Error handling
status.warning(`invalid relative anchor point in frame: ${relativePointValue}`);
continue;
}
}
Expand All @@ -415,13 +416,12 @@ class LayoutFrame {
const fqname = this.fullyQualifyName(relativeValue)!;
relative = ScriptRegion.getObjectByName(fqname);
if (!relative) {
// TODO: Error handling
console.warn(`could not find relative frame: ${fqname}`);
status.warning(`could not find relative frame: ${relativeValue}`);
continue;
}

if (relative === this) {
// TODO: Error handling
status.warning(`frame anchored to itself: ${relativeValue}`);
continue;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/ui/components/abstract/ScriptRegion.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Frame from '../simple/Frame';
import UIRoot from '../UIRoot';
import XMLNode from '../../XMLNode';
import { multipleClasses } from '../../../utils';
import { Status, multipleClasses } from '../../../utils';

import LayoutFrame from './LayoutFrame';
import ScriptObject from './ScriptObject';
Expand Down Expand Up @@ -40,8 +40,8 @@ class ScriptRegion extends multipleClasses(ScriptObject, LayoutFrame) {
return this.parent;
}

loadXML(node: XMLNode) {
LayoutFrame.prototype.loadXML.call(this, node);
loadXML(node: XMLNode, status: Status) {
super.loadXML(node, status);

const parentKey = node.attributes.get('parentKey');
if (parentKey) {
Expand Down
13 changes: 7 additions & 6 deletions src/ui/components/simple/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Script from '../../scripting/Script';
import UIContext from '../../UIContext';
import XMLNode from '../../XMLNode';
import { BlendMode } from '../../../gfx/types';
import { Status } from '../../../utils';

import ButtonState from './ButtonState';
import FontString from './FontString';
Expand Down Expand Up @@ -52,31 +53,31 @@ class Button extends Frame {
this.state = ButtonState.DISABLED;
}

loadXML(node: XMLNode) {
super.loadXML(node);
loadXML(node: XMLNode, status: Status) {
super.loadXML(node, status);

const ui = UIContext.instance;

for (const child of node.children) {
const iname = child.name.toLowerCase();
switch (iname) {
case 'normaltexture': {
const texture = ui.createTexture(child, this);
const texture = ui.createTexture(child, this, status);
this.setStateTexture(ButtonState.NORMAL, texture);
break;
}
case 'pushedtexture': {
const texture = ui.createTexture(child, this);
const texture = ui.createTexture(child, this, status);
this.setStateTexture(ButtonState.PUSHED, texture);
break;
}
case 'disabledtexture': {
const texture = ui.createTexture(child, this);
const texture = ui.createTexture(child, this, status);
this.setStateTexture(ButtonState.DISABLED, texture);
break;
}
case 'highlighttexture': {
const texture = ui.createTexture(child, this);
const texture = ui.createTexture(child, this, status);
// TODO: Blend mode
this.setHighlight(texture, null);
break;
Expand Down
19 changes: 10 additions & 9 deletions src/ui/components/simple/Frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ class Frame extends ScriptRegion {
}
}

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

if (inherits) {
const templates = UIContext.instance.templates.filterByList(inherits);
for (const { template } of templates) {
for (const { name, template } of templates) {
if (template) {
if (template.locked) {
// TODO: Error handling
status.warning(`recursively inherited node: ${name}`);
} else {
template.lock();
this.loadXML(template.node);
this.loadXML(template.node, status);
template.release();
}
} else {
// TODO: Error handling
status.warning(`could not find inherited node: ${name}`);
}
}
}

super.loadXML(node);
super.loadXML(node, status);

if (hidden) {
if (stringToBoolean(hidden)) {
Expand Down Expand Up @@ -348,7 +349,7 @@ class Frame extends ScriptRegion {
this.setBackdrop(backdrop);
} break;
case 'layers':
this.loadXMLLayers(child);
this.loadXMLLayers(child, status);
break;
case 'attributes':
// TODO: Load attributes
Expand All @@ -360,7 +361,7 @@ class Frame extends ScriptRegion {
}
}

loadXMLLayers(node: XMLNode) {
loadXMLLayers(node: XMLNode, status: Status) {
const ui = UIContext.instance;

for (const layer of node.children) {
Expand All @@ -377,7 +378,7 @@ class Frame extends ScriptRegion {
const iname = layerChild.name.toLowerCase();
switch (iname) {
case 'texture': {
const texture = ui.createTexture(layerChild, this);
const texture = ui.createTexture(layerChild, this, status);
texture.setFrame(this, drawLayerType, texture.shown);
} break;
case 'fontstring': {
Expand Down
11 changes: 6 additions & 5 deletions src/ui/components/simple/ScrollFrame.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Script from '../../scripting/Script';
import UIContext from '../../UIContext';
import XMLNode from '../../XMLNode';
import { Status } from '../../../utils';

import Frame from './Frame';

Expand Down Expand Up @@ -28,20 +29,20 @@ class ScrollFrame extends Frame {
);
}

loadXML(node: XMLNode) {
super.loadXML(node);
loadXML(node: XMLNode, status: Status) {
super.loadXML(node, status);

const scrollChild = node.getChildByName('ScrollChild');
if (scrollChild) {
const child = scrollChild.firstChild;
if (child) {
const frame = UIContext.instance.createFrame(child, this);
const frame = UIContext.instance.createFrame(child, this, status);
if (frame) {
this.scrollChild = frame;
}
} else {
// TODO: Error handling
console.warn('scroll frame created without child');
const name = this.name || '<unnamed>';
status.warning(`frame ${name}: scroll frame created without scroll child`);
}
}
}
Expand Down
60 changes: 32 additions & 28 deletions src/ui/components/simple/Texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { stringToBlendMode } from '../../utils';
import {
NDCtoDDCHeight,
NDCtoDDCWidth,
Status,
maxAspectCompensation,
stringToBoolean,
stringToFloat,
Expand Down Expand Up @@ -111,7 +112,8 @@ class Texture extends Region {
super.height = height;
}

loadXML(node: XMLNode) {
loadXML(node: XMLNode, status: Status) {
// TODO: Group attribute extraction together with usage
const alphaMode = node.attributes.get('alphaMode');
const file = node.attributes.get('file');
const hidden = node.attributes.get('hidden');
Expand All @@ -123,18 +125,18 @@ class Texture extends Region {
const template = UIContext.instance.templates.get(inherits);
if (template) {
if (template.locked) {
// TODO: Error handling
status.warning(`recursively inherited node: ${inherits}`);
} else {
template.lock();
this.loadXML(template.node);
this.loadXML(template.node, status);
template.release();
}
} else {
// TODO: Error handling
status.warning(`could not find inherited node: ${inherits}`);
}
}

super.loadXML(node);
super.loadXML(node, status);

if (hidden) {
if (stringToBoolean(hidden)) {
Expand Down Expand Up @@ -170,31 +172,31 @@ class Texture extends Region {
bottom: 1.0,
};

// TODO: Handle name in error handling
// const name = this.name || '<unnamed>';
const name = this.name || '<unnamed>';

// TODO: Handle rectangle
if (child.getChildByName('Rect')) {
continue;
}

for (const side of Object.keys(rect) as (keyof typeof rect)[]) {
const attr = child.attributes.get(side);
if (attr) {
if (
((side === 'left' || side === 'right') && this.tileHorizontally)
|| ((side === 'top' || side === 'bottom') && this.tileVertically)
) {
// TODO: error handling
valid = false;
}

const value = stringToFloat(attr);
if (value < -10000 || value > 10000) {
// TODO: Error handling
valid = false;
// TODO: Handle rectangle
} else {
for (const side of Object.keys(rect) as (keyof typeof rect)[]) {
const attr = child.attributes.get(side);
if (attr) {
if (
((side === 'left' || side === 'right') && this.tileHorizontally)
|| ((side === 'top' || side === 'bottom') && this.tileVertically)
) {
status.error(
`texture ${name}: invalid TexCoords value (horizTile: ${this.tileHorizontally}; vertTile: ${this.tileVertically}`
);
valid = false;
}

const value = stringToFloat(attr);
if (value < -10000 || value > 10000) {
status.error(`texture ${name}: invalid TexCoords value (out of range)`);
valid = false;
}
rect[side] = value;
}
rect[side] = value;
}
}

Expand Down Expand Up @@ -234,7 +236,8 @@ class Texture extends Region {
if (success) {
// TODO: Set colors
} else {
// TODO: Error handling
const name = this.name || '<unnamed>';
status.warning(`texture ${name}: unable to load texture file ${file}`);
}
}

Expand All @@ -245,6 +248,7 @@ class Texture extends Region {
}
}

// TODO: Alpha
// TODO: Non-blocking
}

Expand Down
Loading