Skip to content

Commit 9537ecf

Browse files
committed
fix: handling of enums of value 0
1 parent fd7b1ac commit 9537ecf

File tree

5 files changed

+20
-21
lines changed

5 files changed

+20
-21
lines changed

src/ui/components/abstract/FramePointType.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ enum FramePointType {
1010
BOTTOMRIGHT = 8,
1111
}
1212

13-
export const stringToPointType = (string?: string) => {
14-
if (!string) return undefined;
15-
return FramePointType[string.toUpperCase() as keyof typeof FramePointType];
16-
};
17-
18-
export const FramePointTypeSide = {
13+
const FramePointTypeSide = {
1914
CENTERX: [
2015
FramePointType.TOP,
2116
FramePointType.CENTER,
@@ -49,3 +44,4 @@ export const FramePointTypeSide = {
4944
};
5045

5146
export default FramePointType;
47+
export { FramePointTypeSide };

src/ui/components/abstract/LayoutFrame.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import ScriptRegion from './ScriptRegion';
22
import XMLNode from '../../XMLNode';
3+
import { stringToFramePointType } from '../../utils';
34
import {
45
EPSILON1,
56
EPSILON2,
@@ -18,10 +19,7 @@ import {
1819
} from '../../../utils';
1920

2021
import FramePoint from './FramePoint';
21-
import FramePointType, {
22-
FramePointTypeSide,
23-
stringToPointType,
24-
} from './FramePointType';
22+
import FramePointType, { FramePointTypeSide } from './FramePointType';
2523

2624
class FrameNode extends LinkedListNode {
2725
frame: LayoutFrame;
@@ -397,16 +395,16 @@ class LayoutFrame {
397395
const relativePointValue = child.attributes.get('relativePoint');
398396
const relativeValue = child.attributes.get('relativeTo');
399397

400-
const pointType = stringToPointType(pointValue);
398+
const pointType = stringToFramePointType(pointValue);
401399
let relativePointType = pointType;
402-
if (!pointType) {
400+
if (pointType === undefined) {
403401
// TODO: Error handling
404402
continue;
405403
}
406404

407405
if (relativePointValue) {
408-
relativePointType = stringToPointType(relativePointValue);
409-
if (!relativePointType) {
406+
relativePointType = stringToFramePointType(relativePointValue);
407+
if (relativePointType === undefined) {
410408
// TODO: Error handling
411409
continue;
412410
}

src/ui/components/simple/Frame.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
import { Rect } from '../../../math';
2020
import {
2121
stringToDrawLayerType,
22-
stringToStrataType,
22+
stringToFrameStrataType,
2323
} from '../../utils';
2424

2525
import FrameFlag from './FrameFlag';
@@ -308,8 +308,8 @@ class Frame extends ScriptRegion {
308308
}
309309

310310
if (frameStrata) {
311-
const strataType = stringToStrataType(frameStrata);
312-
if (strataType) {
311+
const strataType = stringToFrameStrataType(frameStrata);
312+
if (strataType !== undefined) {
313313
this.setFrameStrataType(strataType);
314314
} else {
315315
// TODO: Error handling
@@ -371,8 +371,7 @@ class Frame extends ScriptRegion {
371371

372372
const level = layer.attributes.get('level');
373373

374-
// TODO: Case sensitivity
375-
const drawLayerType = stringToDrawLayerType(level) || DrawLayerType.ARTWORK;
374+
const drawLayerType = stringToDrawLayerType(level) ?? DrawLayerType.ARTWORK;
376375

377376
for (const layerChild of layer.children) {
378377
const iname = layerChild.name.toLowerCase();

src/ui/components/simple/Texture.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class Texture extends Region {
240240

241241
if (alphaMode) {
242242
const blendMode = stringToBlendMode(alphaMode);
243-
if (blendMode) {
243+
if (blendMode !== undefined) {
244244
this.setBlendMode(blendMode);
245245
}
246246
}

src/ui/utils.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BlendMode } from '../gfx/types';
22

33
import DrawLayerType from './DrawLayerType';
4+
import FramePointType from './components/abstract/FramePointType';
45
import FrameStrataType from './components/abstract/FrameStrataType';
56

67
export const stringToBlendMode = (string?: string) => {
@@ -13,7 +14,12 @@ export const stringToDrawLayerType = (string?: string) => {
1314
return DrawLayerType[string?.toUpperCase() as keyof typeof DrawLayerType];
1415
};
1516

16-
export const stringToStrataType = (string?: string) => {
17+
export const stringToFramePointType = (string?: string) => {
18+
if (!string) return undefined;
19+
return FramePointType[string.toUpperCase() as keyof typeof FramePointType];
20+
};
21+
22+
export const stringToFrameStrataType = (string?: string) => {
1723
if (!string) return undefined;
1824
return FrameStrataType[string?.toUpperCase() as keyof typeof FrameStrataType];
1925
};

0 commit comments

Comments
 (0)