|
1
|
|
|
import { KeyboardService } from './../../data/keyboard.service'; |
|
2
|
|
|
import { ValueAccessorBase } from './../abstract/ValueAccessorBase'; |
|
3
|
|
|
/** |
|
4
|
|
|
Copyright 2018 June Hanabi |
|
5
|
|
|
|
|
6
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
you may not use this file except in compliance with the License. |
|
8
|
|
|
You may obtain a copy of the License at |
|
9
|
|
|
|
|
10
|
|
|
http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
|
|
12
|
|
|
Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
See the License for the specific language governing permissions and |
|
16
|
|
|
limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
import { Component, OnInit, Input, Output, EventEmitter, OnChanges } from '@angular/core'; |
|
20
|
|
|
import { SaveFileService } from './../../data/savefile.service'; |
|
21
|
|
|
import { TextService } from '../../data/text.service'; |
|
22
|
|
|
|
|
23
|
|
|
import { |
|
24
|
|
|
NG_VALUE_ACCESSOR, |
|
25
|
|
|
} from '@angular/forms'; |
|
26
|
|
|
|
|
27
|
|
|
@Component({ |
|
28
|
|
|
selector: 'name-input', |
|
29
|
|
|
templateUrl: './name-input.component.pug', |
|
30
|
|
|
styleUrls: ['./name-input.component.scss'], |
|
31
|
|
|
providers: [ |
|
32
|
|
|
{ provide: NG_VALUE_ACCESSOR, useExisting: NameInputComponent, multi: true } |
|
33
|
|
|
], |
|
34
|
|
|
}) |
|
35
|
|
|
export class NameInputComponent extends ValueAccessorBase<string> implements OnInit, OnChanges { |
|
36
|
|
|
|
|
37
|
|
|
constructor( |
|
38
|
|
|
public fileService: SaveFileService, |
|
39
|
|
|
public textService: TextService, |
|
40
|
|
|
public ks: KeyboardService |
|
41
|
|
|
) { |
|
42
|
|
|
super(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
ngOnInit() { |
|
46
|
|
|
this.doOnChange(""); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
ngOnChanges() { |
|
50
|
|
|
this.doOnChange(this.value); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
// Max Character count |
|
54
|
|
|
// All Pokemon have 10 character limit |
|
55
|
|
|
// All Trainers and People have a 7 character limit for dialog sake |
|
56
|
|
|
@Input() |
|
57
|
|
|
public maxLength: number = 10; |
|
58
|
|
|
|
|
59
|
|
|
@Input() |
|
60
|
|
|
public label: string = ""; |
|
61
|
|
|
|
|
62
|
|
|
@Input() |
|
63
|
|
|
public disabled: boolean = false; |
|
64
|
|
|
|
|
65
|
|
|
// Latest value |
|
66
|
|
|
@Output() |
|
67
|
|
|
public onChangeValue = new EventEmitter<string>(); |
|
68
|
|
|
|
|
69
|
|
|
// Latest internal array |
|
70
|
|
|
@Output() |
|
71
|
|
|
public onChangeInternal = new EventEmitter<Uint8Array>(); |
|
72
|
|
|
|
|
73
|
|
|
// Latest HTML representation |
|
74
|
|
|
@Output() |
|
75
|
|
|
public onChangeHTML = new EventEmitter<string>(); |
|
76
|
|
|
|
|
77
|
|
|
public invalid: boolean = false; |
|
78
|
|
|
|
|
79
|
|
|
onKeyboardClick() { |
|
80
|
|
|
this.ks.open(this); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
doOnChange(event: any) { |
|
84
|
|
|
// Grab value |
|
85
|
|
|
const val = event; |
|
86
|
|
|
|
|
87
|
|
|
// Notify value changed |
|
88
|
|
|
this.onChangeValue.emit(val); |
|
89
|
|
|
|
|
90
|
|
|
// Retrieve Internal Value and notify change |
|
91
|
|
|
const internalVal = this.textService.convertToCode( |
|
92
|
|
|
val, |
|
93
|
|
|
this.maxLength, |
|
94
|
|
|
false |
|
95
|
|
|
); |
|
96
|
|
|
this.onChangeInternal.emit(internalVal); |
|
97
|
|
|
|
|
98
|
|
|
// Retrive HTML and notify |
|
99
|
|
|
let rival = this.fileService.fileDataExpanded.rival.rivalName; |
|
100
|
|
|
if (rival == "") |
|
101
|
|
|
rival = "Blue"; |
|
102
|
|
|
|
|
103
|
|
|
let player = this.fileService.fileDataExpanded.player.basics.playerName; |
|
104
|
|
|
if (player == "") |
|
105
|
|
|
player = "Red"; |
|
106
|
|
|
|
|
107
|
|
|
this.onChangeHTML.emit(this.textService.convertEngToHTML( |
|
108
|
|
|
val, |
|
109
|
|
|
this.maxLength, |
|
110
|
|
|
rival, |
|
111
|
|
|
player |
|
112
|
|
|
)); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|