@vnejs/plugins.view.coralina.mainmenu 0.1.7 → 0.1.8

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 CHANGED
@@ -1,5 +1,8 @@
1
1
  export const BACKGROUND = "Menu/loading";
2
2
 
3
+ export const BACKGROUNDS = [];
4
+ export const BACKGROUNDS_INTERVAL = 0;
5
+
3
6
  export const TRANSITION = 500;
4
7
  export const ZINDEX = 3000;
5
8
  export const LOC_LABEL = "mainMenu";
@@ -3,6 +3,8 @@ import { ModuleController } from "@vnejs/module.components";
3
3
  const toStateItem = ({ onClick, ...item }) => item;
4
4
  const onRealItems = (item) => !item.isDisabled && !item.isHide;
5
5
 
6
+ const getRandomInt = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
7
+
6
8
  export class MainMenuController extends ModuleController {
7
9
  name = "mainmenu.controller";
8
10
 
@@ -10,6 +12,9 @@ export class MainMenuController extends ModuleController {
10
12
 
11
13
  bgName = this.PARAMS.MAINMENU_VIEW.BACKGROUND;
12
14
 
15
+ bgInterval = null;
16
+ bgIndex = 0;
17
+
13
18
  updateEvent = this.EVENTS.MAINMENU_VIEW.UPDATE;
14
19
  controls = {
15
20
  [this.CONST.CONTROLS.BUTTONS.ARROW_UP]: this.decCurrentItem,
@@ -34,7 +39,7 @@ export class MainMenuController extends ModuleController {
34
39
 
35
40
  this.on(this.EVENTS.SYSTEM.STARTED, this.loadBgMedia);
36
41
 
37
- this.on(this.EVENTS.MEMORY.CLEARED, this.onMemoryCleared);
42
+ this.on(this.EVENTS.MEMORY.CLEARED, this.updateBg);
38
43
  };
39
44
 
40
45
  beforeShow = async () => {
@@ -44,11 +49,35 @@ export class MainMenuController extends ModuleController {
44
49
 
45
50
  this.maxCurrentItem = this.state.realItems.length - 1;
46
51
  };
52
+ afterShow = () => {
53
+ if (this.PARAMS.MAINMENU_VIEW.BACKGROUNDS.length && this.PARAMS.MAINMENU_VIEW.BACKGROUNDS_INTERVAL)
54
+ this.bgInterval = setInterval(this.intervalTickFunc, this.PARAMS.MAINMENU_VIEW.BACKGROUNDS_INTERVAL);
55
+ };
56
+ afterHide = () => {
57
+ this.setDefaultState();
58
+
59
+ clearInterval(this.bgInterval);
60
+ };
47
61
 
48
62
  onAccept = async () => this.click((await this.emitOne(this.EVENTS.MAINMENU.ITEMS)).filter(onRealItems), this.currentItem);
49
63
  onClick = async ({ index } = {}) => this.click(await this.emitOne(this.EVENTS.MAINMENU.ITEMS), index);
50
64
 
51
- onMemoryCleared = async () => this.updateStateAndView({ bgSrc: (await this.loadBgMedia()).src });
65
+ updateBg = async () => this.updateStateAndView({ bgSrc: (await this.loadBgMedia()).src });
66
+
67
+ intervalTickFunc = () => {
68
+ while (true) {
69
+ const newIndex = getRandomInt(0, this.PARAMS.MAINMENU_VIEW.BACKGROUNDS.length - 1);
70
+
71
+ if (newIndex === this.bgIndex) continue;
72
+
73
+ this.bgIndex = newIndex;
74
+ break;
75
+ }
76
+
77
+ this.bgName = this.PARAMS.MAINMENU_VIEW.BACKGROUNDS[this.bgIndex];
78
+
79
+ return this.updateBg();
80
+ };
52
81
 
53
82
  click = (items, index) => index !== null && items[index]?.onClick?.();
54
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.view.coralina.mainmenu",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",