pixi-rainman-game-engine 0.0.3 → 0.0.5

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.
Files changed (38) hide show
  1. package/LICENSE +1 -0
  2. package/README.md +7 -2
  3. package/dist/Rainman/Rainman.d.ts +7 -0
  4. package/dist/Rainman/Rainman.js +8 -0
  5. package/dist/Rainman/index.d.ts +2 -0
  6. package/dist/Rainman/index.js +2 -0
  7. package/dist/Rainman/types.d.ts +6 -0
  8. package/dist/buttons/BaseButton/BaseButton.d.ts +3 -3
  9. package/dist/buttons/BaseButton/BaseButton.js +20 -20
  10. package/dist/buttons/BaseButton/ButtonState.d.ts +8 -8
  11. package/dist/buttons/BaseButton/ButtonState.js +8 -9
  12. package/dist/buttons/BaseButton/index.d.ts +2 -0
  13. package/dist/buttons/BaseButton/index.js +2 -0
  14. package/dist/buttons/BaseButton/types.d.ts +1 -1
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.js +1 -0
  17. package/dist/utils/common/deviceOrientation.js +1 -1
  18. package/dist/utils/common/functions.d.ts +10 -4
  19. package/dist/utils/common/functions.js +55 -39
  20. package/dist/utils/common/index.d.ts +2 -0
  21. package/dist/utils/common/index.js +2 -0
  22. package/dist/utils/common/placementHelpers.d.ts +5 -0
  23. package/dist/utils/common/placementHelpers.js +37 -0
  24. package/dist/utils/common/screenHelpers.d.ts +5 -0
  25. package/dist/utils/common/screenHelpers.js +60 -0
  26. package/dist/utils/common/stats.d.ts +3 -0
  27. package/dist/utils/common/stats.js +16 -0
  28. package/dist/utils/common/uiItems.d.ts +9 -0
  29. package/dist/utils/common/uiItems.js +9 -0
  30. package/dist/utils/index.d.ts +0 -1
  31. package/dist/utils/index.js +0 -1
  32. package/package.json +15 -5
  33. package/dist/utils/application/application.d.ts +0 -3
  34. package/dist/utils/application/application.js +0 -2
  35. package/dist/utils/application/index.d.ts +0 -2
  36. package/dist/utils/application/index.js +0 -2
  37. package/dist/utils/application/types.d.ts +0 -2
  38. /package/dist/{utils/application → Rainman}/types.js +0 -0
package/LICENSE ADDED
@@ -0,0 +1 @@
1
+ ISC
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Rainman pixi game engine
1
+ # RainMan pixi game engine
2
2
 
3
- This repository contains all of the mechanics that used in rainman games.
3
+ This repository contains all of the mechanics that used in rainMan games. This library uses pixi and pixi-spine as dependencies.
4
4
 
5
5
  ### Scripts
6
6
 
@@ -18,3 +18,8 @@ This repository contains all of the mechanics that used in rainman games.
18
18
  Code for the game engine contains in the `src` directory. For create an feature you should add new directory into `src` directory. For example: `freeSpins` and in this folder contains all of the mechanics.
19
19
 
20
20
  In utils directory there all of the utility functions and types.
21
+
22
+ ### Test environment
23
+
24
+ To simulate behavior of game engine mechanics, this repository contains react-pixi app, where you can test features that are included in game engine.
25
+ Test environment uses local built of game engine. To setup test environment go to [README](./src/test-environment/README.md) of test environment.
@@ -0,0 +1,7 @@
1
+ import { Application } from "pixi.js";
2
+ import { AppConfig } from "./types";
3
+ export declare class Rainman {
4
+ static app: Application;
5
+ static config: AppConfig;
6
+ constructor(app: Application, config: AppConfig);
7
+ }
@@ -0,0 +1,8 @@
1
+ export class Rainman {
2
+ static app;
3
+ static config;
4
+ constructor(app, config) {
5
+ Rainman.app = app;
6
+ Rainman.config = config;
7
+ }
8
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./Rainman";
2
+ export * from "./types";
@@ -0,0 +1,2 @@
1
+ export * from "./Rainman";
2
+ export * from "./types";
@@ -0,0 +1,6 @@
1
+ export type AppConfig = {
2
+ gameWidth: number;
3
+ gameHeight: number;
4
+ numberOfColumns: number;
5
+ numberOfRows: number;
6
+ };
@@ -18,14 +18,14 @@ export declare class BaseButton extends Sprite {
18
18
  private isDisabled;
19
19
  private _onClick;
20
20
  private _customClickHandler;
21
- constructor(name: string, texture: Texture, stateful?: boolean);
21
+ constructor(name: string, textureMap: TextureMap, stateful?: boolean);
22
22
  get active(): boolean;
23
23
  forceTextureUpdate(): void;
24
24
  setOnClick(callback: () => void): void;
25
25
  activate(flag: boolean): void;
26
26
  flipDisabledFlag(makeDisabled: boolean): void;
27
- protected switchTexture(state: ButtonStates): void;
28
- protected setTextureForState(state: ButtonStates, texture: Texture): void;
27
+ protected switchTexture(state: keyof typeof ButtonStates): void;
28
+ protected setTextureForState(state: keyof typeof ButtonStates, texture: Texture): void;
29
29
  get disabled(): boolean;
30
30
  get onClick(): typeof this._onClick;
31
31
  private _manageStateUp;
@@ -1,6 +1,5 @@
1
1
  import { Sprite } from "pixi.js";
2
2
  import { TINT_DISABLED, TINT_ENABLED } from "../../constants";
3
- import { ButtonStates } from "./ButtonState";
4
3
  /**
5
4
  * Class for basic button with states and textures
6
5
  *
@@ -11,7 +10,7 @@ import { ButtonStates } from "./ButtonState";
11
10
  */
12
11
  export class BaseButton extends Sprite {
13
12
  static registryName;
14
- textures = new Map();
13
+ textures = {};
15
14
  stateful = false;
16
15
  isActive = false;
17
16
  isOver = false;
@@ -27,13 +26,14 @@ export class BaseButton extends Sprite {
27
26
  this._manageStateOver();
28
27
  };
29
28
  _customClickHandler = () => { };
30
- constructor(name, texture, stateful = false) {
31
- super(texture);
29
+ constructor(name, textureMap, stateful = false) {
30
+ super(textureMap["NORMAL"]);
32
31
  this.stateful = stateful;
33
32
  this.x = 0;
34
33
  this.y = 0;
35
34
  this.name = name;
36
- this.interactive = true;
35
+ this.textures = textureMap;
36
+ this.eventMode = "dynamic";
37
37
  this.isActive = false;
38
38
  }
39
39
  get active() {
@@ -42,10 +42,10 @@ export class BaseButton extends Sprite {
42
42
  forceTextureUpdate() {
43
43
  this.isOver = false;
44
44
  if (this.isActive) {
45
- this.switchTexture(ButtonStates.ACTIVE);
45
+ this.switchTexture("ACTIVE");
46
46
  }
47
47
  if (!this.isActive) {
48
- this.switchTexture(ButtonStates.NORMAL);
48
+ this.switchTexture("NORMAL");
49
49
  }
50
50
  }
51
51
  setOnClick(callback) {
@@ -73,12 +73,12 @@ export class BaseButton extends Sprite {
73
73
  this.tint = makeDisabled ? TINT_DISABLED : TINT_ENABLED;
74
74
  }
75
75
  switchTexture(state) {
76
- if (this.textures.has(state)) {
77
- this.texture = this.textures.get(state);
76
+ if (this.textures[state]) {
77
+ this.texture = this.textures[state];
78
78
  }
79
79
  }
80
80
  setTextureForState(state, texture) {
81
- this.textures.set(state, texture);
81
+ this.textures[state] = texture;
82
82
  }
83
83
  get disabled() {
84
84
  return this.isDisabled;
@@ -89,43 +89,43 @@ export class BaseButton extends Sprite {
89
89
  _manageStateUp() {
90
90
  if (this.isActive) {
91
91
  if (this.isOver) {
92
- this.switchTexture(ButtonStates.ACTIVE_OVER);
92
+ this.switchTexture("ACTIVE_OVER");
93
93
  }
94
94
  else {
95
- this.switchTexture(ButtonStates.ACTIVE);
95
+ this.switchTexture("ACTIVE");
96
96
  }
97
97
  }
98
98
  if (!this.isActive) {
99
- this.switchTexture(ButtonStates.NORMAL);
99
+ this.switchTexture("NORMAL");
100
100
  }
101
101
  if (this.isOver) {
102
- this.switchTexture(ButtonStates.OVER);
102
+ this.switchTexture("OVER");
103
103
  }
104
104
  }
105
105
  _manageStateOver() {
106
106
  this.isOver = true;
107
107
  if (this.isActive) {
108
- this.switchTexture(ButtonStates.ACTIVE_OVER);
108
+ this.switchTexture("ACTIVE_OVER");
109
109
  }
110
110
  else {
111
- this.switchTexture(ButtonStates.OVER);
111
+ this.switchTexture("OVER");
112
112
  }
113
113
  }
114
114
  _manageStateDown() {
115
115
  if (this.isActive) {
116
- this.switchTexture(ButtonStates.ACTIVE_CLICKED);
116
+ this.switchTexture("ACTIVE_CLICKED");
117
117
  }
118
118
  else {
119
- this.switchTexture(ButtonStates.CLICKED);
119
+ this.switchTexture("CLICKED");
120
120
  }
121
121
  }
122
122
  _manageStateOut() {
123
123
  this.isOver = false;
124
124
  if (this.isActive) {
125
- this.switchTexture(ButtonStates.ACTIVE);
125
+ this.switchTexture("ACTIVE");
126
126
  }
127
127
  else {
128
- this.switchTexture(ButtonStates.NORMAL);
128
+ this.switchTexture("NORMAL");
129
129
  }
130
130
  }
131
131
  }
@@ -1,8 +1,8 @@
1
- export declare enum ButtonStates {
2
- NORMAL = "normal",
3
- OVER = "over",
4
- CLICKED = "clicked",
5
- ACTIVE = "active",
6
- ACTIVE_OVER = "activeOver",
7
- ACTIVE_CLICKED = "activeClicked"
8
- }
1
+ export declare const ButtonStates: {
2
+ readonly NORMAL: "normal";
3
+ readonly OVER: "over";
4
+ readonly CLICKED: "clicked";
5
+ readonly ACTIVE: "active";
6
+ readonly ACTIVE_OVER: "activeOver";
7
+ readonly ACTIVE_CLICKED: "activeClicked";
8
+ };
@@ -1,9 +1,8 @@
1
- export var ButtonStates;
2
- (function (ButtonStates) {
3
- ButtonStates["NORMAL"] = "normal";
4
- ButtonStates["OVER"] = "over";
5
- ButtonStates["CLICKED"] = "clicked";
6
- ButtonStates["ACTIVE"] = "active";
7
- ButtonStates["ACTIVE_OVER"] = "activeOver";
8
- ButtonStates["ACTIVE_CLICKED"] = "activeClicked";
9
- })(ButtonStates || (ButtonStates = {}));
1
+ export const ButtonStates = {
2
+ NORMAL: "normal",
3
+ OVER: "over",
4
+ CLICKED: "clicked",
5
+ ACTIVE: "active",
6
+ ACTIVE_OVER: "activeOver",
7
+ ACTIVE_CLICKED: "activeClicked"
8
+ };
@@ -1 +1,3 @@
1
1
  export * from "./BaseButton";
2
+ export * from "./ButtonState";
3
+ export * from "./types";
@@ -1 +1,3 @@
1
1
  export * from "./BaseButton";
2
+ export * from "./ButtonState";
3
+ export * from "./types";
@@ -1,3 +1,3 @@
1
1
  import { Texture } from "pixi.js";
2
2
  import { ButtonStates } from "./ButtonState";
3
- export type TextureMap = Map<ButtonStates, Texture>;
3
+ export type TextureMap = Record<keyof typeof ButtonStates, Texture>;
package/dist/index.d.ts CHANGED
@@ -2,4 +2,5 @@ export * from "./buttons";
2
2
  export * from "./constants";
3
3
  export * from "./freeSpins";
4
4
  export * from "./loading";
5
+ export * from "./Rainman";
5
6
  export * from "./utils";
package/dist/index.js CHANGED
@@ -2,4 +2,5 @@ export * from "./buttons";
2
2
  export * from "./constants";
3
3
  export * from "./freeSpins";
4
4
  export * from "./loading";
5
+ export * from "./Rainman";
5
6
  export * from "./utils";
@@ -1,4 +1,4 @@
1
- import { getScreenRatio, isMobile } from "./functions";
1
+ import { getScreenRatio, isMobile } from "./screenHelpers";
2
2
  export const getDeviceOrientation = () => {
3
3
  if (isMobile()) {
4
4
  if (window.matchMedia("(orientation: portrait)").matches) {
@@ -1,4 +1,10 @@
1
- export declare const checkMobileBrowser: () => boolean;
2
- export declare const getScreenRatio: () => number;
3
- export declare const isMobile: () => boolean;
4
- export declare const setupFullscreenForIOS: () => void;
1
+ import { Spine } from "pixi-spine";
2
+ export declare const ceilToDecimal: (value: number, decimalPlaces?: number) => number;
3
+ export declare const wait: (ms: number) => Promise<void>;
4
+ export declare const range: (start: number, stop: number, step: number) => number[];
5
+ export declare const randomArrayElement: <T>(items: T[]) => T;
6
+ export declare const getRandomInt: (min: number, max: number) => number;
7
+ export declare const hideLayerIfPresent: (elementsToSkip?: string[]) => boolean;
8
+ export declare const hidePaytable: () => void;
9
+ export declare const togglePaytable: () => void;
10
+ export declare const waitForAnimationToEnd: (spine: Spine, animationName: string, loopAnimationName?: string) => Promise<void>;
@@ -1,43 +1,59 @@
1
- import { getDeviceOrientation } from "./deviceOrientation";
2
- export const checkMobileBrowser = () => /^((?!chrome|android).)*safari/i.test(navigator.userAgent || navigator.vendor);
3
- export const getScreenRatio = () => window.innerWidth / window.innerHeight;
4
- export const isMobile = () => {
5
- let check = false;
6
- (function (a) {
7
- if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) ||
8
- /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4)))
9
- check = true;
10
- })(navigator.userAgent || navigator.vendor);
11
- return check;
12
- };
13
- export const setupFullscreenForIOS = () => {
14
- if (!isMobile() || !checkMobileBrowser())
1
+ import { allUiItems, UI_ITEMS } from "./uiItems";
2
+ export const ceilToDecimal = (value, decimalPlaces = 2) => {
3
+ return Number(value.toFixed(decimalPlaces));
4
+ };
5
+ export const wait = (ms) => {
6
+ return new Promise((resolve) => setTimeout(resolve, ms));
7
+ };
8
+ export const range = (start, stop, step) => {
9
+ const result = [];
10
+ for (let i = start; i <= stop; i = ceilToDecimal(i + step)) {
11
+ result.push(i);
12
+ }
13
+ return result;
14
+ };
15
+ export const randomArrayElement = (items) => {
16
+ return items[Math.floor(Math.random() * items.length)];
17
+ };
18
+ export const getRandomInt = (min, max) => {
19
+ return Number((Math.random() * (max - min) + min).toFixed(0));
20
+ };
21
+ export const hideLayerIfPresent = (elementsToSkip = []) => {
22
+ let anyHidden = false;
23
+ allUiItems.forEach((elementId) => {
24
+ if (elementsToSkip.includes(elementId))
25
+ return;
26
+ const element = window.document.getElementById(elementId);
27
+ if (element === null)
28
+ return;
29
+ if (element.style.display !== "none")
30
+ anyHidden = true;
31
+ element.style.display = "none";
32
+ });
33
+ return anyHidden;
34
+ };
35
+ export const hidePaytable = () => {
36
+ const paytableLayer = window.document.getElementById(UI_ITEMS.symbolPaytable);
37
+ if (paytableLayer === null)
15
38
  return;
16
- document.body.style.overflow = "auto";
17
- const scrollingElement = document.scrollingElement;
18
- if (!scrollingElement)
39
+ paytableLayer.style.display = "none";
40
+ };
41
+ export const togglePaytable = () => {
42
+ const paytableLayer = window.document.getElementById(UI_ITEMS.symbolPaytable);
43
+ if (paytableLayer === null)
19
44
  return;
20
- scrollingElement.scrollTo(0, 0);
21
- let lastOrientation = getDeviceOrientation();
22
- const scrollOverlay = document.createElement("div");
23
- scrollOverlay.setAttribute("class", "ios-scroller");
24
- document.body.appendChild(scrollOverlay);
25
- const scrollOverlayAnimation = document.createElement("div");
26
- scrollOverlayAnimation.setAttribute("class", "ios-scroller-animation");
27
- document.body.appendChild(scrollOverlayAnimation);
28
- let lastHeight = window.innerHeight;
29
- addEventListener("resize", () => {
30
- const currentOrientation = getDeviceOrientation();
31
- const changedToLandScape = lastOrientation === "mobile-portrait" && currentOrientation === "mobile-landscape";
32
- const changedToPortrait = lastOrientation === "mobile-landscape" && currentOrientation === "mobile-portrait";
33
- if ((window.innerHeight < lastHeight && !changedToLandScape) || changedToPortrait) {
34
- scrollingElement.scrollTo(0, 0);
35
- document.documentElement.classList.remove("is-locked");
36
- }
37
- else {
38
- document.documentElement.classList.add("is-locked");
39
- }
40
- lastHeight = window.innerHeight;
41
- lastOrientation = currentOrientation;
45
+ paytableLayer.style.display = paytableLayer.style.display === "flex" ? "none" : "flex";
46
+ };
47
+ export const waitForAnimationToEnd = async (spine, animationName, loopAnimationName) => {
48
+ spine.state.clearListeners();
49
+ await new Promise((resolve) => {
50
+ spine.state.setAnimation(0, animationName, false);
51
+ spine.state.addListener({
52
+ complete: () => {
53
+ if (loopAnimationName)
54
+ spine.state.setAnimation(0, loopAnimationName, true);
55
+ resolve();
56
+ }
57
+ });
42
58
  });
43
59
  };
@@ -1,3 +1,5 @@
1
1
  export * from "./deviceOrientation";
2
2
  export * from "./functions";
3
+ export * from "./screenHelpers";
3
4
  export * from "./types";
5
+ export * from "./uiItems";
@@ -1,3 +1,5 @@
1
1
  export * from "./deviceOrientation";
2
2
  export * from "./functions";
3
+ export * from "./screenHelpers";
3
4
  export * from "./types";
5
+ export * from "./uiItems";
@@ -0,0 +1,5 @@
1
+ import { Rect } from "adaptive-scale/lib";
2
+ import { Container, DisplayObject } from "pixi.js";
3
+ export declare const scaleToParent: (width: number, height: number, parentWidth: number, parentHeight: number) => Rect;
4
+ export declare const globalMinRatio: () => number;
5
+ export declare const setChildIndexWithAscendingOrder: (parentContainer: Container, childrenComponents: DisplayObject[]) => void;
@@ -0,0 +1,37 @@
1
+ import { getScaledRect, POLICY, Size } from "adaptive-scale/lib";
2
+ import { Rainman } from "../../Rainman";
3
+ import { getScreenRatio } from "./screenHelpers";
4
+ export const scaleToParent = (width, height, parentWidth, parentHeight) => {
5
+ return getScaledRect({
6
+ // window, canvas or any other thing
7
+ container: new Size(parentWidth, parentHeight),
8
+ // some dependent size. image, figure etc.
9
+ target: new Size(width, height),
10
+ // policy is optional. default is null
11
+ policy: POLICY.ShowAll // null | ExactFit | NoBorder | FullHeight | FullWidth | ShowAll
12
+ });
13
+ };
14
+ const valueForMobile = () => {
15
+ const globalXRatio = Rainman.app.screen.width / Rainman.config.gameWidth;
16
+ const globalYRatio = Rainman.app.screen.height / Rainman.config.gameHeight;
17
+ if (globalXRatio < globalYRatio) {
18
+ return globalXRatio * 2;
19
+ }
20
+ return globalYRatio * 2;
21
+ };
22
+ export const globalMinRatio = () => {
23
+ if (getScreenRatio() < 1) {
24
+ return valueForMobile();
25
+ }
26
+ const globalXRatio = Rainman.app.screen.width / Rainman.config.gameWidth;
27
+ const globalYRatio = Rainman.app.screen.height / Rainman.config.gameHeight;
28
+ if (globalXRatio < globalYRatio) {
29
+ return globalXRatio;
30
+ }
31
+ return globalYRatio;
32
+ };
33
+ export const setChildIndexWithAscendingOrder = (parentContainer, childrenComponents) => {
34
+ childrenComponents.forEach((container, index) => {
35
+ parentContainer.setChildIndex(container, index);
36
+ });
37
+ };
@@ -0,0 +1,5 @@
1
+ export declare const checkMobileBrowser: () => boolean;
2
+ export declare const getScreenRatio: () => number;
3
+ export declare const isMobile: () => boolean;
4
+ export declare const openFullscreen: () => void;
5
+ export declare const setupFullscreenForIOS: () => void;
@@ -0,0 +1,60 @@
1
+ import { getDeviceOrientation } from "./deviceOrientation";
2
+ export const checkMobileBrowser = () => /^((?!chrome|android).)*safari/i.test(navigator.userAgent || navigator.vendor);
3
+ export const getScreenRatio = () => window.innerWidth / window.innerHeight;
4
+ export const isMobile = () => {
5
+ let check = false;
6
+ (function (a) {
7
+ if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) ||
8
+ /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4)))
9
+ check = true;
10
+ })(navigator.userAgent || navigator.vendor);
11
+ return check;
12
+ };
13
+ export const openFullscreen = () => {
14
+ if (!isMobile())
15
+ return;
16
+ try {
17
+ const doc = document.documentElement;
18
+ if (typeof doc.requestFullscreen === "function") {
19
+ doc.requestFullscreen();
20
+ }
21
+ else if (typeof doc.webkitRequestFullscreen === "function") {
22
+ doc.webkitRequestFullscreen();
23
+ }
24
+ else if (typeof doc.msRequestFullscreen === "function") {
25
+ doc.msRequestFullscreen();
26
+ }
27
+ }
28
+ catch (ignore) { }
29
+ };
30
+ export const setupFullscreenForIOS = () => {
31
+ if (!isMobile() || !checkMobileBrowser())
32
+ return;
33
+ document.body.style.overflow = "auto";
34
+ const scrollingElement = document.scrollingElement;
35
+ if (!scrollingElement)
36
+ return;
37
+ scrollingElement.scrollTo(0, 0);
38
+ let lastOrientation = getDeviceOrientation();
39
+ const scrollOverlay = document.createElement("div");
40
+ scrollOverlay.setAttribute("class", "ios-scroller");
41
+ document.body.appendChild(scrollOverlay);
42
+ const scrollOverlayAnimation = document.createElement("div");
43
+ scrollOverlayAnimation.setAttribute("class", "ios-scroller-animation");
44
+ document.body.appendChild(scrollOverlayAnimation);
45
+ let lastHeight = window.innerHeight;
46
+ addEventListener("resize", () => {
47
+ const currentOrientation = getDeviceOrientation();
48
+ const changedToLandScape = lastOrientation === "mobile-portrait" && currentOrientation === "mobile-landscape";
49
+ const changedToPortrait = lastOrientation === "mobile-landscape" && currentOrientation === "mobile-portrait";
50
+ if ((window.innerHeight < lastHeight && !changedToLandScape) || changedToPortrait) {
51
+ scrollingElement.scrollTo(0, 0);
52
+ document.documentElement.classList.remove("is-locked");
53
+ }
54
+ else {
55
+ document.documentElement.classList.add("is-locked");
56
+ }
57
+ lastHeight = window.innerHeight;
58
+ lastOrientation = currentOrientation;
59
+ });
60
+ };
@@ -0,0 +1,3 @@
1
+ import Stats from "stats.js";
2
+ export declare const getStatsInstance: () => Stats;
3
+ export declare const invokeStatsBoard: () => void;
@@ -0,0 +1,16 @@
1
+ import { Ticker } from "pixi.js";
2
+ import Stats from "stats.js";
3
+ const stats = new Stats();
4
+ export const getStatsInstance = () => stats;
5
+ export const invokeStatsBoard = () => {
6
+ const stats = getStatsInstance();
7
+ stats.showPanel(0);
8
+ stats.dom.style.position = "absolute";
9
+ Ticker.shared.add(() => collectStats());
10
+ document.body.appendChild(stats.dom);
11
+ };
12
+ const collectStats = () => {
13
+ const stats = getStatsInstance();
14
+ stats.begin();
15
+ stats.end();
16
+ };
@@ -0,0 +1,9 @@
1
+ export declare const UI_ITEMS: {
2
+ readonly settings: "dom-layer";
3
+ readonly volume: "volume-layer";
4
+ readonly gamerules: "game-rules-layer";
5
+ readonly autoplay: "autoplay-settings-layer";
6
+ readonly speedSettings: "speed-settings-layer";
7
+ readonly symbolPaytable: "symbol-paytable-layer";
8
+ };
9
+ export declare const allUiItems: ("dom-layer" | "volume-layer" | "game-rules-layer" | "autoplay-settings-layer" | "speed-settings-layer" | "symbol-paytable-layer")[];
@@ -0,0 +1,9 @@
1
+ export const UI_ITEMS = {
2
+ settings: "dom-layer",
3
+ volume: "volume-layer",
4
+ gamerules: "game-rules-layer",
5
+ autoplay: "autoplay-settings-layer",
6
+ speedSettings: "speed-settings-layer",
7
+ symbolPaytable: "symbol-paytable-layer"
8
+ };
9
+ export const allUiItems = Object.values(UI_ITEMS);
@@ -1,3 +1,2 @@
1
- export * from "./application";
2
1
  export * from "./assets";
3
2
  export * from "./common";
@@ -1,3 +1,2 @@
1
- export * from "./application";
2
1
  export * from "./assets";
3
2
  export * from "./common";
package/package.json CHANGED
@@ -1,23 +1,31 @@
1
1
  {
2
2
  "name": "pixi-rainman-game-engine",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "This repository contains all of the mechanics that used in rainman games.",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
7
8
  "scripts": {
8
9
  "build": "rm -rf dist && tsc",
10
+ "dev:build": "tsc-watch",
11
+ "dev:link": "npm link && cd test-environment && npm link pixi-rainman-game-engine",
12
+ "dev:server": "cd test-environment && yarn dev",
9
13
  "lint": "eslint src/** --fix",
10
- "prepare": "husky && yarn build"
14
+ "prepublishOnly": "husky && yarn build",
15
+ "prepare": "husky"
11
16
  },
12
17
  "type": "module",
13
18
  "author": "@niceguys",
14
19
  "license": "ISC",
15
20
  "dependencies": {
21
+ "adaptive-scale": "^1.0.0",
16
22
  "pixi-spine": "^4.0.4",
17
- "pixi.js": "^7.4.0"
23
+ "pixi.js": "^7.4.0",
24
+ "stats.js": "^0.17.0"
18
25
  },
19
26
  "devDependencies": {
20
27
  "@types/node": "^20.11.19",
28
+ "@types/stats.js": "^0.17.3",
21
29
  "@typescript-eslint/eslint-plugin": "^7.0.2",
22
30
  "@typescript-eslint/parser": "^7.0.2",
23
31
  "eslint": "^8.57.0",
@@ -30,6 +38,7 @@
30
38
  "prettier": "^3.2.5",
31
39
  "pretty-quick": "^4.0.0",
32
40
  "tsc": "^2.0.4",
41
+ "tsc-watch": "^6.0.4",
33
42
  "typescript": "^5.3.3"
34
43
  },
35
44
  "bugs": {
@@ -42,6 +51,7 @@
42
51
  },
43
52
  "files": [
44
53
  "dist",
54
+ "LICENSE",
45
55
  "README.md"
46
56
  ],
47
57
  "keywords": [
@@ -1,3 +0,0 @@
1
- import { Application } from "pixi.js";
2
- import { ApplicationOptions } from "./types";
3
- export declare const createApplication: (options: ApplicationOptions) => Application<import("pixi.js").ICanvas>;
@@ -1,2 +0,0 @@
1
- import { Application } from "pixi.js";
2
- export const createApplication = (options) => new Application({ ...options, width: window.innerWidth, height: window.innerHeight });
@@ -1,2 +0,0 @@
1
- export * from "./application";
2
- export * from "./types";
@@ -1,2 +0,0 @@
1
- export * from "./application";
2
- export * from "./types";
@@ -1,2 +0,0 @@
1
- import { IApplicationOptions as PixiApplicationOptions } from "pixi.js";
2
- export type ApplicationOptions = Partial<PixiApplicationOptions>;
File without changes