Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
372 changes: 240 additions & 132 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"@ffmpeg-installer/ffmpeg": "^1.1.0",
"@ffprobe-installer/ffprobe": "^2.1.2",
"@types/opentype.js": "^1.3.4",
"ag-psd": "^30.1.0",
"ag-psd-psdtool": "^1.1.10",
"mathjax-full": "^3.2.1",
"opentype.js": "^1.3.4",
"prismjs": "^1.30.0",
Expand Down
87 changes: 87 additions & 0 deletions src/lib/character/ast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import type { Variable } from "../animation"

export const PsdCharacterElement = {
Character: "Character",
MotionSequence: "MotionSequence",
DeclareVariable: "DeclareVariable",
Block: "Block",
DeclareAnimation: "DeclareAnimation",
Voice: "Voice",
Motion: "Motion",
} as const


export type CharacterChild =
| MotionSequenceNode
| DeclareVariableNode
| VoiceNode
| MotionNode

export type MotionSequenceChild =
| BlockNode
| DeclareVariableNode
| VoiceNode
| MotionNode

export type DeclareVariableChild =
| DeclareVariableNode
| DeclareAnimationNode

export type BlockChild =
| MotionSequenceNode
| DeclareVariableNode
| VoiceNode
| MotionNode

export type DeclareAnimationChild =
| MotionSequenceNode
| DeclareVariableNode
| VoiceNode
| MotionNode

export type VoiceChild =
| MotionNode




export interface CharacterNode {
type: typeof PsdCharacterElement.Character
children: CharacterChild[]
}

export interface MotionSequenceNode {
type: typeof PsdCharacterElement.MotionSequence
children: MotionSequenceChild[]
}

export interface DeclareVariableNode {
type: typeof PsdCharacterElement.DeclareVariable
variableName: string
initValue: any
children: DeclareVariableChild
}

export interface BlockNode {
type: typeof PsdCharacterElement.Block
children: BlockChild[]
}

export interface DeclareAnimationNode {
type: typeof PsdCharacterElement.DeclareAnimation
f: (ctx: any, variable: Record<string, Variable<any>>) => Promise<void>
children: DeclareAnimationChild[]
}

export interface VoiceNode {
type: typeof PsdCharacterElement.Voice
voice: string
volume: undefined | number | ((variables: Record<string, Variable<any>>, frames: number[]) => number)
children: VoiceChild[]
}

export interface MotionNode {
type: typeof PsdCharacterElement.Motion
motion: (variables: Record<string, Variable<any>>, frames: number[]) => Record<string, any>
}

12 changes: 12 additions & 0 deletions src/lib/character/defineDSL.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { ReactElement } from "react"

export type DslComponent<P = {}> = {
(props: P): ReactElement | null
__dslType: string
}

export function defineDSL<P>(type: string): DslComponent<P> {
const C = ((_: P) => null) as DslComponent<P>
C.__dslType = type
return C
}
3 changes: 3 additions & 0 deletions src/lib/character/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./psd-character"
export * from "./psd-character-component"
export * from "./util-motions"
Loading