Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
release: v2.0.0-beta.6
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepbox8646 committed Aug 10, 2024
1 parent c964cae commit 3a6e91d
Show file tree
Hide file tree
Showing 18 changed files with 412 additions and 321 deletions.
15 changes: 12 additions & 3 deletions examples/scene1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import * as nc from 'newcar'
await useFont('./default.ttf')

export default importScene(

`{
"root": {
"type": "Circle",
"arguments": [150],
"options": {
"style": {
"border": true,
"fill": false
"fill": false,
"borderColor": [144, 144, 144, 1]
},
"x": 800,
"y": 450
Expand All @@ -39,4 +40,12 @@ export default importScene(
`,
nc as any,
nc as any,
)
)
//
// export default createScene(
// new Circle(100, {
// style: {
// color: Color.rgba(144, 144, 144, 1)
// }
// })
// )
2 changes: 1 addition & 1 deletion mods/mod-geometry/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@newcar/mod-geometry",
"version": "2.0.0-beta.5",
"version": "2.0.0-beta.6",
"description": "",
"author": "BugDuck Team",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion mods/mod-layout/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@newcar/mod-layout",
"version": "2.0.0-beta.5",
"version": "2.0.0-beta.6",
"description": "",
"author": "BugDuck Team",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion mods/mod-markdown/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@newcar/mod-markdown",
"version": "2.0.0-beta.5",
"version": "2.0.0-beta.6",
"description": "",
"author": "BugDuck Team",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion mods/mod-math/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@newcar/mod-math",
"type": "module",
"version": "2.0.0-beta.5",
"version": "2.0.0-beta.6",
"description": "",
"author": "BugDuck Team",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion mods/mod-skottie/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@newcar/mod-skottie",
"type": "module",
"version": "2.0.0-beta.5",
"version": "2.0.0-beta.6",
"description": "",
"author": "BugDuck Team",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/basic/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@newcar/basic",
"version": "2.0.0-beta.5",
"version": "2.0.0-beta.6",
"description": "The basic objects, animations and interpolators of newcar.",
"author": "BugDuck Team",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@newcar/core",
"type": "module",
"version": "2.0.0-beta.5",
"version": "2.0.0-beta.6",
"description": "The core of newcar.",
"author": "BugDuck Team",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/json/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@newcar/json",
"type": "module",
"version": "2.0.0-beta.5",
"version": "2.0.0-beta.6",
"description": "The core of newcar.",
"author": "BugDuck Team",
"license": "Apache-2.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/json/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
"to": true,
"elapsed": {
"type": "number"
},
"arguments": {
"type": "array"
}
}
}
Expand Down
68 changes: 66 additions & 2 deletions packages/json/src/import-widget.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,70 @@
import type { Widget } from '@newcar/core'
import type { Widget, WidgetOptions } from '@newcar/core'
import { Color, Shader, isString } from '@newcar/utils'
import type { WidgetFormat } from './format'
import { processAction } from './process-action'
import { processResource } from './process-resource'

export function processColor(color: string | Array<number>) {
if (Array.isArray(color)) {
return Color.rgba(color[0], color[1], color[2], color[3] ?? 1)
}
else if (isString(color) && /color\(.+\)/) {
return Color.parse(color.replace(/color\(/, '').replace(/\)$/, ''))
}
else if (isString(color) && /shader\(.+\)/) {
return Shader.createColorShader(Color.WHITE)
}
else {
return color
}
}

export function processOptions(options: WidgetOptions) {
for (const key in options) {
if (typeof (options as Record<string, any>)[key] === 'object')
(options as Record<string, any>)[key] = processOptions((options as Record<string, any>)[key])
const result1 = processResource((options as Record<string, any>)[key])
const result2 = processColor((options as Record<string, any>)[key])
if (isString(result2)) {
if (isString(result1)) {
(options as Record<string, any>)[key] = (options as Record<string, any>)[key]
}
else {
(options as Record<string, any>)[key] = result1
}
}
else {
(options as Record<string, any>)[key] = result2
}
}
return options
}

export function processArguments(args: unknown[]) {
const result = []
for (const arg of args) {
if (isString(arg)) {
const result1 = processResource(arg as string)
const result2 = processColor(arg as string)
if (isString(result1)) {
if (isString(result2)) {
result.push(arg)
}
else {
result.push(result2)
}
}
else {
result.push(result1)
}
}
else {
result.push(arg)
}
}

return result
}

export function importWidget<T extends typeof Widget>(
widgetData: WidgetFormat | string,
Expand All @@ -10,7 +74,7 @@ export function importWidget<T extends typeof Widget>(
if (typeof widgetData === 'string') {
widgetData = JSON.parse(widgetData) as WidgetFormat
}
const widget = new widgets[widgetData.type](...widgetData.arguments, widgetData.options)
const widget = new widgets[widgetData.type](...processArguments(widgetData.arguments), processOptions(widgetData.options))
if (widgetData.children) {
widget.add(...widgetData.children.map((child) => {
return importWidget(child, widgets, anims)
Expand Down
16 changes: 16 additions & 0 deletions packages/json/src/process-resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useFont, useImage } from '@newcar/core'

export function processResource(str: string) {
const rex = /(?:image|font)\(.+\)/
if (rex.test(str)) {
if (/image\(.+\)/) {
return useImage(str.replace(/image\(/, '').replace(/\)$/, ''))
}
else if (/font\(.+\)/.test(str)) {
return useFont(str.replace(/font\(/, '').replace(/\)$/, ''))
}
}
else {
return str
}
}
2 changes: 1 addition & 1 deletion packages/newcar/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "newcar",
"type": "module",
"version": "2.0.0-beta.5",
"version": "2.0.0-beta.6",
"description": "A Highly configurable universal advanced engine, Born for creating animation rapidly.",
"author": "BugDuck Team",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/recorder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@newcar/recorder",
"version": "2.0.0-beta.5",
"version": "2.0.0-beta.6",
"description": "The utils of newcar",
"author": "BugDuck Team",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@newcar/utils",
"version": "2.0.0-beta.5",
"version": "2.0.0-beta.6",
"description": "The utils of newcar",
"author": "BugDuck Team",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion plugins/plugin-debug/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@newcar/plugin-debug",
"version": "2.0.0-beta.5",
"version": "2.0.0-beta.6",
"description": "",
"author": "BugDuck Team",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion plugins/plugin-timeview/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@newcar/plugin-timeview",
"version": "2.0.0-beta.5",
"version": "2.0.0-beta.6",
"description": "",
"author": "BugDuck Team",
"license": "Apache-2.0",
Expand Down
Loading

0 comments on commit 3a6e91d

Please sign in to comment.