@everymatrix/lottery-program-wof 1.11.0 → 1.12.0
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/dist/lottery-program-wof.js +8036 -4427
- package/dist/lottery-program-wof.js.map +1 -1
- package/package.json +2 -2
- package/src/LotteryProgramWof.svelte +13 -6
- package/src/business.dom.ts +0 -118
- package/src/business.ts +28 -18
- package/src/calc.point.ts +2 -139
- package/src/class.process.ts +64 -0
- package/src/class.spinner.ts +38 -6
- package/src/class.spinner.util.ts +1 -1
- package/src/class.svgcalc.ts +372 -0
- package/src/i18n.js +38 -0
- package/src/images/Thankyou_1.svg +100 -0
- package/src/images/Thankyou_2.svg +112 -0
- package/src/images/Thankyou_3.svg +87 -0
- package/src/images/Thankyou_4.svg +114 -0
- package/src/images/centerBackground1.svg +21 -0
- package/src/private.item.svelte +7 -20
- package/src/private.item.svg.svelte +133 -512
- package/src/private.loader.svelte +61 -0
- package/src/private.message.svelte +14 -15
- package/src/private.outcomes.svelte +8 -6
- package/src/private.tabs.svelte +2 -2
- package/src/themes.image.base.ts +69 -0
- package/src/themes.image.center.ts +141 -0
- package/src/themes.image.pointer.ts +51 -0
- package/src/themes.partitions.ts +19 -0
- package/src/themes.ts +7 -0
- package/src/translations.js +52 -0
- package/src/calc.image.ts +0 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@everymatrix/lottery-program-wof",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"main": "dist/lottery-program-wof.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": "
|
|
39
|
+
"gitHead": "5ba32db088ec6ebf8eb6110b6172d8c9409b9f70"
|
|
40
40
|
}
|
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
import './private.tabs.svelte'
|
|
6
6
|
import './private.outcomes.svelte'
|
|
7
7
|
import './private.item.svelte'
|
|
8
|
+
import './private.loader.svelte'
|
|
8
9
|
|
|
9
10
|
import { onMount } from 'svelte';
|
|
11
|
+
import { _, setLocale, setLocaleWhenInit } from './i18n';
|
|
10
12
|
|
|
11
13
|
// types
|
|
12
14
|
import { Lang } from './types';
|
|
@@ -22,8 +24,6 @@
|
|
|
22
24
|
export let endpoint: string = ''
|
|
23
25
|
export let session: string = ''
|
|
24
26
|
|
|
25
|
-
export let theme: string = '0'
|
|
26
|
-
|
|
27
27
|
export let spinduration: string = '3'
|
|
28
28
|
export let spinrotation: string = '3'
|
|
29
29
|
|
|
@@ -34,6 +34,8 @@
|
|
|
34
34
|
return () => isMounted = false
|
|
35
35
|
})
|
|
36
36
|
|
|
37
|
+
setLocaleWhenInit()
|
|
38
|
+
|
|
37
39
|
let lotteryProgramsForPlayer: LotteryProgramForPlayer[] = []
|
|
38
40
|
let lotteryProgram: LotteryProgram;
|
|
39
41
|
let loading: boolean = true;
|
|
@@ -52,18 +54,24 @@
|
|
|
52
54
|
_postMessage({type: 'wof-private-message-lotteryProgramsForPlayer', lotteryProgramsForPlayer })
|
|
53
55
|
}
|
|
54
56
|
|
|
57
|
+
const setLangReactive = () => {
|
|
58
|
+
setLocale(lang)
|
|
59
|
+
init()
|
|
60
|
+
}
|
|
61
|
+
|
|
55
62
|
$: session && init()
|
|
56
63
|
$: endpoint && init()
|
|
64
|
+
$: lang && setLangReactive()
|
|
57
65
|
|
|
58
66
|
</script>
|
|
59
67
|
|
|
60
68
|
<div {...classWithPart("Root")}>
|
|
61
69
|
|
|
62
|
-
<lottery-program-wof-private-tabs>
|
|
70
|
+
<lottery-program-wof-private-tabs {lang}>
|
|
63
71
|
<div slot="tab-Program">
|
|
64
72
|
<div {...classWithPart('CommonContainer')}>
|
|
65
73
|
{#if loading}
|
|
66
|
-
<
|
|
74
|
+
<wof-loader />
|
|
67
75
|
{:else}
|
|
68
76
|
{#if lotteryProgramsForPlayer.length}
|
|
69
77
|
{#each lotteryProgramsForPlayer as _l}
|
|
@@ -71,13 +79,12 @@
|
|
|
71
79
|
lang,
|
|
72
80
|
endpoint,
|
|
73
81
|
session,
|
|
74
|
-
theme,
|
|
75
82
|
lotteryprogramforplayer: JSON.stringify(_l)
|
|
76
83
|
}} />
|
|
77
84
|
{/each}
|
|
78
85
|
{:else}
|
|
79
86
|
<div {...classWithPart("NoContent")}>
|
|
80
|
-
<p>
|
|
87
|
+
<p>{$_('wof.NoContent')}</p>
|
|
81
88
|
</div>
|
|
82
89
|
{/if}
|
|
83
90
|
{/if}
|
package/src/business.dom.ts
CHANGED
|
@@ -1,121 +1,3 @@
|
|
|
1
|
-
import { createSVGElement } from "./calc";
|
|
2
|
-
import { getPropsForPartitionInfo } from "./calc.point";
|
|
3
|
-
import { setProps } from "./util";
|
|
4
|
-
|
|
5
|
-
export const getSvgImageProps = (ratio, index, radius, center, length, pointermode, arrowmode) => {
|
|
6
|
-
const sizeImage = radius / 8 // this.sizeImage
|
|
7
|
-
|
|
8
|
-
const width = sizeImage
|
|
9
|
-
const height = sizeImage
|
|
10
|
-
|
|
11
|
-
const offset = {
|
|
12
|
-
center: -1 * sizeImage / 2,
|
|
13
|
-
transform: {
|
|
14
|
-
x: sizeImage / 2,
|
|
15
|
-
y: sizeImage / 2,
|
|
16
|
-
},
|
|
17
|
-
position: {
|
|
18
|
-
x: 0,
|
|
19
|
-
y: 0,
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
...getPropsForPartitionInfo(ratio, radius, center, index, length, pointermode, arrowmode, offset),
|
|
24
|
-
width,
|
|
25
|
-
height,
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const getSvgTextProps = (ratio, index, radius, center, length, pointermode, arrowmode) => {
|
|
30
|
-
|
|
31
|
-
const offset = {
|
|
32
|
-
center: 0,
|
|
33
|
-
position: {
|
|
34
|
-
x: 0, //option.name.length * 4,
|
|
35
|
-
y: 0
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
transform: {
|
|
39
|
-
x: 0,
|
|
40
|
-
y: 0,
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
...getPropsForPartitionInfo(ratio, radius, center, index, length, pointermode, arrowmode, offset),
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export const renderPartitionInfo = (ratio, svg, options, radius, center, pointermode, arrowmode) => {
|
|
50
|
-
const container = svg.querySelector("g#Images")
|
|
51
|
-
container.innerHTML = null
|
|
52
|
-
|
|
53
|
-
options.map((option, index) => {
|
|
54
|
-
|
|
55
|
-
let partitionAppearence: SVGElement
|
|
56
|
-
|
|
57
|
-
if(option.image){
|
|
58
|
-
|
|
59
|
-
const image = option.image as SVGImageElement
|
|
60
|
-
|
|
61
|
-
const sizeImage = radius / 8 // this.sizeImage
|
|
62
|
-
|
|
63
|
-
const width = sizeImage
|
|
64
|
-
const height = sizeImage
|
|
65
|
-
|
|
66
|
-
const offset = {
|
|
67
|
-
center: -1 * sizeImage / 2,
|
|
68
|
-
transform: {
|
|
69
|
-
x: sizeImage / 2,
|
|
70
|
-
y: sizeImage / 2,
|
|
71
|
-
},
|
|
72
|
-
position: {
|
|
73
|
-
x: 0,
|
|
74
|
-
y: 0,
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
setProps(image, {
|
|
79
|
-
...getPropsForPartitionInfo(ratio, radius, center, index, options.length, pointermode, arrowmode, offset),
|
|
80
|
-
width,
|
|
81
|
-
height,
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
partitionAppearence = image
|
|
85
|
-
|
|
86
|
-
}else if(option.name){
|
|
87
|
-
|
|
88
|
-
const text = createSVGElement("text")
|
|
89
|
-
|
|
90
|
-
const offset = {
|
|
91
|
-
center: 0,
|
|
92
|
-
position: {
|
|
93
|
-
x: option.name.length * 4,
|
|
94
|
-
y: 0
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
transform: {
|
|
98
|
-
x: 0,
|
|
99
|
-
y: 0,
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
setProps(text, {
|
|
104
|
-
...getPropsForPartitionInfo(ratio, radius, center, index, options.length, pointermode, arrowmode, offset),
|
|
105
|
-
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
text.innerHTML = option.name
|
|
109
|
-
|
|
110
|
-
partitionAppearence = text
|
|
111
|
-
|
|
112
|
-
}else{
|
|
113
|
-
throw new Error('please set name for partition')
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
container.appendChild(partitionAppearence)
|
|
117
|
-
})
|
|
118
|
-
}
|
|
119
1
|
|
|
120
2
|
export const getPropsOfBackgroundCircle = (radius, rRingOuter, rRingInner) => ({
|
|
121
3
|
cx: radius,
|
package/src/business.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { WheelOfFortunePartition } from './api';
|
|
2
|
-
import {
|
|
3
|
-
import { findDeg, randomInSection } from './calc';
|
|
2
|
+
import { findDeg } from './calc';
|
|
4
3
|
import { getStatePropsForSpin } from './css.state';
|
|
5
4
|
import fakeDraw from './fakeDraw';
|
|
6
5
|
import fakeResult from './fakeResult';
|
|
@@ -8,6 +7,16 @@ import { _postMessage } from './message';
|
|
|
8
7
|
import { Api, ApiConfigs, Lang, PointerMode } from './types';
|
|
9
8
|
import type { LotteryProgramForPlayer } from './types.business';
|
|
10
9
|
import { delay, fetcher, imageLoaderSvg, setProps } from './util';
|
|
10
|
+
import { _ } from './i18n';
|
|
11
|
+
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
import Thankyou1Svg from './images/Thankyou_1.svg'
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
import Thankyou2Svg from './images/Thankyou_2.svg'
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
import Thankyou3Svg from './images/Thankyou_3.svg'
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
import Thankyou4Svg from './images/Thankyou_4.svg'
|
|
11
20
|
|
|
12
21
|
export interface Option {
|
|
13
22
|
image: SVGElement | string,
|
|
@@ -92,7 +101,7 @@ export const getOptionsFromPartitions = (partitions: WheelOfFortunePartition[],
|
|
|
92
101
|
const partitionLang = {}
|
|
93
102
|
Object.keys(_partition).map((_key) => {
|
|
94
103
|
if(['name', 'image1', 'image2', 'image3'].includes(_key)){
|
|
95
|
-
partitionLang[_key] = _partition[_key][lang
|
|
104
|
+
partitionLang[_key] = _partition[_key][lang] || _partition[_key]['*']
|
|
96
105
|
}
|
|
97
106
|
})
|
|
98
107
|
|
|
@@ -107,7 +116,7 @@ export const getOptionsFromPartitions = (partitions: WheelOfFortunePartition[],
|
|
|
107
116
|
partitions.map(partition => probabilityAll += Number(partition.probability))
|
|
108
117
|
if(probabilityAll < 1){
|
|
109
118
|
options.push({
|
|
110
|
-
image:
|
|
119
|
+
image: Thankyou1Svg,
|
|
111
120
|
name: 'Thank you'
|
|
112
121
|
})
|
|
113
122
|
}
|
|
@@ -171,7 +180,7 @@ export const api = {
|
|
|
171
180
|
return lotteryProgramForPlayers
|
|
172
181
|
},
|
|
173
182
|
draw:
|
|
174
|
-
async (endpoint: string, session: string, id: string, guid, options: Option[]
|
|
183
|
+
async (endpoint: string, session: string, id: string, guid, options: Option[]) => {
|
|
175
184
|
|
|
176
185
|
let data = await fetcherApi(Api.draw, endpoint, { id, session, guid })
|
|
177
186
|
|
|
@@ -183,7 +192,7 @@ export const api = {
|
|
|
183
192
|
|
|
184
193
|
if(!index){
|
|
185
194
|
index = options.length - 1
|
|
186
|
-
message =
|
|
195
|
+
message = _('wof.Loss')
|
|
187
196
|
}else{
|
|
188
197
|
message = {
|
|
189
198
|
mode: 'gift',
|
|
@@ -203,23 +212,24 @@ export const api = {
|
|
|
203
212
|
},
|
|
204
213
|
}
|
|
205
214
|
|
|
206
|
-
export const getMessageByCurrent = (current) => {
|
|
215
|
+
// export const getMessageByCurrent = (current) => {
|
|
207
216
|
|
|
208
|
-
|
|
217
|
+
// const { maxImplicitTickets, usedImplicitTickets, activeTickets } = current
|
|
209
218
|
|
|
210
|
-
|
|
211
|
-
|
|
219
|
+
// const conditionImplicitTickets = usedImplicitTickets < maxImplicitTickets
|
|
220
|
+
// const conditionActiveTickets = activeTickets > 0
|
|
212
221
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
222
|
+
// if(conditionImplicitTickets){
|
|
223
|
+
// const implicitTickets = `${maxImplicitTickets - usedImplicitTickets}/${maxImplicitTickets}`
|
|
224
|
+
// return `You have ${implicitTickets} Implicit Tickets`
|
|
225
|
+
// }
|
|
216
226
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
227
|
+
// if(conditionActiveTickets){
|
|
228
|
+
// return `You used all Implicit Tickets in this period, but you have ${activeTickets} active Tickets`
|
|
229
|
+
// }
|
|
220
230
|
|
|
221
|
-
|
|
222
|
-
}
|
|
231
|
+
// return `You not have any more tickets, please check T&C to get a chance.`
|
|
232
|
+
// }
|
|
223
233
|
|
|
224
234
|
export const checkIfNowIsBetween = (current) => {
|
|
225
235
|
|
package/src/calc.point.ts
CHANGED
|
@@ -115,56 +115,6 @@ export const getTrianglePoints =
|
|
|
115
115
|
return pointsValue
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
export const getPartitionProps =
|
|
119
|
-
(
|
|
120
|
-
index: number,
|
|
121
|
-
number: number,
|
|
122
|
-
rRingInner: number,
|
|
123
|
-
r: number,
|
|
124
|
-
) => {
|
|
125
|
-
|
|
126
|
-
const rPoint = getSymmetricalPointFromScalar(r)
|
|
127
|
-
const rRingInnerPoint = getSymmetricalPointFromScalar(rRingInner)
|
|
128
|
-
|
|
129
|
-
const { point, pointNext } = getPointWithNext(index, number, rRingInner, r)
|
|
130
|
-
|
|
131
|
-
const ds = [
|
|
132
|
-
`M`,
|
|
133
|
-
...mapObjectValueToTuple(rPoint),
|
|
134
|
-
`L`,
|
|
135
|
-
...mapObjectValueToTuple(point),
|
|
136
|
-
`A`,
|
|
137
|
-
...mapObjectValueToTuple(rRingInnerPoint),
|
|
138
|
-
`0 0 1`,
|
|
139
|
-
...mapObjectValueToTuple(pointNext),
|
|
140
|
-
`Z`,
|
|
141
|
-
]
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
d: ds.join(' ')
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export const getRingImageProps = (index, length, rRingOuter, rRingInner, center, ratio) => {
|
|
149
|
-
|
|
150
|
-
const aver = (rRingOuter + rRingInner) / 2
|
|
151
|
-
const diff = (rRingOuter - rRingInner) / 2 + 4 * ratio
|
|
152
|
-
|
|
153
|
-
const { point } = getPointWithNext(index, length, aver, center)
|
|
154
|
-
|
|
155
|
-
const radius = diff * 2
|
|
156
|
-
|
|
157
|
-
return {
|
|
158
|
-
x: point.x - diff,
|
|
159
|
-
y: point.y - diff,
|
|
160
|
-
width: radius,
|
|
161
|
-
height: radius,
|
|
162
|
-
// style: `stroke-width: ${radius * ratioGoldenMean(6)}px`,
|
|
163
|
-
class: "RingImage",
|
|
164
|
-
part: "RingImage",
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
118
|
export const getImagePartitionProps = (index, length, radius) => {
|
|
169
119
|
|
|
170
120
|
const multiple = 1.5
|
|
@@ -196,27 +146,6 @@ export const getImagePartitionProps = (index, length, radius) => {
|
|
|
196
146
|
}
|
|
197
147
|
}
|
|
198
148
|
|
|
199
|
-
export const getImageProps = (length, radius, center) => {
|
|
200
|
-
|
|
201
|
-
const multiple = 1
|
|
202
|
-
|
|
203
|
-
const size = {
|
|
204
|
-
width: multiple * 2 * radius * Math.sin(2 * Math.PI / length /2),
|
|
205
|
-
height: multiple * radius,
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return {
|
|
209
|
-
x: center,
|
|
210
|
-
y: center,
|
|
211
|
-
...size,
|
|
212
|
-
style: `transform: translate(${[
|
|
213
|
-
size.width / 2,
|
|
214
|
-
size.height
|
|
215
|
-
// * (1 - 168/197)
|
|
216
|
-
].map(s => `${s * -1}px`).join(',')})`,
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
149
|
export const getRingCircleProps = (index, length, rRingOuter, rRingInner, r) => {
|
|
221
150
|
|
|
222
151
|
const aver = (rRingOuter + rRingInner) / 2
|
|
@@ -236,80 +165,14 @@ export const getRingCircleProps = (index, length, rRingOuter, rRingInner, r) =>
|
|
|
236
165
|
}
|
|
237
166
|
}
|
|
238
167
|
|
|
239
|
-
const angleTransform = (pointermode, arrowmode) => {
|
|
240
|
-
switch(pointermode){
|
|
241
|
-
case PointerMode.Arrow:
|
|
242
|
-
switch(arrowmode){
|
|
243
|
-
case ArrowMode.DownFromTop:
|
|
244
|
-
case ArrowMode.UpFromCenter:
|
|
245
|
-
return - Math.PI / 2
|
|
246
|
-
|
|
247
|
-
case ArrowMode.DownFromCenter:
|
|
248
|
-
case ArrowMode.UpFromBottom:
|
|
249
|
-
return Math.PI / 2
|
|
250
|
-
}
|
|
251
168
|
|
|
252
|
-
|
|
253
|
-
return - Math.PI / 2
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
enum RotateDirection {
|
|
258
|
-
clockwise = 1,
|
|
259
|
-
anticlockwise = -1,
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
const pointMinus = (point1: Point, point2: Point): Point => ({
|
|
169
|
+
export const pointMinus = (point1: Point, point2: Point): Point => ({
|
|
263
170
|
x: point1.x - point2.x,
|
|
264
171
|
y: point1.y - point2.y
|
|
265
172
|
})
|
|
266
173
|
|
|
267
|
-
const pointPlus = (point1: Point, point2: Point): Point => ({
|
|
174
|
+
export const pointPlus = (point1: Point, point2: Point): Point => ({
|
|
268
175
|
x: point1.x + point2.x,
|
|
269
176
|
y: point1.y + point2.y
|
|
270
177
|
})
|
|
271
178
|
|
|
272
|
-
const getPropsCommonTransform = (ratio: number, index: number, length: number, point: Point, offset: Point, direction: RotateDirection) => {
|
|
273
|
-
|
|
274
|
-
const angleSelf = 360 * index / length * direction -90
|
|
275
|
-
|
|
276
|
-
const transformOrigin: Point = pointPlus(point, offset)
|
|
277
|
-
|
|
278
|
-
return {
|
|
279
|
-
style: [
|
|
280
|
-
`font-size: ${13 * ratio}px`,
|
|
281
|
-
`transform: rotate(${angleSelf}deg)`,
|
|
282
|
-
`transform-origin: ${transformOrigin.x}px ${transformOrigin.y}px`,
|
|
283
|
-
].join(';')
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
export const getPropsForPartitionInfo = (
|
|
288
|
-
ratio: number,
|
|
289
|
-
radius: number,
|
|
290
|
-
center: number,
|
|
291
|
-
index: number,
|
|
292
|
-
length: number,
|
|
293
|
-
pointermode: PointerMode,
|
|
294
|
-
arrowmode: ArrowMode,
|
|
295
|
-
offset: any
|
|
296
|
-
) => {
|
|
297
|
-
|
|
298
|
-
const direction = RotateDirection.clockwise
|
|
299
|
-
|
|
300
|
-
const angle =
|
|
301
|
-
angleTransform(pointermode, arrowmode) +
|
|
302
|
-
direction * index * 2 * Math.PI / length
|
|
303
|
-
|
|
304
|
-
const point = getPointOnCircle(radius - 9 * ratio, angle, center + offset.center)
|
|
305
|
-
|
|
306
|
-
return {
|
|
307
|
-
...pointMinus(point, offset.position),
|
|
308
|
-
...(pointermode === PointerMode.Arrow || true ?
|
|
309
|
-
getPropsCommonTransform(ratio, index, length, point, offset.transform, direction)
|
|
310
|
-
:
|
|
311
|
-
{}
|
|
312
|
-
)
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { api } from "./business"
|
|
2
|
+
import { _postMessage } from "./message"
|
|
3
|
+
import { setMessage as setMessageBase } from './business';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export class Process {
|
|
7
|
+
|
|
8
|
+
id
|
|
9
|
+
halter
|
|
10
|
+
afterSuccess
|
|
11
|
+
afterSetMessage
|
|
12
|
+
fetcher
|
|
13
|
+
|
|
14
|
+
constructor(params){
|
|
15
|
+
this.id = params.id
|
|
16
|
+
this.afterSetMessage = params.afterSetMessage
|
|
17
|
+
this.halter = params.halter
|
|
18
|
+
this.afterSuccess = params.afterSuccess
|
|
19
|
+
this.fetcher = params.fetcher
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
handleHaltProcess(index, message, fn = () => {}){
|
|
23
|
+
_postMessage({ id: this.id, type: 'wof-private-message-spin-before' })
|
|
24
|
+
|
|
25
|
+
const cb = () => {
|
|
26
|
+
setTimeout(() => {
|
|
27
|
+
_postMessage({ id: this.id, type: 'wof-private-message-spin-after' })
|
|
28
|
+
fn()
|
|
29
|
+
this.setMessage(message)
|
|
30
|
+
}, 1000)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// spinner.halt(calc.getDeg(index), cb)
|
|
34
|
+
this.halter(index, cb)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async drawer (guid, frequency: number = 0){
|
|
38
|
+
|
|
39
|
+
let index
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const { data, message, index: _index } = await this.fetcher(guid)
|
|
43
|
+
index = _index
|
|
44
|
+
|
|
45
|
+
if(!data.success) throw new Error()
|
|
46
|
+
if(data.item.state === "drawn") throw new Error()
|
|
47
|
+
|
|
48
|
+
this.handleHaltProcess(index, message, this.afterSuccess)
|
|
49
|
+
|
|
50
|
+
} catch (e) {
|
|
51
|
+
if(frequency < 4){
|
|
52
|
+
this.drawer(guid, frequency + 1)
|
|
53
|
+
}else{
|
|
54
|
+
const messageError = 'There was a problem to grant the reward. Please contact support'
|
|
55
|
+
this.handleHaltProcess(index, messageError)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
setMessage(entry: string | object) {
|
|
61
|
+
setMessageBase(this.id, entry)
|
|
62
|
+
this.afterSetMessage()
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/class.spinner.ts
CHANGED
|
@@ -3,9 +3,9 @@ import { easing, easingGrad, params, SpinStep, Easing, easingGradX } from "./cla
|
|
|
3
3
|
export class Spinner {
|
|
4
4
|
|
|
5
5
|
deg: number = 0
|
|
6
|
+
fps: number;
|
|
6
7
|
// spinable: boolean = true
|
|
7
8
|
degTarget: number = undefined
|
|
8
|
-
container: HTMLElement = undefined
|
|
9
9
|
step: SpinStep = undefined
|
|
10
10
|
tick
|
|
11
11
|
cb
|
|
@@ -14,6 +14,10 @@ export class Spinner {
|
|
|
14
14
|
|
|
15
15
|
param = params[2]
|
|
16
16
|
|
|
17
|
+
constructor(inits){
|
|
18
|
+
this.tick = inits.tick
|
|
19
|
+
}
|
|
20
|
+
|
|
17
21
|
public launch(){
|
|
18
22
|
this.shouldHalt = undefined
|
|
19
23
|
this.step = SpinStep.launch
|
|
@@ -32,22 +36,24 @@ export class Spinner {
|
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
38
|
|
|
35
|
-
private continueRepeat = () =>
|
|
39
|
+
private continueRepeat = () => setTimeout(() => this.ticker(), 30)
|
|
36
40
|
private ticker = () => {
|
|
37
41
|
|
|
38
42
|
const linkSpeed = this.param.loopSpeed
|
|
39
43
|
|
|
40
44
|
const easingDuration = (deg: number) =>
|
|
41
|
-
|
|
45
|
+
33 * easingGrad[this.easingType] * deg / this.param.loopSpeed
|
|
42
46
|
|
|
43
47
|
const animations = {
|
|
44
48
|
launch: () => {
|
|
45
|
-
const
|
|
46
|
-
|
|
49
|
+
const degTar = 360 * this.param.launchTurns - this.deg
|
|
50
|
+
const t = easingDuration(degTar)
|
|
51
|
+
|
|
52
|
+
this.animateF(t, this.deg, degTar, easing.in[this.easingType], easingGradX.in[this.easingType])
|
|
47
53
|
},
|
|
48
54
|
halt: () => {
|
|
49
55
|
const t = easingDuration(this.degTarget)
|
|
50
|
-
this.
|
|
56
|
+
this.animateF(t, 0, this.degTarget, easing.out[this.easingType], easingGradX.out[this.easingType])
|
|
51
57
|
},
|
|
52
58
|
loop: () => {
|
|
53
59
|
this.setDeg((this.deg + linkSpeed) % 360, easingGrad[this.easingType])
|
|
@@ -115,6 +121,32 @@ export class Spinner {
|
|
|
115
121
|
this.tick(deg, speed)
|
|
116
122
|
}
|
|
117
123
|
|
|
124
|
+
animateF = (duration: number, startAngle, target: number, easing, _easingGrad) => {
|
|
125
|
+
let start = null
|
|
126
|
+
|
|
127
|
+
const step = () => {
|
|
128
|
+
let timestamp = new Date().getTime()
|
|
129
|
+
if(!start){
|
|
130
|
+
start = timestamp
|
|
131
|
+
}
|
|
132
|
+
const progress = timestamp - start
|
|
133
|
+
|
|
134
|
+
const translation = target * easing(progress / duration) + startAngle;
|
|
135
|
+
const speedCur = Math.abs(_easingGrad(progress / duration))
|
|
136
|
+
//const speedRealCur = target / duration * Math.abs(_easingGrad(progress / duration)) * 33
|
|
137
|
+
//console.log(this.param.loopSpeed, speedRealCur);
|
|
138
|
+
|
|
139
|
+
this.setDeg(translation, speedCur)
|
|
140
|
+
|
|
141
|
+
if (progress < duration) {
|
|
142
|
+
setTimeout(() => step(), 30)
|
|
143
|
+
}else{
|
|
144
|
+
this.cb()
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
step()
|
|
148
|
+
}
|
|
149
|
+
|
|
118
150
|
animate = (duration: number, startAngle, target: number, easing, _easingGrad) => {
|
|
119
151
|
|
|
120
152
|
let animationId = null;
|