Skip to content

Commit

Permalink
⚡ styleUtils to TypeScript and new IStyle interface (#440 @markmehere
Browse files Browse the repository at this point in the history
  • Loading branch information
markmehere authored Sep 25, 2023
1 parent 19b6356 commit 318afe6
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 44 deletions.
28 changes: 27 additions & 1 deletion src/node_requires/resources/styles/IStyle.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
declare interface IStyle extends IAsset {
name: string;
// TODO:
font: {
family: string;
size: number;
italic?: boolean;
weight: string;
halign: string;
lineHeight?: number;
wrap?: boolean;
wrapPosition?: number;
};
fill?: {
type: string;
color?: string;
color1?: string;
color2?: string;
gradtype?: string;
};
stroke?: {
weight: number;
color: string;
};
shadow?: {
x: number;
y: number;
blur: number;
color: string | number;
}
}
43 changes: 0 additions & 43 deletions src/node_requires/styleUtils.js

This file was deleted.

39 changes: 39 additions & 0 deletions src/node_requires/styleUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export const styleToTextStyle = (s: IStyle) => {
const o: Omit<Partial<PIXI.TextStyle>, 'whiteSpace'> = {
fontFamily: s.font.family,
fontSize: s.font.size,
fontStyle: s.font.italic ? 'italic' : 'normal',
fontWeight: s.font.weight,
align: s.font.halign,
lineJoin: 'round',
lineHeight: s.font.lineHeight || s.font.size * 1.35
};
if (s.font.wrap) {
o.wordWrap = true;
o.wordWrapWidth = s.font.wrapPosition || 100;
}
if (s.fill) {
if (Number(s.fill.type) === 0) {
o.fill = s.fill.color || '#FFFFFF';
} else if (Number(s.fill.type) === 1) {
o.fill = [s.fill.color1 || '#FFFFFF', s.fill.color2 || '#FFFFFF'];
if (Number(s.fill.gradtype) === 1) {
o.fillGradientType = 0;
} else if (Number(s.fill.gradtype) === 2) {
o.fillGradientType = 1;
}
}
}
if (s.stroke) {
o.strokeThickness = s.stroke.weight;
o.stroke = s.stroke.color;
}
if (s.shadow) {
o.dropShadow = true;
o.dropShadowBlur = s.shadow.blur;
o.dropShadowColor = s.shadow.color;
o.dropShadowAngle = Math.atan2(s.shadow.y, s.shadow.x);
o.dropShadowDistance = Math.hypot(s.shadow.x, s.shadow.y);
}
return o;
};

0 comments on commit 318afe6

Please sign in to comment.