@everymatrix/player-reality-check 0.0.192 → 0.0.196

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@everymatrix/player-reality-check",
3
- "version": "0.0.192",
3
+ "version": "0.0.196",
4
4
  "main": "dist/player-reality-check.js",
5
5
  "svelte": "src/index.ts",
6
6
  "scripts": {
@@ -36,5 +36,5 @@
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "90772f9f46872463853a444005e5adbfb07fc973"
39
+ "gitHead": "9809bd993cd1842fb5832ca5b3269eb33d0be029"
40
40
  }
@@ -5,34 +5,67 @@
5
5
  import { getDevice } from 'rvhelper';
6
6
 
7
7
  export let realitycheck:any = '';
8
+ export let endpoint:string = '';
9
+ export let playerid:string = '';
10
+ export let session:string = '';
8
11
 
9
12
  let userAgent:String = window.navigator.userAgent;
10
13
  let isMobile = (getDevice(userAgent) === 'PC') ? false : true;
11
14
  let frequency = '';
12
15
  let receivedData:any = {};
13
16
  let realityCheckData:any = {};
17
+ let isLoading:boolean = true;
14
18
 
15
19
  let realityCheckSuccess:boolean = false;
16
- let realityCheckSuccessMessage:string = 'Reality check ha been successfully updated.';
17
-
18
- let realityCheckOptions = [
19
- {value: '0', text: 'Never'},
20
- {value: '60', text: '1 Hour'},
21
- {value: '120', text: '2 Hours'},
22
- {value: '180', text: '3 Hours'},
23
- {value: '240', text: '4 Hours'}
24
- ]
25
-
26
- // Send Frequency period and date
27
- const submitFrequency = () => {
28
- window.postMessage({ type: 'SubmittedRealityCheck', realityCheckUpdatedValue: frequency }, window.location.href);
20
+ let realityCheckSuccessMessage:string = 'Reality check has been successfully updated.';
21
+ let realityCheckValues:Array<Object> = [];
22
+ let realityCheckOptions:Array<Object> = [];
23
+
24
+ // Get Reality Check Values From NW
25
+ const getRealityCheckValues = () => {
26
+ let url = new URL(`${endpoint}/player/${playerid}/availablerealityvalues`);
27
+
28
+ let options = {
29
+ method: "GET",
30
+ headers: {
31
+ 'playerId': playerid,
32
+ 'X-SessionId': session,
33
+ 'accept': 'application/json'
34
+ },
35
+ };
36
+
37
+ fetch(url, options)
38
+ .then((res:any) => res.json())
39
+ .then((data:any) => {
40
+
41
+ realityCheckValues = data.AvailableRealityCheckValues;
42
+
43
+ createRealityCheckOptions();
44
+ verifyFrequency();
45
+
46
+ isLoading = false;
47
+ }, (err:any) => {
48
+ console.error(err);
49
+ });
29
50
  }
30
51
 
31
- const toggleScreen = () => {
32
- window.postMessage({ type: 'ReturnToMenu' }, window.location.href);
52
+ // Create Reality Check Options Array
53
+ const createRealityCheckOptions = () => {
54
+ realityCheckValues.forEach((value) => {
55
+ if (value == 0) {
56
+ realityCheckOptions.push({'value': value.toString(), 'text': 'Never'});
57
+ } else if (value < 60) {
58
+ realityCheckOptions.push({'value': value.toString(), 'text': value + ' Minutes'});
59
+ } else if (value == 60) {
60
+ realityCheckOptions.push({'value': value.toString(), 'text': '1 Hour'});
61
+ } else if (value > 60) {
62
+ realityCheckOptions.push({'value': value.toString(), 'text': value / 60 + ' Hours'});
63
+ }
64
+ });
33
65
  }
34
66
 
35
- const initialLoad = () => {
67
+ // Verify if frequency exists
68
+ const verifyFrequency = () => {
36
69
  if(realitycheck) {
37
70
  frequency = realitycheck;
38
71
  } else {
@@ -40,6 +73,15 @@
40
73
  }
41
74
  }
42
75
 
76
+ // Send Frequency period and date
77
+ const submitFrequency = () => {
78
+ window.postMessage({ type: 'SubmittedRealityCheck', realityCheckUpdatedValue: frequency }, window.location.href);
79
+ }
80
+
81
+ const toggleScreen = () => {
82
+ window.postMessage({ type: 'ReturnToMenu' }, window.location.href);
83
+ }
84
+
43
85
  const messageHandler = (e:any) => {
44
86
  if (e.data) {
45
87
  switch(e.data.type) {
@@ -61,7 +103,7 @@
61
103
  }
62
104
  });
63
105
 
64
- $: realitycheck && initialLoad();
106
+ $: endpoint && playerid && session && getRealityCheckValues();
65
107
  </script>
66
108
 
67
109
 
@@ -86,14 +128,18 @@
86
128
  <div class="RealityCheckDescription {isMobile ? 'RealityCheckDescriptionMobile' : ''}">
87
129
  <p>The Reality Check facility allows you to set the frequency at which you will see a Reality Check on the screen within your gaming session. A Reality Check means a display of the time elapsed since your session began.<br><br>
88
130
  You are able to control the frequency at which the Reality Check will appear on your screen.</p>
89
- <form class="customRadio">
90
- {#each realityCheckOptions as {value, text}, idx}
91
- <div>
92
- <input type="radio" id="{value}" {value} bind:group={frequency} />
93
- <label for="{value}">{text}</label>
94
- </div>
95
- {/each}
96
- </form>
131
+ {#if isLoading}
132
+ <p>Loading items, please wait ...</p>
133
+ {:else}
134
+ <form class="customRadio">
135
+ {#each realityCheckOptions as {value, text}, idx}
136
+ <div>
137
+ <input type="radio" id="{value}" {value} bind:group={frequency} />
138
+ <label for="{value}">{text}</label>
139
+ </div>
140
+ {/each}
141
+ </form>
142
+ {/if}
97
143
  </div>
98
144
  <div class="BottomButtonsArea {isMobile ? 'BottomButtonsAreaMobile' : ''}">
99
145
  <button class="PlayerRealityCheckButton" on:click={() => submitFrequency()}>Set frequency</button>
@@ -109,6 +155,10 @@
109
155
  @return $value * $multiplicator;
110
156
  }
111
157
 
158
+ :host {
159
+ font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
160
+ }
161
+
112
162
  .successMessage {
113
163
  position: absolute;
114
164
  display: block;