File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ timer-display {
2+ position : absolute;
3+ top : 0 ;
4+ width : 100% ;
5+ height : 0.5rem ;
6+
7+ & div {
8+ background : rgba (255 , 255 , 255 , 0.2 );
9+ }
10+ }
Original file line number Diff line number Diff line change 1+ import { Component } from './../../lib/Component' ;
2+ import { Util } from '@aegis-framework/artemis' ;
3+
4+ class TimerDisplay extends Component {
5+
6+ constructor ( ...args ) {
7+ super ( ...args ) ;
8+
9+ this . props = {
10+ callback : ( ) => { } ,
11+ time : 0 ,
12+ step : 0 ,
13+ timer : null ,
14+ tick : null
15+ } ;
16+
17+ this . state = {
18+ elapsed : 0 ,
19+ remaining : 0 ,
20+ value : 100
21+ } ;
22+ }
23+
24+ willMount ( ) {
25+ this . setProps ( {
26+ step : this . props . time / 100
27+ } ) ;
28+
29+ this . setState ( {
30+ remaining : this . props . time
31+ } ) ;
32+
33+ return Promise . resolve ( ) ;
34+ }
35+
36+ didMount ( ) {
37+ this . setProps ( {
38+ tick : ( ) => {
39+ this . setProps ( {
40+ timer : setTimeout ( ( ) => {
41+ if ( this . state . elapsed >= this . props . time ) {
42+ Util . callAsync ( this . props . callback , this . engine ) . then ( ( ) => {
43+ clearTimeout ( this . props . timer ) ;
44+ if ( this . parentNode ) {
45+ this . element ( ) . remove ( ) ;
46+ }
47+ } ) ;
48+ } else {
49+ this . setState ( {
50+ elapsed : this . state . elapsed + this . props . step ,
51+ remaining : this . state . remaining - this . props . step ,
52+ value : ( 1 - ( this . state . elapsed / this . props . time ) ) * 100
53+ } ) ;
54+
55+ this . forceRender ( ) ;
56+ this . props . tick ( ) ;
57+ }
58+
59+
60+ } , this . props . step )
61+ } ) ;
62+ }
63+ } ) ;
64+
65+ this . props . tick ( ) ;
66+
67+ return Promise . resolve ( ) ;
68+ }
69+
70+ render ( ) {
71+ return `
72+ <div style="width: ${ this . state . value } %;"></div>
73+ ` ;
74+ }
75+ }
76+
77+ TimerDisplay . tag = 'timer-display' ;
78+
79+
80+ export default TimerDisplay ;
Original file line number Diff line number Diff line change 4444@import './components/slot-container/index.css' ;
4545@import './components/text-box/index.css' ;
4646@import './components/text-input/index.css' ;
47+ @import './components/timer-display/index.css' ;
4748@import './components/visual-novel/index.css' ;
Original file line number Diff line number Diff line change @@ -122,6 +122,7 @@ import SettingsScreen from './components/settings-screen';
122122import SlotContainer from './components/slot-container' ;
123123import TextBox from './components/text-box' ;
124124import TextInput from './components/text-input' ;
125+ import TimerDisplay from './components/timer-display' ;
125126import VisualNovel from './components/visual-novel' ;
126127
127128Monogatari . _components = [
@@ -145,6 +146,7 @@ Monogatari._components = [
145146 SlotContainer ,
146147 TextBox ,
147148 TextInput ,
149+ TimerDisplay ,
148150 VisualNovel ,
149151] ;
150152
You can’t perform that action at this time.
0 commit comments