Skip to content

Commit

Permalink
feat(uicontrol): abstract runstopbutton ui control to switch button
Browse files Browse the repository at this point in the history
update input corresponding;
  • Loading branch information
yyc-git committed Nov 22, 2023
1 parent cc4eec6 commit e0805d0
Show file tree
Hide file tree
Showing 54 changed files with 279 additions and 313 deletions.
5 changes: 4 additions & 1 deletion .cz-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ module.exports = {
{ name: "utils" },
{ name: "demos" },
{ name: "backend" },
{ name: "defaults" }
{ name: "defaults" },
{ name: "uicontrol" },
{ name: "action" },
{ name: "input" },
],

// it needs to match the value for field type. Eg.: "fix"
Expand Down
6 changes: 3 additions & 3 deletions contributes/meta3d-input-runstopbutton/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "meta3d-input-runstopbutton",
"version": "0.20.1",
"version": "0.20.2",
"publisher": "0xf63e1991A343814EdE505D7cfC368615EAe75307",
"description": "",
"protocol": {
"name": "meta3d-input-runstopbutton-protocol"
"name": "meta3d-input-switch-button-protocol"
},
"license": "MIT",
"scripts": {
Expand All @@ -16,7 +16,7 @@
"keywords": [],
"dependencies": {
"meta3d-type": "^0.20.0",
"meta3d-input-runstopbutton-protocol": "^0.20.0"
"meta3d-input-switch-button-protocol": "^0.20.0"
},
"devDependencies": {
"clean-webpack-plugin": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion contributes/meta3d-input-runstopbutton/src/Main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getContribute as getContributeMeta3D } from "meta3d-type"
import { data } from "meta3d-input-runstopbutton-protocol"
import { data } from "meta3d-input-switch-button-protocol"
import { inputContribute } from "meta3d-editor-whole-protocol/src/service/ServiceType"
import { actionName as runActionName, state as runState } from "meta3d-action-run-protocol"

Expand Down
33 changes: 0 additions & 33 deletions contributes/meta3d-input-runstopbutton2/package.json

This file was deleted.

12 changes: 0 additions & 12 deletions contributes/meta3d-input-runstopbutton2/src/Main.ts

This file was deleted.

25 changes: 0 additions & 25 deletions contributes/meta3d-ui-control-runstopbutton/gulpfile.js

This file was deleted.

24 changes: 0 additions & 24 deletions contributes/meta3d-ui-control-runstopbutton/tsconfig.json

This file was deleted.

64 changes: 0 additions & 64 deletions contributes/meta3d-ui-control-runstopbutton/webpack.config.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "meta3d-ui-control-runstopbutton",
"name": "meta3d-ui-control-switch-button",
"version": "0.20.6",
"publisher": "0xf63e1991A343814EdE505D7cfC368615EAe75307",
"description": "",
"protocol": {
"name": "meta3d-ui-control-runstopbutton-protocol"
"name": "meta3d-ui-control-switch-button-protocol"
},
"license": "MIT",
"scripts": {
Expand All @@ -17,7 +17,7 @@
"dependencies": {
"meta3d-editor-whole-protocol": "^0.20.0",
"meta3d-type": "^0.20.0",
"meta3d-ui-control-runstopbutton-protocol": "^0.20.0"
"meta3d-ui-control-switch-button-protocol": "^0.20.0"
},
"devDependencies": {
"clean-webpack-plugin": "^4.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { api, getContribute as getContributeMeta3D } from "meta3d-type"
import { state as meta3dState } from "meta3d-type"
import { inputFunc, specificData, outputData, uiControlName, state, imageBase64 } from "meta3d-ui-control-runstopbutton-protocol"
import { inputFunc, specificData, outputData, uiControlName, state, imageBase64 } from "meta3d-ui-control-switch-button-protocol"
import { service, uiControlContribute } from "meta3d-editor-whole-protocol/src/service/ServiceType"
// import runImageSrc from "url-loader!./image/run.png"
// import stopImageSrc from "url-loader!./image/stop.png"
import { nullable } from "meta3d-commonlib-ts/src/nullable"
// import { actionName as runActionName, state as runState } from "meta3d-action-run-protocol"

let _loadImage = (
meta3dState: meta3dState,
Expand All @@ -17,18 +14,14 @@ let _loadImage = (

let state = api.nullable.getExn(api.uiControl.getUIControlState<state>(meta3dState, uiControlName))

// console.warn(image1, image2);


let promise = null
// if (api.nullable.isNullable(state.runTexture) ) {
// if (api.nullable.isNullable(state.runTexture) && !api.nullable.isNullable(image1)) {
if (!api.nullable.isNullable(image1) && api.nullable.getWithDefault(api.nullable.map(lastRunTextureImageBase64 => lastRunTextureImageBase64 != api.nullable.getExn(image1), state.lastRunTextureImageBase64), true)) {
promise = loadImage(meta3dState, api.nullable.getExn(image1)).then((runTexture: any) => {
if (!api.nullable.isNullable(image1) && api.nullable.getWithDefault(api.nullable.map(lastEvent1TextureImageBase64 => lastEvent1TextureImageBase64 != api.nullable.getExn(image1), state.lastEvent1TextureImageBase64), true)) {
promise = loadImage(meta3dState, api.nullable.getExn(image1)).then((event1Texture: any) => {
meta3dState = api.uiControl.setUIControlState<state>(meta3dState, uiControlName, {
...state,
runTexture,
lastRunTextureImageBase64: api.nullable.getExn(image1)
event1Texture,
lastEvent1TextureImageBase64: api.nullable.getExn(image1)
})

return meta3dState
Expand All @@ -38,16 +31,13 @@ let _loadImage = (
promise = Promise.resolve(meta3dState)
}

// if (api.nullable.isNullable(state.stopTexture)) {
// if (api.nullable.isNullable(state.stopTexture) && !api.nullable.isNullable(image2)) {
if (!api.nullable.isNullable(image2) && api.nullable.getWithDefault(api.nullable.map(lastStopTextureImageBase64 => lastStopTextureImageBase64 != api.nullable.getExn(image2), state.lastStopTextureImageBase64), true)) {
// if (!api.nullable.isNullable(image2)) {
if (!api.nullable.isNullable(image2) && api.nullable.getWithDefault(api.nullable.map(lastEvent2TextureImageBase64 => lastEvent2TextureImageBase64 != api.nullable.getExn(image2), state.lastEvent2TextureImageBase64), true)) {
return promise.then(meta3dState => {
return loadImage(meta3dState, api.nullable.getExn(image2)).then((stopTexture: any) => {
return loadImage(meta3dState, api.nullable.getExn(image2)).then((event2Texture: any) => {
meta3dState = api.uiControl.setUIControlState<state>(meta3dState, uiControlName, {
...state,
stopTexture,
lastStopTextureImageBase64: api.nullable.getExn(image2)
event2Texture,
lastEvent2TextureImageBase64: api.nullable.getExn(image2)
})

return meta3dState
Expand All @@ -74,27 +64,27 @@ export let getContribute: getContributeMeta3D<uiControlContribute<inputFunc, spe
return Promise.resolve([meta3dState, [false, false]])
}

return api.nullable.getExn(getInputFunc)(meta3dState).then(isRun => {
return api.nullable.getExn(getInputFunc)(meta3dState).then(isEvent1 => {
return _loadImage(
meta3dState,
api,
image1,
image2,
).then(meta3dState => {
let { runStopButton, setCursorPos } = api.nullable.getExn(api.getPackageService<service>(meta3dState, "meta3d-editor-whole-protocol")).ui(meta3dState)
let { switchButton, setCursorPos } = api.nullable.getExn(api.getPackageService<service>(meta3dState, "meta3d-editor-whole-protocol")).ui(meta3dState)

meta3dState = setCursorPos(meta3dState, [rect.x, rect.y])

let { runTexture,
stopTexture,
let { event1Texture,
event2Texture,
} = api.nullable.getExn(api.uiControl.getUIControlState<state>(meta3dState, uiControlName))

if (!api.nullable.isNullable(runTexture) && !api.nullable.isNullable(stopTexture)) {
return runStopButton(meta3dState,
isRun,
if (!api.nullable.isNullable(event1Texture) && !api.nullable.isNullable(event2Texture)) {
return switchButton(meta3dState,
isEvent1,
{
runTexture: api.nullable.getExn(runTexture),
stopTexture: api.nullable.getExn(stopTexture),
event1Texture: api.nullable.getExn(event1Texture),
event2Texture: api.nullable.getExn(event2Texture),
}, [rect.width, rect.height])
}

Expand All @@ -104,10 +94,10 @@ export let getContribute: getContributeMeta3D<uiControlContribute<inputFunc, spe
},
init: (meta3dState) => {
meta3dState = api.uiControl.setUIControlState<state>(meta3dState, uiControlName, {
runTexture: null,
stopTexture: null,
lastRunTextureImageBase64: null,
lastStopTextureImageBase64: null,
event1Texture: null,
event2Texture: null,
lastEvent1TextureImageBase64: null,
lastEvent2TextureImageBase64: null,
})

return Promise.resolve(meta3dState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type supportedEventName = [
| #button_click
| #run
| #stop
| #event1
| #event2
]

type actionName = Js.Nullable.t<string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type rect = {

export type childrenFunc = (state: state) => state

export type supportedEventName = "button_click" | "run" | "stop"
export type supportedEventName = "button_click" | "run" | "stop" | "event1" | "event2"

export type actionName = nullable<string>

Expand Down
Loading

0 comments on commit e0805d0

Please sign in to comment.