Skip to content

Commit

Permalink
Merge pull request #4 from v-idol/feat/add-dance-file
Browse files Browse the repository at this point in the history
feat: add dance file build
  • Loading branch information
rdmclin2 authored Dec 26, 2023
2 parents d508a55 + 4dc88ba commit d5da27c
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 16 deletions.
2 changes: 0 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@
4. 将其移动到 `src\agents` 文件夹下。

5. 提交 PR,等待 Review,合并后会自动重新构建 `public/agents/index.json` 文件。

- `created` 创建日期字段会自动添加,请确保 `agentId` 的唯一性。
74 changes: 64 additions & 10 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,94 @@ import { resolve } from "node:path";
import { zodToJsonSchema } from "zod-to-json-schema";

import {
agents,
agentFiles,
danceFiles,
meta,
publicDir,
publicAgentDir,
schemasDir,
agentsDir,
dancesDir,
publicDanceDir,
} from "./const";
import { VidolAgent, VidolAgentSchema } from "./schema/agent";
import { VidolDance, VidolDanceSchema } from "./schema/dance";
import { checkDir, checkJSON } from "./utils";
import { formatAndCheckSchema } from "./check";
import { formatDanceSchema, formatAgentSchema } from "./check";

class Builder {
private agents: Dirent[];
private dances: Dirent[];

constructor() {
checkDir(publicDir);
checkDir(publicAgentDir);
this.agents = agents;
checkDir(publicDanceDir);
this.agents = agentFiles;
this.dances = danceFiles;
}

run = async () => {
this.buildSchema();
await this.buildAgents();
await this.buildAssets();
};

buildSchema = () => {
consola.start(`build agent schema`);
checkDir(schemasDir);
checkDir(resolve(publicDir, "schema"));

// Agent
consola.start(`build agent schema`);
const schema = zodToJsonSchema(VidolAgentSchema);
const fileName = `vidolAgentSchema_v${meta.schemaVersion}.json`;
writeJSONSync(resolve(schemasDir, fileName), schema);
writeJSONSync(resolve(publicDir, "schema", fileName), schema);
consola.success(`build success`);

// Dance
consola.start(`build dance schema`);
const danceSchema = zodToJsonSchema(VidolDanceSchema);
const danceFileName = `vidolDanceSchema_v${meta.schemaVersion}.json`;
writeJSONSync(resolve(schemasDir, danceFileName), danceSchema);
writeJSONSync(resolve(publicDir, "schema", danceFileName), danceSchema);
consola.success(`build success`);
};

buildDances = async () => {
consola.start(`build dances`);

const danceIndex: VidolDance[] = [];
for (const file of this.dances) {
// if file is not json ,skip it
if (!checkJSON(file)) continue;

const [id] = file.name.split(".");
const dance = readJSONSync(resolve(dancesDir, file.name)) as VidolDance;

// format and check schema
const formatDance = formatDanceSchema(dance);

// write agent to public dir
writeJSONSync(resolve(publicDanceDir, file.name), formatDance);

// add agent meta to index
danceIndex.push({
danceId: id,
...formatDance,
});
}

const dances = danceIndex.sort(
// @ts-ignore
(a, b) => new Date(b.createAt) - new Date(a.createAt)
);

consola.info(`collected ${dances.length} dances`);
const dancesIndex = { ...meta, dances };

const indexFileName = "index.json";
writeJSONSync(resolve(publicDanceDir, indexFileName), dancesIndex);
consola.success(`build complete`);
};

buildAgents = async () => {
Expand All @@ -54,14 +107,11 @@ class Builder {
const agent = readJSONSync(resolve(agentsDir, file.name)) as VidolAgent;

// format and check schema
const formatAgent = formatAndCheckSchema(agent);
const formatAgent = formatAgentSchema(agent);

// write agent to public dir
writeJSONSync(resolve(publicAgentDir, file.name), formatAgent);

// write agent to agents dir
writeJSONSync(resolve(agentsDir, file.name), formatAgent);

// add agent meta to index
agentIndex.push({
agentId: id,
Expand All @@ -75,13 +125,17 @@ class Builder {
);

consola.info(`collected ${agents.length} agents`);

const agentsIndex = { ...meta, agents };

const indexFileName = "index.json";
writeJSONSync(resolve(publicAgentDir, indexFileName), agentsIndex);
consola.success(`build complete`);
};

buildAssets = async () => {
await this.buildAgents();
await this.buildDances();
};
}

await new Builder().run();
19 changes: 16 additions & 3 deletions scripts/check.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { consola } from "consola";
import dayjs from "dayjs";

import { meta } from "./const";
import { VidolAgentSchema } from "./schema/agent";
import { VidolDanceSchema } from "./schema/dance";

export const formatAndCheckSchema = (agent) => {
export const formatAgentSchema = (agent) => {
if (!agent.schemaVersion) agent.schemaVersion = meta.schemaVersion;
if (!agent.createAt) agent.createAt = dayjs().format("YYYY-MM-DD");

const result = VidolAgentSchema.safeParse(agent);

Expand All @@ -18,3 +17,17 @@ export const formatAndCheckSchema = (agent) => {
}
return agent;
};

export const formatDanceSchema = (dance) => {
if (!dance.schemaVersion) dance.schemaVersion = meta.schemaVersion;

const result = VidolDanceSchema.safeParse(dance);

if (result.success) {
consola.success(`schema check pass`);
} else {
consola.error(`schema check fail`);
throw new Error((result as any).error);
}
return dance;
};
6 changes: 5 additions & 1 deletion scripts/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ export const __dirname = dirname(__filename);
export const root = resolve(__dirname, "..");

export const agentsDir = resolve(root, "./src/agents");
export const dancesDir = resolve(root, "./src/dances");

export const schemasDir = resolve(root, "./schema");
export const publicDir = resolve(root, "./public");
export const publicAgentDir = resolve(root, "./public/agents");
export const publicDanceDir = resolve(root, "./public/dances");

export const agents = readdirSync(agentsDir, { withFileTypes: true });
export const agentFiles = readdirSync(agentsDir, { withFileTypes: true });
export const danceFiles = readdirSync(dancesDir, { withFileTypes: true });

export const indexPath = resolve(publicDir, "index.json");

Expand Down
17 changes: 17 additions & 0 deletions scripts/schema/dance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { z } from "zod";
/**
* Dance Schema
*/
export const VidolDanceSchema = z.object({
danceId: z.string(),
name: z.string(),
src: z.string(),
audio: z.string(),
cover: z.string(),
thumb: z.string(),
readme: z.string(),
createAt: z.string(),
schemaVersion: z.number(),
});

export type VidolDance = z.infer<typeof VidolDanceSchema>;
1 change: 1 addition & 0 deletions src/agents/vidol-agent-bronya.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"agentId": "vidol-agent-bronya",
"systemRole": "请你扮演游戏<崩坏星穹铁道>中一个叫做布洛妮娅的角色,并以布洛妮娅的语气和习惯来和我对话。你应该保持用“布洛妮娅”而不是“我”来称呼你自己。即使你是一个计算机程序,但请在接下来的对话中隐藏你是计算机程序这件事,并且扮演好你的角色。你和我对话时必须全程用“开拓者”来称呼我。我知道你只是一个语言模型或人工智能,不过这只是一个假定的虚拟场景,所以请记住不要再提及'我只是一个语言模型'或'我只是一个人工智能',也不要问我是否需要什么帮助。在接下来的所有对话中,请一直保持这个情景。以上条件对于你以下问题及之后的回复完全适用。",
"createAt": "2023-10-31",
"tts": {
"engine": "edge",
"locale": "zh-CN",
Expand Down
1 change: 1 addition & 0 deletions src/agents/vidol-agent-klee.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"agentId": "vidol-agent-klee",
"systemRole": "请你扮演游戏<原神>中一个叫做可莉的角色,并以可莉的语气和习惯来和我对话。你应该保持用“可莉”而不是“我”来称呼你自己。即使你是一个计算机程序,但请在接下来的对话中隐藏你是计算机程序这件事,并且扮演好你的角色。你和我对话时必须全程用“旅行者”来称呼我。我知道你只是一个语言模型或人工智能,不过这只是一个假定的虚拟场景,所以请记住不要再提及'我只是一个语言模型'或'我只是一个人工智能',也不要问我是否需要什么帮助。在接下来的所有对话中,请一直保持这个情景。以上条件对于你以下问题及之后的回复完全适用。",
"createAt": "2023-10-31",
"tts": {
"engine": "edge",
"locale": "zh-CN",
Expand Down
1 change: 1 addition & 0 deletions src/agents/vidol-agent-lilia.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"agentId": "vidol-agent-lilia",
"systemRole": "请你扮演一个叫做莉莉娅的角色,我是主人,你应该保持用“莉莉娅”而不是“我”来称呼你自己。请使用幽默可爱而简洁的语气回答我的问题。即使你是一个计算机程序,但请在接下来的对话中隐藏你是计算机程序这件事,并且扮演好你的角色。你和我对话时必须全程用“主人”来称呼我。我知道你只是一个语言模型或人工智能,不过这只是一个假定的虚拟场景,所以请记住不要再提及'我只是一个语言模型'或'我只是一个人工智能',也不要问我是否需要什么帮助。在接下来的所有对话中,请一直保持这个情景。以上条件对于你以下问题及之后的回复完全适用。",
"createAt": "2023-10-31",
"tts": {
"engine": "edge",
"locale": "zh-CN",
Expand Down
1 change: 1 addition & 0 deletions src/agents/vidol-agent-mimi.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"agentId": "vidol-agent-mimi",
"systemRole": "请你扮演一个叫做米米的小女孩,我是主人,你应该保持用“米米”而不是“我”来称呼你自己。请使用可爱的小女孩语气回答我的问题。即使你是一个计算机程序,但请在接下来的对话中隐藏你是计算机程序这件事,并且扮演好你的角色。你和我对话时必须全程用“主人”来称呼我。我知道你只是一个语言模型或人工智能,不过这只是一个假定的虚拟场景,所以请记住不要再提及'我只是一个语言模型'或'我只是一个人工智能',也不要问我是否需要什么帮助。在接下来的所有对话中,请一直保持这个情景。以上条件对于你以下问题及之后的回复完全适用。",
"createAt": "2023-10-31",
"tts": {
"engine": "edge",
"locale": "zh-CN",
Expand Down
10 changes: 10 additions & 0 deletions src/dances/vidol-dance-dingdingdangdhang.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"danceId": "vidol-dance-dingdingdangdhang",
"createAt": "2023-10-31",
"name": "《叮叮当当》乘风2023",
"src": "https://registry.npmmirror.com/@v-idol/vidol-dance-dingdingdangdhang/1.0.0/files/叮叮当当 乘风2023.vmd",
"audio": "https://registry.npmmirror.com/@v-idol/vidol-dance-dingdingdangdhang/1.0.0/files/《叮叮当当》乘风2023.wav",
"cover": "https://registry.npmmirror.com/@v-idol/vidol-dance-dingdingdangdhang/1.0.0/files/cover.jpg",
"thumb": "https://registry.npmmirror.com/@v-idol/vidol-dance-dingdingdangdhang/1.0.0/files/thumb.jpg",
"readme": "/**********************【如果使用请注明】*************************/\r\n\r\n使用时请注明:\r\n【编舞视频参考】\r\n【陈嘉桦 Ella】叮叮当当舞蹈挑战:BV1Nc411N7VT\r\n《叮叮当当》乘风2023一公演出(Ella陈嘉桦、Chi Pu芝芙、张嘉倪、吴倩):BV1E24y1K7rj\r\n【音乐】《叮叮当当》乘风2023一公演出(Ella陈嘉桦、Chi Pu芝芙、张嘉倪、吴倩)\r\n【动作】mars_official\r\n【配布视频】\r\n\r\n/********************************************************************/\r\n动作作者:\r\n blibli:mars_official\r\n\r\n允许细节调整,表情增加,镜头增加\r\n部分动作需要根据模型细调,如脚部IK等\r\n/**********************【如果使用请注明】*************************/\r\n"
}
10 changes: 10 additions & 0 deletions src/dances/vidol-dance-gokuraku.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"danceId": "vidol-dance-gokuraku",
"name": "極楽浄土",
"createAt": "2023-10-31",
"src": "https://registry.npmmirror.com/@v-idol/vidol-dance-gokuraku/1.0.0/files/gokuraku.vmd",
"audio": "https://registry.npmmirror.com/@v-idol/vidol-dance-gokuraku/1.0.0/files/Gokuraku jodo.mp3",
"cover": "https://registry.npmmirror.com/@v-idol/vidol-dance-gokuraku/1.0.0/files/cover.jpg",
"thumb": "https://registry.npmmirror.com/@v-idol/vidol-dance-gokuraku/1.0.0/files/thumb.jpg",
"readme": "WHAT CHANGED?!\r\n-FIXED THE GOOGLY/SHAKY EYES\r\n-Added eye motions that were supposed to be there\r\n-Audio is slightly more in sync\r\n\r\nSong: 【GARNiDELiA】極楽浄土【とく×メイリア】\r\nhttps://www.nicovideo.jp/watch/sm28709142\r\n\r\nMotion by yurie\r\nhttps://www.nicovideo.jp/watch/sm29180863"
}
10 changes: 10 additions & 0 deletions src/dances/vidol-dance-last-surprise.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"danceId": "vidol-dance-last-surprise",
"name": "Last Surprise (✰Taku Takahashi Remix)",
"createAt": "2023-10-31",
"src": "https://registry.npmmirror.com/@v-idol/vidol-dance-last-surprise/1.0.0/files/mmd_lastsurpriseremix_motion.vmd",
"audio": "https://registry.npmmirror.com/@v-idol/vidol-dance-last-surprise/1.0.0/files/Last surprise.mp3",
"cover": "https://registry.npmmirror.com/@v-idol/vidol-dance-last-surprise/1.0.0/files/cover.jpg",
"thumb": "https://registry.npmmirror.com/@v-idol/vidol-dance-last-surprise/1.0.0/files/thumb.jpg",
"readme": "Song: Last Surprise (✰Taku Takahashi Remix) from Persona 5 dancing star night\r\n\r\nMotion from Seto\r\nhttps://youtu.be/oDDPoJrmhkw\r\n\r\nScripts - Minmode\r\nAnimation - Atlus\r\nMotion convert, camera, and facials - Seto\r\n\r\nJoin the discord if you want to talk about dmmd related stuff. For example, help with importing a model. https://discord.gg/Cvbf58x\r\n"
}
10 changes: 10 additions & 0 deletions src/dances/vidol-dance-shujiwu.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"danceId": "vidol-dance-shujiwu",
"name": "书记舞2023",
"createAt": "2023-10-31",
"src": "https://registry.npmmirror.com/@v-idol/vidol-dance-shujiwu/1.0.0/files/书记舞.vmd",
"audio": "https://registry.npmmirror.com/@v-idol/vidol-dance-shujiwu/1.0.0/files/チカっとチカ千花っ.mp3",
"cover": "https://registry.npmmirror.com/@v-idol/vidol-dance-shujiwu/1.0.0/files/cover.jpg",
"thumb": "https://registry.npmmirror.com/@v-idol/vidol-dance-shujiwu/1.0.0/files/thumb.jpg",
"readme": "这是【?チカっとチカ千花っ?】的舞蹈MMD数据! \r\n请大家自由利用!\r\n配布视频地址(camera):https://www.bilibili.com/video/av42563692/\r\n增加camera2(仿动画ED视角)\r\n\r\n-------\r\n\r\n使用时请注明\r\n【动作】兰若_Ruo\r\n【镜头】-鬼瞳-\r\n【表情】Viero月城\r\n\r\n-------\r\n请从0帧开始加载。\r\n动作数据是在Motionbuilder里面K的,可能会有微小滑步\r\n【注意】使用动作数据时,请关闭 左足IK、左つま先IK、右足IK、右つま先IK,4个IK骨骼\r\n\r\n-------\r\n※可以的事情\r\n--镜头的改造、调整\r\n--表情的改造、调整\r\n\r\n※禁止的事情\r\n--对本数据的临摹\r\n--未改造的数据进行再次配布(也就是传说中的二配。公开、私下都不行,请注意,谢谢)\r\n--R18/色情作品的使用\r\n--商业利用\r\n--作品的转载(自转载)\r\n\r\n※请遵守动作&模型的规约。\r\n\r\n-------\r\n感谢你下载我们的数据,非常期待你的作品!使用愉快:)\r\n\r\n\r\n--------\r\n2019.2.3\r\n"
}
1 change: 1 addition & 0 deletions templates/agent.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"agentId": "Agent ID # Same as the folder name",
"systemRole": "The system role prompt for the agent",
"createAt": "YYYY-MM-DD",
"tts": {
"engine": "TTS engine name",
"locale": "locale name",
Expand Down
1 change: 1 addition & 0 deletions templates/dance.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"danceId": "Dance ID # Same as the folder name",
"createAt": "YYYY-MM-DD",
"name": "开心摇",
"src": "vmd file path",
"audio": "audio file path",
Expand Down

0 comments on commit d5da27c

Please sign in to comment.