This repository has been archived by the owner on Apr 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
143 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { parseDeg } from "./parseDeg" | ||
|
||
export const attributeValueToArray = (value: string) => | ||
value | ||
.split(/[, ]+/) | ||
.map((s) => s.trim()) | ||
.map((s) => parseDeg(s) ?? floatOrNot(s)) | ||
|
||
const floatOrNot = (s: string) => { | ||
const f = parseFloat(s) | ||
return f || f === 0 ? f : s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { MathUtils } from "three" | ||
|
||
export const parseDeg = (value: string) => { | ||
const r = value.trim().match(/^([0-9\.\- ]+)deg$/) | ||
if (r) return MathUtils.degToRad(parseFloat(r[1])) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { expect, fixture, html, nextFrame } from "@open-wc/testing" | ||
import "../src" | ||
import { ThreeElement } from "../src/ThreeElement" | ||
|
||
describe("the args attribute", () => { | ||
const render = () => | ||
fixture(html` | ||
<three-game> | ||
<three-scene> | ||
<three-mesh> | ||
<three-fog args="#333333, 1, 1000"></three-fog> | ||
</three-mesh> | ||
</three-scene> | ||
</three-game> | ||
`) | ||
|
||
it("provides the arguments for the Three.js constructor", async () => { | ||
const game = await render() | ||
const fog = game.querySelector("three-fog") as ThreeElement | ||
|
||
await nextFrame() | ||
|
||
expect(fog.object.color.getHexString()).to.equal("333333") | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { expect } from "@open-wc/testing" | ||
import { attributeValueToArray } from "../../src/util/attributeValueToArray" | ||
|
||
describe("attributeValueToArray", () => { | ||
it("parses a singular string value to an array containing the string", () => { | ||
expect(attributeValueToArray("foo")).to.eql(["foo"]) | ||
}) | ||
|
||
it("parses a singular numerical value to an array containing the number", () => { | ||
expect(attributeValueToArray("123")).to.eql([123]) | ||
}) | ||
|
||
it("parses a '0' to the number 0", () => { | ||
expect(attributeValueToArray("0")).to.eql([0]) | ||
}) | ||
|
||
it("parses a list of numerical values to an array containing those numbers", () => { | ||
expect(attributeValueToArray("123, 0, -123")).to.eql([123, 0, -123]) | ||
}) | ||
|
||
it("parses a list of strings to an array containing those strings", () => { | ||
expect(attributeValueToArray("foo, bar")).to.eql(["foo", "bar"]) | ||
}) | ||
|
||
it("parses a list of mixed value types to an array containing the correct values", () => { | ||
expect(attributeValueToArray("foo, 0, 1, bar")).to.eql(["foo", 0, 1, "bar"]) | ||
}) | ||
|
||
it("also works without a comma", () => { | ||
expect(attributeValueToArray("foo 0 1 bar")).to.eql(["foo", 0, 1, "bar"]) | ||
}) | ||
|
||
it("also works with floating point values", () => { | ||
expect(attributeValueToArray("-0.5 +0.5")).to.eql([-0.5, 0.5]) | ||
}) | ||
}) |