Skip to content
Merged
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
2 changes: 1 addition & 1 deletion packages/webgal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"mitt": "^3.0.0",
"modern-css-reset": "^1.4.0",
"pixi-filters": "^4.2.0",
"pixi-live2d-display-webgal": "^0.5.2",
"pixi-live2d-display-webgal": "^0.5.8",
"pixi-spine": "^3.1.2",
"pixi.js": "^6.3.0",
"popmotion": "^11.0.5",
Expand Down
20 changes: 18 additions & 2 deletions packages/webgal/src/Core/controller/stage/pixi/PixiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'pixi-spine'; // Do this once at the very start of your code. This regist
import { Spine } from 'pixi-spine';
import { SCREEN_CONSTANTS } from '@/Core/util/constants';
// import { figureCash } from '@/Core/gameScripts/vocal/conentsCash'; // 如果要使用 Live2D,取消这里的注释
// import { Live2DModel, SoundManager } from 'pixi-live2d-display'; // 如果要使用 Live2D,取消这里的注释
// import { Live2DModel, SoundManager } from 'pixi-live2d-display-webgal'; // 如果要使用 Live2D,取消这里的注释

export interface IAnimationObject {
setStartState: Function;
Expand Down Expand Up @@ -689,7 +689,23 @@ export default class PixiStage {
// const setup = () => {
// if (thisFigureContainer) {
// (async function () {
// const models = await Promise.all([Live2DModel.from(jsonPath, { autoInteract: false })]);
// let overrideBounds: [number, number, number, number] = [0, 0, 0, 0];
// const mot = webgalStore.getState().stage.live2dMotion.find((e) => e.target === key);
// if (mot?.overrideBounds) {
// overrideBounds = mot.overrideBounds;
// }
// console.log(overrideBounds);
// const models = await Promise.all([
// Live2DModel.from(jsonPath, {
// autoInteract: false,
// overWriteBounds: {
// x0: overrideBounds[0],
// y0: overrideBounds[1],
// x1: overrideBounds[2],
// y1: overrideBounds[3],
// },
// }),
// ]);
//
// models.forEach((model) => {
// const scaleX = stageWidth / model.width;
Expand Down
29 changes: 25 additions & 4 deletions packages/webgal/src/Core/gameScripts/changeFigure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function changeFigure(sentence: ISentence): IPerform {
let animationFlag: any = '';
let mouthAnimationKey: any = 'mouthAnimation';
let eyesAnimationKey: any = 'blinkAnimation';
let overrideBounds = '';
const dispatch = webgalStore.dispatch;

for (const e of sentence.args) {
Expand Down Expand Up @@ -63,6 +64,9 @@ export function changeFigure(sentence: ISentence): IPerform {
case 'motion':
motion = e.value.toString();
break;
case 'bounds':
overrideBounds = String(e.value);
break;
case 'expression':
expression = e.value.toString();
break;
Expand Down Expand Up @@ -215,8 +219,10 @@ export function changeFigure(sentence: ISentence): IPerform {
*/
const freeFigureItem: IFreeFigure = { key, name: content, basePosition: pos };
setAnimationNames(key, sentence);
if (motion) {
dispatch(stageActions.setLive2dMotion({ target: key, motion }));
if (motion || overrideBounds) {
dispatch(
stageActions.setLive2dMotion({ target: key, motion, overrideBounds: getOverrideBoundsArr(overrideBounds) }),
);
}
if (expression) {
dispatch(stageActions.setLive2dExpression({ target: key, expression }));
Expand All @@ -236,8 +242,10 @@ export function changeFigure(sentence: ISentence): IPerform {

key = positionMap[pos];
setAnimationNames(key, sentence);
if (motion) {
dispatch(stageActions.setLive2dMotion({ target: key, motion }));
if (motion || overrideBounds) {
dispatch(
stageActions.setLive2dMotion({ target: key, motion, overrideBounds: getOverrideBoundsArr(overrideBounds) }),
);
}
if (expression) {
dispatch(stageActions.setLive2dExpression({ target: key, expression }));
Expand All @@ -255,3 +263,16 @@ export function changeFigure(sentence: ISentence): IPerform {
stopTimeout: undefined, // 暂时不用,后面会交给自动清除
};
}

function getOverrideBoundsArr(raw: string): undefined | [number, number, number, number] {
const parseOverrideBoundsResult = raw.split(',').map((e) => Number(e));
let isPass = true;
parseOverrideBoundsResult.forEach((e) => {
if (isNaN(e)) {
isPass = false;
}
});
isPass = isPass && parseOverrideBoundsResult.length === 4;
if (isPass) return parseOverrideBoundsResult as [number, number, number, number];
else return undefined;
}
1 change: 1 addition & 0 deletions packages/webgal/src/store/stageInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export interface IRunPerform {
export interface ILive2DMotion {
target: string;
motion: string;
overrideBounds?: [number, number, number, number];
}

export interface ILive2DExpression {
Expand Down
5 changes: 3 additions & 2 deletions packages/webgal/src/store/stageReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,17 @@ const stageSlice = createSlice({
}
},
setLive2dMotion: (state, action: PayloadAction<ILive2DMotion>) => {
const { target, motion } = action.payload;
const { target, motion, overrideBounds } = action.payload;

const index = state.live2dMotion.findIndex((e) => e.target === target);

if (index < 0) {
// Add a new motion
state.live2dMotion.push({ target, motion });
state.live2dMotion.push({ target, motion, overrideBounds });
} else {
// Update the existing motion
state.live2dMotion[index].motion = motion;
state.live2dMotion[index].overrideBounds = overrideBounds;
}
},
setLive2dExpression: (state, action: PayloadAction<ILive2DExpression>) => {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4255,10 +4255,10 @@ pixi-filters@^4.2.0:
"@pixi/filter-twist" "4.2.0"
"@pixi/filter-zoom-blur" "4.2.0"

pixi-live2d-display-webgal@^0.5.2:
version "0.5.2"
resolved "https://registry.yarnpkg.com/pixi-live2d-display-webgal/-/pixi-live2d-display-webgal-0.5.2.tgz#a9153e39540a92293b91ccff8b106908415cfc52"
integrity sha512-XWI9Ev4OOB0cmve5RPdKP22LjjB7RdF2GkgRv55A3hEJgMvueuU4IZ5wBDuLYqHwiVxeWA/gTMycj7vyDCyn1g==
pixi-live2d-display-webgal@^0.5.8:
version "0.5.8"
resolved "https://registry.yarnpkg.com/pixi-live2d-display-webgal/-/pixi-live2d-display-webgal-0.5.8.tgz#1ff7b5016559ff56a5cfaa96abeac84c878a2bbf"
integrity sha512-yekmPckXykqziyFcmmgYlZU4ad42rRGGmUFvrm96YJrdRIi+V9uv/xKOrRBMxD/tr3Sckqp6hOr9Wi3UX6NNLw==
dependencies:
gh-pages "^4.0.0"

Expand Down