Skip to content

Commit

Permalink
#147 feat: Shapeのレコード更新を履歴に対応(WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
ienaga committed Jul 18, 2024
1 parent 9f211e3 commit 5280305
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import { execute as characterUpdateYHistoryUndoUseCase } from "@/history/applica
import { execute as instanceUpdateNameHistoryUndoUseCase } from "@/history/application/core/application/Instance/usecase/InstanceUpdateNameHistoryUndoUseCase";
import { execute as instanceUpdateSymbolHistoryUndoUseCase } from "@/history/application/core/application/Instance/usecase/InstanceUpdateSymbolHistoryUndoUseCase";
import { execute as libraryAreaAddNewShapeHistoryUndoUseCase } from "@/history/application/controller/application/LibraryArea/Shape/usecase/LibraryAreaAddNewShapeHistoryUndoUseCase";
import { execute as libraryAreaUpdateShapeGraphicsHistoryUndoUseCase } from "@/history/application/controller/application/LibraryArea/Shape/usecase/LibraryAreaUpdateShapeGraphicsHistoryUndoUseCase";
import {
$SCREEN_TAB_NAME_UPDATE_COMMAND,
$TIMELINE_TOOL_LAYER_ADD_COMMAND,
Expand Down Expand Up @@ -111,7 +112,8 @@ import {
$STAGE_COLOR_COMMAND,
$CHARACTER_UPDATE_X,
$CHARACTER_UPDATE_Y,
$LIBRARY_ADD_NEW_SHAPE_COMMAND
$LIBRARY_ADD_NEW_SHAPE_COMMAND,
$LIBRARY_UPDATE_SHAPE_GRAPHICS_COMMAND
} from "@/config/HistoryConfig";
import { ShapeSaveObjectImpl } from "@/interface/ShapeSaveObjectImpl";

Expand Down Expand Up @@ -629,6 +631,14 @@ export const execute = async (
);
break;

// Shapeのグラフィックスを更新
case $LIBRARY_UPDATE_SHAPE_GRAPHICS_COMMAND:
libraryAreaUpdateShapeGraphicsHistoryUndoUseCase(
messages[0] as number, // WorkSpace ID
messages[2] as ShapeSaveObjectImpl // Shape Save Object
);
break;

default:
break;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { Shape } from "@/core/domain/model/Shape";
import type { BoundsImpl } from "@/interface/BoundsImpl";

/**
* @description Shapeのグラフィックスレコード更新とバウンディングボックス更新
* Update Shape graphics record and bounding box
*
* @param {Shape} shape
* @param {Float32Array} recodes
* @param {object} bounds
* @return {void}
* @method
* @public
*/
export const execute = (
shape: Shape,
recodes: Float32Array | number[],
bounds: BoundsImpl
): void => {
// 描画レコードを更新
// todo Float32ArrayをAnimation Toolの描画レコードに変換する
shape.recodes.length = 0;
shape.recodes.push(...Array.from(recodes));

// 描画反映のバウンディングボックスを更新
const rawBounds = shape.getRawBounds();
rawBounds.xMin = bounds.xMin;
rawBounds.yMin = bounds.yMin;
rawBounds.xMax = bounds.xMax;
rawBounds.yMax = bounds.yMax;
};
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { MovieClip } from "@/core/domain/model/MovieClip";
import type { MovieClip } from "@/core/domain/model/MovieClip";
import type { Shape } from "@/core/domain/model/Shape";
import { WorkSpace } from "@/core/domain/model/WorkSpace";
import type { ExternalShape } from "@/external/core/domain/model/ExternalShape";
import type { WorkSpace } from "@/core/domain/model/WorkSpace";
import type { BoundsImpl } from "@/interface/BoundsImpl";
import { execute as libraryAreaUpdateShapeGraphicsHistoryUseCase } from "@/history/application/controller/application/LibraryArea/Shape/usecase/LibraryAreaUpdateShapeGraphicsHistoryUseCase";
import { BoundsImpl } from "@/interface/BoundsImpl";
import { execute as externalShapeUpdateService } from "../service/ExternalShapeUpdateService";

/**
* @description グラフィックスの更新を適用
* Apply graphics update
*
* @param {WorkSpace} work_space
* @param {MovieClip} movie_clip
* @param {ExternalShape} external_shape
* @param {Float32Array} recodes
* @param {object} bounds
* @param {Shape} shape
* @param {boolean} [receiver=false]
* @return {Promise}
Expand All @@ -25,8 +26,8 @@ export const execute = async (
bounds: BoundsImpl,
shape: Shape,
receiver: boolean = false
): Promise<void> =>
{
): Promise<void> => {

// 履歴に登録
await libraryAreaUpdateShapeGraphicsHistoryUseCase(
work_space,
Expand All @@ -38,14 +39,9 @@ export const execute = async (
);

// 描画レコードを更新
// todo Float32ArrayをAnimation Toolの描画レコードに変換する
shape.recodes.length = 0;
shape.recodes.push(...Array.from(recodes));

// 描画反映のバウンディングボックスを更新
const rawBounds = shape.getRawBounds();
rawBounds.xMin = bounds.xMin;
rawBounds.yMin = bounds.yMin;
rawBounds.xMax = bounds.xMax;
rawBounds.yMax = bounds.yMax;
externalShapeUpdateService(
shape,
recodes,
bounds
);
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { ShapeSaveObjectImpl } from "@/interface/ShapeSaveObjectImpl";
import { execute as externalWorkSpaceRegisterInstanceService } from "@/external/core/application/ExternalWorkSpace/service/ExternalWorkSpaceRegisterInstanceService";
import { execute as libraryAreaReloadUseCase } from "@/controller/application/LibraryArea/usecase/LibraryAreaReloadUseCase";
import type { BoundsImpl } from "@/interface/BoundsImpl";
import { $getWorkSpace } from "@/core/application/CoreUtil";
import { Shape } from "@/core/domain/model/Shape";
import { execute as externalShapeUpdateService } from "@/external/core/application/ExternalShape/service/ExternalShapeUpdateService";
import { execute as screenDisplayObjectChangeElementUseCase } from "@/screen/application/DisplayObject/usecase/ScreenDisplayObjectChangeElementUseCase";

/**
* @description 新規Shape追加処理のRedo関数
Expand All @@ -16,21 +16,31 @@ import { Shape } from "@/core/domain/model/Shape";
*/
export const execute = (
work_space_id: number,
shape_object: ShapeSaveObjectImpl
before_shape_object: ShapeSaveObjectImpl,
recodes: number[],
bounds: BoundsImpl
): void => {

const workSpace = $getWorkSpace(work_space_id);
if (!workSpace) {
return ;
}

const shape = new Shape(shape_object);
const shape = workSpace.getLibrary(before_shape_object.id);
if (!shape) {
return ;
}

// 内部情報に登録
externalWorkSpaceRegisterInstanceService(workSpace, shape);
// Shapeの描画レコードを更新
externalShapeUpdateService(
shape,
recodes,
bounds
);

// 起動中のプロジェクトならライブラリエリアを再描画
if (workSpace.active) {
libraryAreaReloadUseCase();
// 配置されてるDisplayObjectのElementを入れ替える
screenDisplayObjectChangeElementUseCase(shape.id);
}
};
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
import type { Shape } from "@/core/domain/model/Shape";
import type { InstanceImpl } from "@/interface/InstanceImpl";
import type { ShapeSaveObjectImpl } from "@/interface/ShapeSaveObjectImpl";
import { execute as externalWorkSpaceRegisterInstanceService } from "@/external/core/application/ExternalWorkSpace/service/ExternalWorkSpaceRegisterInstanceService";
import { $getWorkSpace } from "@/core/application/CoreUtil";
import { execute as externalWorkSpaceRemoveInstanceService } from "@/external/core/application/ExternalWorkSpace/service/ExternalWorkSpaceRemoveInstanceService";
import { execute as libraryAreaReloadUseCase } from "@/controller/application/LibraryArea/usecase/LibraryAreaReloadUseCase";
import { Shape } from "@/core/domain/model/Shape";
import { $SCREEN_STAGE_AREA_ID } from "@/config/ScreenConfig";
import { execute as screenDisplayObjectChangeElementUseCase } from "@/screen/application/DisplayObject/usecase/ScreenDisplayObjectChangeElementUseCase";

/**
* @description 新規Shape追加処理のUndo関数
* Undo function for new Shape addition process
* @description Shapeの描画レコード更新処理のUndo関数
* Undo function of Shape drawing record update processing
*
* @param {number} work_space_id
* @param {object} shape_object
* @param {object} before_shape_object
* @return {void}
* @method
* @public
*/
export const execute = (
export const execute = async (
work_space_id: number,
shape_object: ShapeSaveObjectImpl
): void => {
before_shape_object: ShapeSaveObjectImpl
): Promise<void> => {

const workSpace = $getWorkSpace(work_space_id);
if (!workSpace) {
return ;
}

const shape: InstanceImpl<Shape> | null = workSpace.getLibrary(shape_object.id);
if (!shape) {
const element: HTMLElement | null = document
.getElementById($SCREEN_STAGE_AREA_ID);
if (!element) {
return ;
}

// 内部情報から削除
externalWorkSpaceRemoveInstanceService(workSpace, shape);
// 更新前のShapeを生成
const shape = new Shape(before_shape_object);

// 内部情報に登録
externalWorkSpaceRegisterInstanceService(workSpace, shape);

// 起動中のプロジェクトならライブラリを再描画
if (workSpace.active) {
libraryAreaReloadUseCase();
// 配置されてるDisplayObjectのElementを入れ替える
screenDisplayObjectChangeElementUseCase(shape.id);
}
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { WorkSpace } from "@/core/domain/model/WorkSpace";
import type { MovieClip } from "@/core/domain/model/MovieClip";
import type { Shape } from "@/core/domain/model/Shape";
import type { ExternalShape } from "@/external/core/domain/model/ExternalShape";
import { $useSocket } from "@/share/ShareUtil";
import { $LIBRARY_UPDATE_SHAPE_GRAPHICS_COMMAND } from "@/config/HistoryConfig";
import { execute as historyAddElementUseCase } from "@/controller/application/HistoryArea/usecase/HistoryAddElementUseCase";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { $SCREEN_STAGE_AREA_ID } from "@/config/ScreenConfig";
import { $getCurrentWorkSpace } from "@/core/application/CoreUtil";
import { $poolCanvas } from "@/global/GlobalUtil";
import { $setReDrawState } from "../../ScreenArea/ScreenAreaUtil";
import { execute as shapeCreateDisplayObjectElementUseCase } from "@/core/application/Shape/usecase/ShapeCreateDisplayObjectElementUseCase";
import { $SHAPE_TYPE } from "@/config/InstanceConfig";

/**
* @description 指定ライブラリのDisplayObjectのElementを入れ替える
* Replace the Element of the specified library's DisplayObject
*
* @param {number} library_id
* @return {void}
* @method
* @public
*/
export const execute = async (library_id: number): Promise<void> =>
{
const element: HTMLElement | null = document
.getElementById($SCREEN_STAGE_AREA_ID);
if (!element) {
return ;
}

const workSpace = $getCurrentWorkSpace();
const instance = workSpace.getLibrary(library_id);
if (!instance) {
return ;
}

const movieClip = workSpace.scene;
const frame = movieClip.currentFrame;
for (let idx = 0; idx < movieClip.layers.length; ++idx) {
const layer = movieClip.layers[idx];
if (!layer) {
continue;
}

const activeCharacters = layer.getActiveCharacters(frame);
if (!activeCharacters.length) {
continue;
}

const elements = element
.querySelectorAll(`layer-id-${layer.id}`);

for (let idx = 0; idx < activeCharacters.length; ++idx) {

const character = activeCharacters[idx];
if (!character) {
continue;
}

if (character.libraryId !== library_id) {
continue;
}

const node = elements[character.depth];
if (!node) {
continue;
}

// 既存のcanvasをキャッシュに戻す
const canvas = node.children[0] as HTMLCanvasElement;
if (canvas) {
$poolCanvas(canvas);
}

// 既存のElementを削除
node.remove();

// 変更前のShapeを描画したelementを再配置
$setReDrawState(true);
switch (instance.type) {

case $SHAPE_TYPE:
await shapeCreateDisplayObjectElementUseCase(
workSpace.id,
instance,
element,
layer,
character
);
break;

default:
break;

}
$setReDrawState(false);
}

}
};

0 comments on commit 5280305

Please sign in to comment.