Skip to content

Commit

Permalink
fix(redo-undo): change textureInspector->wrap,filter should add to re…
Browse files Browse the repository at this point in the history
…do-undo

update wonder.js version
  • Loading branch information
yyc-git committed Feb 25, 2019
1 parent a8b4657 commit db459eb
Show file tree
Hide file tree
Showing 17 changed files with 704 additions and 62 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"wonder-bs-most": "^0.0.3",
"wonder-commonlib": "0.2.26",
"wonder-log": "^0.2.10",
"wonder.js": "1.0.0-beta.1.4"
"wonder.js": "1.0.0-beta.1.5"
},
"resolutions": {
"wonder-log": "^0.2.10",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module CustomEventHandler = {
include EmptyEventHandler.EmptyEventHandler;
type prepareTuple = unit;
type dataTuple = (Wonderjs.ComponentType.component, int);
type return = unit;

let handleSelfLogic =
((uiState, dispatchFunc), (), (textureComponent, value)) => {
TextureFilterUtils.changeMagFilter(textureComponent, value);

();
};

let setUndoValueToCopiedEngineState =
((uiState, dispatchFunc), (), (textureComponent, value)) =>
StateEngineService.unsafeGetState()
|> StateEngineService.deepCopyForRestore
|> BasicSourceTextureEngineService.setIsNeedUpdate(true, textureComponent);
};

module MakeEventHandler = EventHandler.MakeEventHandler(CustomEventHandler);
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module CustomEventHandler = {
include EmptyEventHandler.EmptyEventHandler;
type prepareTuple = unit;
type dataTuple = (Wonderjs.ComponentType.component, int);
type return = unit;

let handleSelfLogic =
((uiState, dispatchFunc), (), (textureComponent, value)) => {
TextureFilterUtils.changeMinFilter(textureComponent, value);

();
};

let setUndoValueToCopiedEngineState =
((uiState, dispatchFunc), (), (textureComponent, value)) =>
StateEngineService.unsafeGetState()
|> StateEngineService.deepCopyForRestore
|> BasicSourceTextureEngineService.setIsNeedUpdate(true, textureComponent);
};

module MakeEventHandler = EventHandler.MakeEventHandler(CustomEventHandler);
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module CustomEventHandler = {
include EmptyEventHandler.EmptyEventHandler;
type prepareTuple = unit;
type dataTuple = (Wonderjs.ComponentType.component, int);
type return = unit;

let handleSelfLogic =
((uiState, dispatchFunc), (), (textureComponent, value)) => {
TextureWrapUtils.changeWrapS(textureComponent, value);

();
};

let setUndoValueToCopiedEngineState =
((uiState, dispatchFunc), (), (textureComponent, value)) =>
StateEngineService.unsafeGetState()
|> StateEngineService.deepCopyForRestore
|> BasicSourceTextureEngineService.setIsNeedUpdate(true, textureComponent);
};

module MakeEventHandler = EventHandler.MakeEventHandler(CustomEventHandler);
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module CustomEventHandler = {
include EmptyEventHandler.EmptyEventHandler;
type prepareTuple = unit;
type dataTuple = (Wonderjs.ComponentType.component, int);
type return = unit;

let handleSelfLogic =
((uiState, dispatchFunc), (), (textureComponent, value)) => {
TextureWrapUtils.changeWrapT(textureComponent, value);

();
};

let setUndoValueToCopiedEngineState =
((uiState, dispatchFunc), (), (textureComponent, value)) =>
StateEngineService.unsafeGetState()
|> StateEngineService.deepCopyForRestore
|> BasicSourceTextureEngineService.setIsNeedUpdate(true, textureComponent);
};

module MakeEventHandler = EventHandler.MakeEventHandler(CustomEventHandler);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Method = {
let renderWrapSSelect = textureComponent =>
let renderWrapSSelect = (dispatchFunc, textureComponent) =>
<Select
label="WrapS"
options=(TextureWrapUtils.getWrapOptions())
Expand All @@ -8,10 +8,17 @@ module Method = {
|> StateLogicService.getEngineStateToGetData
|> TextureTypeUtils.convertWrapToInt
)
onChange=(TextureWrapUtils.changeWrapS(textureComponent))
onChange=(
value =>
InspectorChangeTextureWrapSEventHandler.MakeEventHandler.pushUndoStackWithTwoHandleFunc(
(UIStateService.getState(), dispatchFunc),
(),
(textureComponent, value),
)
)
/>;

let renderWrapTSelect = textureComponent =>
let renderWrapTSelect = (dispatchFunc, textureComponent) =>
<Select
label="WrapT"
options=(TextureWrapUtils.getWrapOptions())
Expand All @@ -20,9 +27,16 @@ module Method = {
|> StateLogicService.getEngineStateToGetData
|> TextureTypeUtils.convertWrapToInt
)
onChange=(TextureWrapUtils.changeWrapT(textureComponent))
onChange=(
value =>
InspectorChangeTextureWrapTEventHandler.MakeEventHandler.pushUndoStackWithTwoHandleFunc(
(UIStateService.getState(), dispatchFunc),
(),
(textureComponent, value),
)
)
/>;
let renderMagFilterSelect = textureComponent =>
let renderMagFilterSelect = (dispatchFunc, textureComponent) =>
<Select
label="Mag Filter"
options=(TextureFilterUtils.getMagFilterOptions())
Expand All @@ -31,10 +45,17 @@ module Method = {
|> StateLogicService.getEngineStateToGetData
|> TextureTypeUtils.convertFilterToInt
)
onChange=(TextureFilterUtils.changeMagFilter(textureComponent))
onChange=(
value =>
InspectorChangeTextureMagFilterEventHandler.MakeEventHandler.pushUndoStackWithTwoHandleFunc(
(UIStateService.getState(), dispatchFunc),
(),
(textureComponent, value),
)
)
/>;

let renderMinFilterSelect = textureComponent =>
let renderMinFilterSelect = (dispatchFunc, textureComponent) =>
<Select
label="Min Filter"
options=(TextureFilterUtils.getMinFilterOptions())
Expand All @@ -43,7 +64,14 @@ module Method = {
|> StateLogicService.getEngineStateToGetData
|> TextureTypeUtils.convertFilterToInt
)
onChange=(TextureFilterUtils.changeMinFilter(textureComponent))
onChange=(
value =>
InspectorChangeTextureMinFilterEventHandler.MakeEventHandler.pushUndoStackWithTwoHandleFunc(
(UIStateService.getState(), dispatchFunc),
(),
(textureComponent, value),
)
)
/>;
};

Expand All @@ -59,14 +87,21 @@ let render = ((dispatchFunc, renameFunc), name, textureComponent, _self) =>
onBlur=renameFunc
canBeNull=false
/>
(Method.renderWrapSSelect(textureComponent))
(Method.renderWrapTSelect(textureComponent))
(Method.renderMagFilterSelect(textureComponent))
(Method.renderMinFilterSelect(textureComponent))
(Method.renderWrapSSelect(dispatchFunc, textureComponent))
(Method.renderWrapTSelect(dispatchFunc, textureComponent))
(Method.renderMagFilterSelect(dispatchFunc, textureComponent))
(Method.renderMinFilterSelect(dispatchFunc, textureComponent))
</article>;

let make =
(~uiState, ~dispatchFunc, ~name, ~textureComponent, ~renameFunc, _children) => {
(
~uiState,
~dispatchFunc,
~name,
~textureComponent,
~renameFunc,
_children,
) => {
...component,
render: self =>
render((dispatchFunc, renameFunc), name, textureComponent, self),
Expand Down
18 changes: 18 additions & 0 deletions src/core/ui/eventHandler/EventHandler.re
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,23 @@ module MakeEventHandler = (EventItem: EventHandler) => {

(StateEditorService.getState(), engineState)
|> StoreHistoryUtils.storeHistoryStateWithCopiedEngineState(uiState);

();
};

let pushUndoStackWithTwoHandleFunc =
((uiState, dispatchFunc) as reduxTuple, prepareTuple, dataTuple) => {
let engineState =
EventItem.setUndoValueToCopiedEngineState(
reduxTuple,
prepareTuple,
dataTuple,
);

(StateEditorService.getState(), engineState)
|> StoreHistoryUtils.storeHistoryStateWithCopiedEngineState(uiState)
|> ignore;

EventItem.handleSelfLogic(reduxTuple, prepareTuple, dataTuple);
};
};
2 changes: 1 addition & 1 deletion src/core/utils/controller/ControllerHistoryUtils.re
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let restoreHistoryStack =

(
lastEditorState,
lastEngineState |> StateEngineService.restoreState(engineState),
lastEngineState |> RestoreStateEngineService.restoreState(engineState),
)
|> StateHistoryService.refreshStateForHistory;

Expand Down
4 changes: 3 additions & 1 deletion src/service/state/engine/BasicSourceTextureEngineService.re
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,6 @@ let setIsNeedUpdate = (isNeedUpdate, texture, state) =>
);

let initTexture = (texture, state) =>
InitSourceTextureMainService.initTexture(texture |. Some, state);
InitSourceTextureMainService.initTexture(texture |. Some, state);

let getAllTextures = BasicSourceTextureAPI.getAllTextures;
19 changes: 0 additions & 19 deletions src/service/state/engine/StateEngineService.re

This file was deleted.

48 changes: 48 additions & 0 deletions src/service/state/engine/state/RestoreStateEngineService.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
let _isTextureParametersDifferent = (texture, currentState, targetState) =>
BasicSourceTextureEngineService.getWrapS(texture, currentState)
!== BasicSourceTextureEngineService.getWrapS(texture, targetState)
||
BasicSourceTextureEngineService.getWrapT(texture, currentState) !== BasicSourceTextureEngineService.getWrapT(
texture,
targetState,
)
||
BasicSourceTextureEngineService.getMagFilter(texture, currentState) !== BasicSourceTextureEngineService.getMagFilter(
texture,
targetState,
)
||
BasicSourceTextureEngineService.getMinFilter(texture, currentState) !== BasicSourceTextureEngineService.getMinFilter(
texture,
targetState,
);

let _getBasicSourceTexturesNeedUpdate = (currentState, targetState) =>
ArrayService.intersect(
BasicSourceTextureEngineService.getAllTextures(currentState),
BasicSourceTextureEngineService.getAllTextures(targetState),
)
|> Js.Array.filter(texture =>
_isTextureParametersDifferent(texture, currentState, targetState)
);

let _markBasicSourceTextureNeedUpdate =
(basicSourceTexturesNeedUpdate, restoredState) =>
basicSourceTexturesNeedUpdate
|> WonderCommonlib.ArrayService.reduceOneParam(
(. restoredState, texture) =>
BasicSourceTextureEngineService.setIsNeedUpdate(
true,
texture,
restoredState,
),
restoredState,
);

let restoreState = (currentState, targetState) => {
let basicSourceTexturesNeedUpdate =
_getBasicSourceTexturesNeedUpdate(currentState, targetState);

Wonderjs.StateAPI.restoreState(currentState, targetState)
|> _markBasicSourceTextureNeedUpdate(basicSourceTexturesNeedUpdate);
};
15 changes: 15 additions & 0 deletions src/service/state/engine/state/StateEngineService.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
let deepCopyForRestore = Wonderjs.StateAPI.deepCopyForRestore;

let createState = Wonderjs.StateAPI.createState;

let createStateData = Wonderjs.StateAPI.createStateData;

let getStateFromData = Wonderjs.StateAPI.getStateFromData;

let unsafeGetState = Wonderjs.StateAPI.unsafeGetState;

let setStateToData = Wonderjs.StateAPI.setStateToData;

let setState = Wonderjs.StateAPI.setState;

let setIsDebug = Wonderjs.StateAPI.setIsDebug;
4 changes: 2 additions & 2 deletions src/service/stateTuple/history/EngineHistoryService.re
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let undo = (historyState, currentState) =>
engineUndoStack: Stack.removeFirstOrRaise(historyState.engineUndoStack),
}
)
|> StateEngineService.restoreState(currentState);
|> RestoreStateEngineService.restoreState(currentState);

let redo = (historyState, currentState) =>
OperateStateHistoryService.operateHistory(
Expand All @@ -30,7 +30,7 @@ let redo = (historyState, currentState) =>
engineRedoStack: Stack.removeFirstOrRaise(historyState.engineRedoStack),
}
)
|> StateEngineService.restoreState(currentState);
|> RestoreStateEngineService.restoreState(currentState);

let storeHasCopyState = (maxStackSize, currentState, historyState) => {
...historyState,
Expand Down
Loading

0 comments on commit db459eb

Please sign in to comment.