@vnejs/plugins.view.coralina.point-and-click 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/const/params.js +2 -0
- package/index.js +3 -1
- package/modules/controller.js +1 -3
- package/modules/view.js +3 -3
- package/package.json +1 -1
- package/view/index.jsx +30 -31
package/const/params.js
ADDED
package/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { regPlugin } from "@vnejs/shared";
|
|
2
2
|
|
|
3
|
+
import * as params from "./const/params";
|
|
4
|
+
|
|
3
5
|
import { PointAndClickController } from "./modules/controller";
|
|
4
6
|
import { PointAndClickView } from "./modules/view";
|
|
5
7
|
|
|
6
|
-
regPlugin("POINT_AND_CLICK_VIEW", {}, [PointAndClickController, PointAndClickView]);
|
|
8
|
+
regPlugin("POINT_AND_CLICK_VIEW", { params }, [PointAndClickController, PointAndClickView]);
|
package/modules/controller.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { ModuleController } from "@vnejs/module.components";
|
|
2
2
|
|
|
3
|
-
import { ZINDEX } from "../view";
|
|
4
|
-
|
|
5
3
|
export class PointAndClickController extends ModuleController {
|
|
6
4
|
name = "point-and-click.controller";
|
|
7
5
|
|
|
@@ -15,7 +13,7 @@ export class PointAndClickController extends ModuleController {
|
|
|
15
13
|
[this.CONST.CONTROLS.BUTTONS.GAMEMENU]: this.emitGameMenu,
|
|
16
14
|
[this.CONST.CONTROLS.BUTTONS.ARROW_LEFT]: () => this.emit(this.EVENTS.INTERFACE.HISTORY_BACK),
|
|
17
15
|
};
|
|
18
|
-
controlsIndex = ZINDEX;
|
|
16
|
+
controlsIndex = this.PARAMS.POINT_AND_CLICK_VIEW.ZINDEX;
|
|
19
17
|
|
|
20
18
|
subscribe = () => {
|
|
21
19
|
this.on(this.EVENTS.POINT_AND_CLICK.SHOW, this.onShow);
|
package/modules/view.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ModuleView } from "@vnejs/module.components";
|
|
2
2
|
|
|
3
|
-
import { render
|
|
3
|
+
import { render } from "../view";
|
|
4
4
|
|
|
5
5
|
export class PointAndClickView extends ModuleView {
|
|
6
6
|
name = "point-and-click.view";
|
|
7
7
|
|
|
8
|
-
animationTime = TRANSITION;
|
|
8
|
+
animationTime = this.PARAMS.POINT_AND_CLICK_VIEW.TRANSITION;
|
|
9
9
|
updateEvent = this.EVENTS.POINT_AND_CLICK.UPDATE;
|
|
10
10
|
|
|
11
11
|
renderFunc = render;
|
|
12
|
-
updateHandler = this.
|
|
12
|
+
updateHandler = this.onUpdateStoreComponent;
|
|
13
13
|
}
|
package/package.json
CHANGED
package/view/index.jsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { createRoot } from "react-dom/client";
|
|
3
3
|
|
|
4
4
|
import { cn } from "@bem-react/classname";
|
|
5
5
|
|
|
@@ -9,15 +9,8 @@ import "./index.styl";
|
|
|
9
9
|
|
|
10
10
|
const b = cn("PointAndClick");
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class PointAndClick extends React.Component {
|
|
16
|
-
state = { isShow: false, isForce: false, options: [] };
|
|
17
|
-
|
|
18
|
-
onClick = (index) => this.props.emit(this.props.EVENTS.POINT_AND_CLICK.OPTION, { index });
|
|
19
|
-
|
|
20
|
-
renderOption = ({ disabled, hided, coords: [x, y], icon }, index) => (
|
|
12
|
+
const renderOptions = (options, currentItem, onClick) =>
|
|
13
|
+
options.map(({ disabled, hided, coords: [x, y], icon }, index) => (
|
|
21
14
|
<PositionBox
|
|
22
15
|
left={`${x}%`}
|
|
23
16
|
top={`${y}%`}
|
|
@@ -25,28 +18,34 @@ class PointAndClick extends React.Component {
|
|
|
25
18
|
translateY={"-50%"}
|
|
26
19
|
isNotRender={hided}
|
|
27
20
|
key={index}
|
|
28
|
-
onClick={disabled ? undefined :
|
|
21
|
+
onClick={disabled ? undefined : onClick}
|
|
29
22
|
value={index}
|
|
30
23
|
>
|
|
31
|
-
<div className={b("option", { icon, disabled, isCurrent: index ===
|
|
24
|
+
<div className={b("option", { icon, disabled, isCurrent: index === currentItem, coords: Boolean(x) && Boolean(y) })} />
|
|
32
25
|
</PositionBox>
|
|
26
|
+
));
|
|
27
|
+
|
|
28
|
+
export const PointAndClick = ({ store, onMount, ...props } = {}) => {
|
|
29
|
+
const [{ isShow = false, isForce = false, options = [], currentItem = null }, setState] = useState({});
|
|
30
|
+
|
|
31
|
+
useEffect(() => store.subscribe(setState), []);
|
|
32
|
+
useEffect(() => void onMount(), []);
|
|
33
|
+
|
|
34
|
+
const onClick = useCallback((index) => props.emit(props.EVENTS.POINT_AND_CLICK.OPTION, { index }), []);
|
|
35
|
+
|
|
36
|
+
const renderedOptions = useMemo(() => renderOptions(options, currentItem, onClick), [options, currentItem, onClick]);
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<Screen
|
|
40
|
+
isShow={isShow}
|
|
41
|
+
isForce={isForce}
|
|
42
|
+
isDisableAutoread={isShow}
|
|
43
|
+
zIndex={props.PARAMS.POINT_AND_CLICK_VIEW.ZINDEX}
|
|
44
|
+
transition={props.PARAMS.POINT_AND_CLICK_VIEW.TRANSITION}
|
|
45
|
+
>
|
|
46
|
+
{renderedOptions}
|
|
47
|
+
</Screen>
|
|
33
48
|
);
|
|
49
|
+
};
|
|
34
50
|
|
|
35
|
-
|
|
36
|
-
const { isShow = false, isForce = false, options = [] } = this.state;
|
|
37
|
-
|
|
38
|
-
return (
|
|
39
|
-
<Screen
|
|
40
|
-
isShow={isShow}
|
|
41
|
-
isForce={isForce}
|
|
42
|
-
zIndex={ZINDEX}
|
|
43
|
-
transition={TRANSITION}
|
|
44
|
-
isDisableAutoread={isShow}
|
|
45
|
-
>
|
|
46
|
-
{options.map(this.renderOption)}
|
|
47
|
-
</Screen>
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const render = (props, root, resolve) => ReactDOM.render(<PointAndClick {...props} />, root, resolve);
|
|
51
|
+
export const render = (props, root) => createRoot(root).render(<PointAndClick {...props} />);
|