/
game.ts
95 lines (77 loc) · 2.73 KB
/
game.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import Vue from 'vue';
import { Component, Prop } from 'vue-property-decorator';
import { State } from 'vuex-class';
import { propOptional, propRequired } from '../../../../utils/vue';
import AppContentViewer from '../../../../_common/content/content-viewer/content-viewer.vue';
import { Environment } from '../../../../_common/environment/environment.service';
import AppFadeCollapse from '../../../../_common/fade-collapse/fade-collapse.vue';
import { GameBundle } from '../../../../_common/game-bundle/game-bundle.model';
import { CustomMessage as CustomGameMessage, Game } from '../../../../_common/game/game.model';
import AppGamePackageCard from '../../../../_common/game/package/card/card.vue';
import { GamePackagePayloadModel } from '../../../../_common/game/package/package-payload.model';
import { KeyGroup } from '../../../../_common/key-group/key-group.model';
import AppMediaItemCover from '../../../../_common/media-item/cover/cover.vue';
import { store, Store } from '../../../store/index';
const ClaimGameThemeKey = 'claim-game';
@Component({
components: {
AppFadeCollapse,
AppGamePackageCard,
AppMediaItemCover,
AppContentViewer,
},
})
export default class AppKeyGame extends Vue {
@Prop({ required: true })
payload!: any;
@Prop(propRequired(String))
loginUrl!: string;
@Prop(propOptional(String))
accessKey?: string;
@State
app!: Store['app'];
showingThanks = false;
isClaimOnly = false;
game: Game = null as any;
bundle: GameBundle | null = null;
keyGroup: KeyGroup | null = null;
packagePayload: GamePackagePayloadModel | null = null;
gameIsLocked = false;
canToggleDescription = false;
showingFullDescription = false;
customGameMessages: CustomGameMessage[] = [];
Environment = Environment;
created() {
this.showingThanks = typeof this.$route.query.thanks !== 'undefined';
this.game = new Game(this.payload.game);
this.bundle = this.payload.bundle ? new GameBundle(this.payload.bundle) : null;
this.keyGroup = this.payload.keyGroup ? new KeyGroup(this.payload.keyGroup) : null;
this.gameIsLocked = this.payload.gameIsLocked ?? false;
this.setPageTheme();
if (
this.keyGroup &&
(this.keyGroup.type === KeyGroup.TYPE_USER ||
this.keyGroup.type === KeyGroup.TYPE_ANONYMOUS_CLAIM)
) {
this.isClaimOnly = true;
return;
}
this.customGameMessages = this.payload.customMessages || [];
if (this.payload.packages && this.payload.packages.length) {
this.packagePayload = new GamePackagePayloadModel(this.payload);
}
}
destroyed() {
store.commit('theme/clearPageTheme', ClaimGameThemeKey);
}
private setPageTheme() {
const theme = this.game.theme ?? null;
store.commit('theme/setPageTheme', {
key: ClaimGameThemeKey,
theme,
});
}
claim() {
this.$emit('claim', this.game);
}
}