Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Mar 2, 2024
1 parent 1c0e539 commit e754530
Show file tree
Hide file tree
Showing 29 changed files with 228 additions and 229 deletions.
8 changes: 3 additions & 5 deletions .gitignore
@@ -1,14 +1,11 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
test/dist/*
tests/dist/*
dist-ssr
*.local
# Editor directories and files
Expand All @@ -24,4 +21,5 @@ dist-ssr
.env
.cache
.temp
cache
cache
.npmrc
5 changes: 4 additions & 1 deletion docs/.vitepress/theme/index.ts
@@ -1,9 +1,12 @@
import DefaultTheme from 'vitepress/theme';

export default {
...DefaultTheme,

async enhanceApp() {
if (!(import.meta as any).env.SSR) {
const { loadOml2d } = await import('oh-mylive-2d');
const { loadOml2d } = await import('oh-my-live2d');

loadOml2d({
models: [
{
Expand Down
14 changes: 10 additions & 4 deletions packages/oh-my-live2d/package.json
Expand Up @@ -11,7 +11,8 @@
"bugs": "https://github.com/oh-my-live2d/oh-my-live2d/issues",
"repository": {
"type": "git",
"url": "git+https://github.com/oh-my-live2d/oh-my-live2d.git"
"url": "git+https://github.com/oh-my-live2d/oh-my-live2d.git",
"directory": "packages/oh-my-live2d"
},
"license": "MIT",
"author": "loclink",
Expand All @@ -22,17 +23,22 @@
"files": [
"dist"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
},
"scripts": {
"build": "rimraf dist && tsc && tsc-alias && node ./scripts/build.js",
"dev": "rimraf dist && tsc && (concurrently \"tsc -w\" \"tsc-alias -w\" \"cross-env OML_ENV=dev node ./scripts/build.js\" \"pnpm run test\")",
"build": "rimraf dist && tsc && node ./scripts/build.js",
"dev": "rimraf dist && tsc && (concurrently \"tsc -w\" \"cross-env OML_ENV=dev node ./scripts/build.js\" \"pnpm run test\")",
"release": "dotenv release-it"
},
"devDependencies": {
"csstype": "^3.1.3",
"pixi-live2d-display": "0.4.0",
"pixi.js": "6.5.10",
"tianjie": "^0.0.9",
"tsc-alias": "^1.8.8",
"vite": "5.1.4"
}
}
4 changes: 2 additions & 2 deletions packages/oh-my-live2d/scripts/build.js
Expand Up @@ -47,8 +47,8 @@ const profiles = entries.flatMap(({ entry, name, format }) => {
name: 'copy-min-file',
writeBundle(outOptions) {
if (outOptions.format === 'umd') {
fs.ensureDirSync(resolve(__dirname, '../test/vite-app/public'));
fs.copyFile(resolve(__dirname, `../dist/${name}.min.js`), resolve(__dirname, `../test/vite-app/public/${name}.min.js`));
fs.ensureDirSync(resolve(__dirname, '../../../testd/vite-app/public'));
fs.copyFile(resolve(__dirname, `../dist/${name}.min.js`), resolve(__dirname, `../../../tests/vite-app/public/${name}.min.js`));
}
}
}
Expand Down
86 changes: 86 additions & 0 deletions packages/oh-my-live2d/src/config/config.ts
@@ -0,0 +1,86 @@
import type { DefaultOptions } from '../types/index.js';

// 第三方库服务地址
const libServicePath = 'https://lib.oml2d.com';

// 默认配置选项, 实例化时会与用户传进来的合并
export const DEFAULT_OPTIONS: DefaultOptions = {
fixed: true,
sayHello: true,
transitionTime: 1000,
parentElement: document.body,
importType: 'complete',
libraryUrls: {
cubism2: `${libServicePath}/live2d.min.js`,
cubism5: `${libServicePath}/live2dcubismcore.min.js`
},
models: [],
tips: {
style: {
width: 230,
height: 100,
offsetX: 0,
offsetY: 0
},
idleTips: {
wordTheDay: false,
message: [],
duration: 5000,
interval: 10000,
priority: 2
},
welcomeTips: {
message: {
daybreak: '早上好!一日之计在于晨,美好的一天就要开始了。',
morning: '上午好!工作顺利嘛,不要久坐,多起来走动走动哦!',
noon: '中午了,工作了一个上午,现在是午餐时间!',
afternoon: '午后很容易犯困呢,来杯咖啡吧~',
dusk: '傍晚了!工作一天幸苦啦~',
night: '晚上好,今天过得怎么样呢?',
lateNight: '已经这么晚了呀,早点休息吧,晚安~',
weeHours: '这么晚还不睡吗?当心熬夜秃头哦!'
},
duration: 6000,
priority: 3
},
copyTips: {
duration: 3000,
priority: 3,
message: ['你复制了什么内容呢?记得注明出处哦~']
}
}
};

/** 第三方 SDK */
export const SDK = {
PIXI: `${libServicePath}/pixi.min.js`,
PIXI_LIVE2D_DISPLAY: `${libServicePath}/pixi-live2d-display.min.js`
};

/** 全局配置 */
export const CONFIG = {
stageId: 'oml2dStage',
canvasId: 'oml2dCanvas',
statusBarId: 'oml2dStatusBar',
tipsId: 'oml2dTips',
menusId: 'oml2dMenus'
};

/** 菜单的配置 */
export const MENU_ITEMS = [
{
id: 'SwitchModel',
name: 'icon-a-userswitch-fill',
title: '切换模型'
},
{
id: 'Play',
name: 'icon-skin-fill',
title: '变装'
},
{
id: 'About',
name: 'icon-info-circle-fill',
title: '关于'
}
];
90 changes: 2 additions & 88 deletions packages/oh-my-live2d/src/config/index.ts
@@ -1,88 +1,2 @@
import '@/library/iconfont';

import type { DefaultOptions } from '@/types';

// 第三方库服务地址
const libServicePath = 'https://lib.oml2d.com';

// 默认配置选项, 实例化时会与用户传进来的合并
export const defaultOptions: DefaultOptions = {
fixed: true,
sayHello: true,
transitionTime: 1000,
parentElement: document.body,
importType: 'complete',
libraryUrls: {
cubism2: `${libServicePath}/live2d.min.js`,
cubism5: `${libServicePath}/live2dcubismcore.min.js`
},
models: [],
tips: {
style: {
width: 230,
height: 100,
offsetX: 0,
offsetY: 0
},
idleTips: {
wordTheDay: false,
message: [],
duration: 5000,
interval: 10000,
priority: 2
},
welcomeTips: {
message: {
daybreak: '早上好!一日之计在于晨,美好的一天就要开始了。',
morning: '上午好!工作顺利嘛,不要久坐,多起来走动走动哦!',
noon: '中午了,工作了一个上午,现在是午餐时间!',
afternoon: '午后很容易犯困呢,来杯咖啡吧~',
dusk: '傍晚了!工作一天幸苦啦~',
night: '晚上好,今天过得怎么样呢?',
lateNight: '已经这么晚了呀,早点休息吧,晚安~',
weeHours: '这么晚还不睡吗?当心熬夜秃头哦!'
},
duration: 6000,
priority: 3
},
copyTips: {
duration: 3000,
priority: 3,
message: ['你复制了什么内容呢?记得注明出处哦~']
}
}
};

// 第三方SDK
export const SDK = {
PIXI: `${libServicePath}/pixi.min.js`,
PIXI_LIVE2D_DISPLAY: `${libServicePath}/pixi-live2d-display.min.js`
};

// 全局配置
export const config = {
stageId: 'oml2dStage',
canvasId: 'oml2dCanvas',
statusBarId: 'oml2dStatusBar',
tipsId: 'oml2dTips',
menusId: 'oml2dMenus'
};

// 菜单的配置
export const menusConfig = [
{
id: 'SwitchModel',
name: 'icon-a-userswitch-fill',
title: '切换模型'
},
{
id: 'Play',
name: 'icon-skin-fill',
title: '变装'
},
{
id: 'About',
name: 'icon-info-circle-fill',
title: '关于'
}
];
export * from './config.js';
export * from './style.js';
15 changes: 4 additions & 11 deletions packages/oh-my-live2d/src/constants/index.ts
@@ -1,15 +1,8 @@
const COMPLETE = 'complete';
const CUBISM2 = 'cubism2';
const CUBISM4 = 'cubism4';
export const COMPLETE = 'complete';
export const CUBISM2 = 'cubism2';
export const CUBISM4 = 'cubism4';

// export enum ImportType {
// COMPLETE = 'complete',
// CUBISM2 = 'cubism2',
// CUBISM4 = 'cubism4'
// }

export enum WindowSizeType {
export const enum WindowSizeType {
PC = 'PC',
MOBILE = 'MOBILE'
}
export { COMPLETE, CUBISM2, CUBISM4 };
12 changes: 9 additions & 3 deletions packages/oh-my-live2d/src/index.ts
@@ -1,15 +1,21 @@
import { setup } from '@/modules';
import { loadLibrary } from '@/utils';
import * as PIXI from 'pixi.js';

import { setup } from './modules/index.js';
import { loadLibrary } from './utils/index.js';

import './library/iconfont.js';

export * from './types/options.js';

(window as any).PIXI = PIXI;

PIXI.utils.skipHello();

export const loadOml2d = setup(async (importType, urls) => {
const Live2dModule = await loadLibrary(importType, urls);

return {
Live2dModule,
PIXI
};
});
export * from './types/options';
10 changes: 6 additions & 4 deletions packages/oh-my-live2d/src/index.umd.ts
@@ -1,5 +1,9 @@
import { setup } from '@/modules';
import { loadUmdLibrary } from '@/utils';
import { setup } from './modules/index.js';
import { loadUmdLibrary } from './utils/index.js';

import './library/iconfont.js';

export * from './types/options.js';

export const loadOml2d = setup(async (importType, urls) => {
await loadUmdLibrary(importType, urls);
Expand All @@ -9,5 +13,3 @@ export const loadOml2d = setup(async (importType, urls) => {
PIXI: (window as any).PIXI
};
});

export * from './types/options';
25 changes: 12 additions & 13 deletions packages/oh-my-live2d/src/modules/index.ts
@@ -1,17 +1,16 @@
import type { Application } from 'pixi.js';
import { checkVersion, formatUnit, printProjectInfo } from '../utils';

import { defaultOptions } from '@/config';
import { WindowSizeType } from '@/constants';
import { Menus } from '@/modules/menus';
import { Model } from '@/modules/model';
import { Stage } from '@/modules/stage';
import { StatusBar, SystemStete } from '@/modules/status-bar';
import { Tips } from '@/modules/tips';
import type { ApplicationType, DefaultOptions, Live2DModelType } from '@/types';
import { Options } from '@/types/options';
import { isNumber, mergeDeep } from 'tianjie';

import { WindowSizeType } from '../constants/index.js';
import { DEFAULT_OPTIONS } from '../config/index.js';
import { checkVersion, formatUnit, printProjectInfo } from '../utils/index.js';
import { Menus } from './menus.js';
import { Model } from './model.js';
import { Stage } from './stage.js';
import { StatusBar, SystemState } from './status-bar.js';
import { Tips } from './tips.js';
import type { ApplicationType, DefaultOptions, Live2DModelType, Options } from '../types/index.js';

export class OhMyLive2D {
private stage: Stage;
private statusBar: StatusBar;
Expand All @@ -38,7 +37,7 @@ export class OhMyLive2D {
initialize() {
this.verifyWindowSizeType();
if (this.windowSizeType !== WindowSizeType.PC) {
this.statusBar.popup('暂不支持移动端', SystemStete.info, 8000);
this.statusBar.popup('暂不支持移动端', SystemState.info, 8000);
return;
}
this.loadModel();
Expand Down Expand Up @@ -178,7 +177,7 @@ export const setup = (loadMethod) => {
let oml2d;
const loadOml2d = async (options: Options) => {
const { parentElement } = options;
const finalOptions = mergeDeep(defaultOptions, options);
const finalOptions = mergeDeep(DEFAULT_OPTIONS, options);
finalOptions.parentElement = parentElement || document.body;
if (!finalOptions.models?.length) throw new Error('至少需要配置一个模型');
const { Live2dModule, PIXI } = await loadMethod(finalOptions.importType, finalOptions.libraryUrls);
Expand Down

0 comments on commit e754530

Please sign in to comment.