-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove hide props * Update default format version * Fix format version type * Add animations * Add animation controllers * Add animations accessor
- Loading branch information
Showing
7 changed files
with
142 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Project } from "../../core/Project.ts"; | ||
import { AddonFile } from "../AddonFile.ts"; | ||
import { StringOrRecord } from "../common/StringOrRecord.ts"; | ||
|
||
export class AnimationControllers extends AddonFile { | ||
#data: AnimationControllersSchema; | ||
constructor(fileName: string) { | ||
super(fileName); | ||
this.#data = { | ||
format_version: "1.10.0", | ||
animation_controllers: {}, | ||
}; | ||
|
||
Project.onSave(({ writeBP }) => { | ||
writeBP(`animation_controllers/${this.fileName}.json`, this.#data); | ||
}); | ||
} | ||
|
||
/** | ||
* @param id The id of the animation controller, without the `controller.animation.` prefix | ||
*/ | ||
add(id: string, controller?: AnimationController) { | ||
controller ??= { | ||
states: {}, | ||
}; | ||
return this.#data.animation_controllers[`controller.animation.${id}`] = controller; | ||
} | ||
|
||
/** | ||
* @param id The id of the animation controller, without the `controller.animation.` prefix | ||
*/ | ||
get(id: string) { | ||
return this.#data.animation_controllers[`controller.animation.${id}`]; | ||
} | ||
|
||
/** | ||
* @param id The id of the animation controller, without the `controller.animation.` prefix | ||
*/ | ||
delete(id: string) { | ||
delete this.#data.animation_controllers[`controller.animation.${id}`]; | ||
} | ||
} | ||
|
||
export interface AnimationControllersSchema { | ||
format_version: string; | ||
animation_controllers: Record<string, AnimationController>; | ||
} | ||
|
||
export interface AnimationController { | ||
initial_state?: string; | ||
states: Record<string, AnimationControllerState>; | ||
} | ||
|
||
export interface AnimationControllerState { | ||
animations?: StringOrRecord[]; | ||
on_entry?: string[]; | ||
on_exit?: string[]; | ||
transitions?: Record<string, string>[]; | ||
} |
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,58 @@ | ||
import { Project } from "../../core/Project.ts"; | ||
import { AddonFile } from "../AddonFile.ts"; | ||
|
||
export class Animations extends AddonFile { | ||
#data: AnimationsSchema; | ||
/** | ||
* @param fileName File name without extension | ||
*/ | ||
constructor(fileName: string) { | ||
super(fileName); | ||
this.#data = { | ||
format_version: "1.10.0", | ||
animations: {}, | ||
}; | ||
|
||
Project.onSave(({ writeBP }) => { | ||
writeBP(`animations/${this.fileName}.json`, this.#data); | ||
}); | ||
} | ||
|
||
/** | ||
* @param id The id of the animation, without the `animation.` prefix | ||
*/ | ||
add(id: string, animation?: Animation) { | ||
animation ??= { | ||
timeline: {}, | ||
}; | ||
return this.#data.animations[`animation.${id}`] = animation; | ||
} | ||
|
||
/** | ||
* @param id The id of the animation, without the `animation.` prefix | ||
*/ | ||
get(id: string) { | ||
return this.#data.animations[`animation.${id}`]; | ||
} | ||
|
||
/** | ||
* @param id The id of the animation, without the `animation.` prefix | ||
*/ | ||
delete(id: string) { | ||
delete this.#data.animations[`animation.${id}`]; | ||
} | ||
} | ||
|
||
export interface AnimationsSchema { | ||
format_version: string; | ||
animations: Record<string, Animation>; | ||
} | ||
|
||
export interface Animation { | ||
anim_time_update?: string | number; | ||
animation_length?: number; | ||
loop?: boolean; | ||
loop_delay?: string | number; | ||
start_delay?: string | number; | ||
timeline: Record<number, string[]>; | ||
} |
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