Skip to content

Commit

Permalink
feat: prettify number output
Browse files Browse the repository at this point in the history
  • Loading branch information
lopi-py committed Dec 18, 2023
1 parent 696dc2b commit 086d217
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/roblox.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { fixed } from "./util";

export type Value = boolean | number | string | Color3 | Enum | Font | UDim | UDim2 | Vector2;

export interface Properties {
Expand Down Expand Up @@ -32,9 +34,9 @@ export class UDim2 {
x: UDim
y: UDim

constructor(x: number, y: number) {
this.x = new UDim(x, 0)
this.y = new UDim(y, 0)
constructor(xScale: number, xOffset: number, yScale: number, yOffset: number) {
this.x = new UDim(fixed(xScale), xOffset)
this.y = new UDim(fixed(yScale), yOffset)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/seralizers/luau.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class LuauSerializer extends Serializer {
}

serUDim2(value: UDim2): string {
return `UDim2.fromScale(${value.x.scale}, ${value.y.scale})`
return `UDim2.new(${value.x.scale}, ${value.x.offset}, ${value.y.scale}, ${value.y.offset})`
}

serVector2(value: Vector2): string {
Expand Down
6 changes: 5 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { Color3 } from "./roblox";

export function fixed(value: number): number {
return Math.round((value + Number.EPSILON) * 1e5) / 1e5
}

export function getLength(obj: object): number {
return Object.keys(obj).length;
}
Expand Down Expand Up @@ -47,7 +51,7 @@ export function getTransparency(node: GeometryMixin): number | undefined {
if (!fill || !fill.opacity)
return

return (1 - fill.opacity)
return fixed(1 - fill.opacity)
}

export function getFont(node: TextNode): [string, string, string] {
Expand Down

0 comments on commit 086d217

Please sign in to comment.