1
1
const path = require ( `path` )
2
2
const fs = require ( "fs" )
3
+ const { resourceLimits } = require ( "worker_threads" )
3
4
4
5
exports . onCreateWebpackConfig = ( { actions } ) => {
5
6
actions . setWebpackConfig ( {
@@ -45,9 +46,110 @@ exports.onCreateNode = ({ node, actions }) => {
45
46
}
46
47
}
47
48
49
+ const lookupTable = {
50
+ 0 : "•" ,
51
+ 5 : "•" ,
52
+ 14 : "•" ,
53
+ 15 : "•" ,
54
+ 16 : "[" ,
55
+ 17 : "]" ,
56
+ 18 : "0" ,
57
+ 19 : "1" ,
58
+ 20 : "2" ,
59
+ 21 : "3" ,
60
+ 22 : "4" ,
61
+ 23 : "5" ,
62
+ 24 : "6" ,
63
+ 25 : "7" ,
64
+ 26 : "8" ,
65
+ 27 : "9" ,
66
+ 28 : "•"
67
+ }
68
+
69
+
70
+ function normalizeName ( name ) {
71
+ let result = ""
72
+ for ( let i = 0 ; i < name . length ; i ++ ) {
73
+ let code = name . charCodeAt ( i )
74
+ if ( code > 127 ) {
75
+ code -= 128
76
+ }
77
+ if ( code >= 32 && code < 127 ) {
78
+ result += String . fromCharCode ( code )
79
+ } else {
80
+ result += lookupTable [ code ] || " "
81
+ }
82
+ }
83
+ return result
84
+ }
85
+
86
+ function prepareTableData ( duration , stats ) {
87
+ const result = {
88
+ players : [ ] ,
89
+ teams : [ { } , { } ]
90
+ }
91
+ for ( let i = 0 ; i < stats . length ; i ++ ) {
92
+ result . players . push ( {
93
+ name : normalizeName ( stats [ i ] . name ) ,
94
+ team : stats [ i ] . team ,
95
+ frags : stats [ i ] . stats . frags ,
96
+ kills : stats [ i ] . stats . kills ,
97
+ deaths : stats [ i ] . stats . deaths ,
98
+ quad_takes : ( stats [ i ] . items . q || { took : 0 } ) . took ,
99
+ pent_takes : ( stats [ i ] . items . p || { took : 0 } ) . took ,
100
+ ctf_points : stats [ i ] . ctf . points || 0 ,
101
+ flag_pickups : stats [ i ] . ctf . pickups || 0 ,
102
+ flag_captures : stats [ i ] . ctf . caps || 0 ,
103
+ flag_defends : stats [ i ] . ctf . defends || 0 ,
104
+ flag_returns : stats [ i ] . ctf . returns || 0 ,
105
+ flag_carrier_defends : stats [ i ] . ctf . carrier_defends || 0 ,
106
+ flag_carrier_frags : stats [ i ] . ctf . carrier_frags || 0 ,
107
+ rune_time_res : Math . floor ( ( stats [ i ] . ctf . runes [ 0 ] * 100.0 ) / duration ) . toString ( ) + "%" ,
108
+ rune_time_str : Math . floor ( ( stats [ i ] . ctf . runes [ 1 ] * 100.0 ) / duration ) . toString ( ) + "%" ,
109
+ rune_time_hst : Math . floor ( ( stats [ i ] . ctf . runes [ 2 ] * 100.0 ) / duration ) . toString ( ) + "%" ,
110
+ rune_time_reg : Math . floor ( ( stats [ i ] . ctf . runes [ 3 ] * 100.0 ) / duration ) . toString ( ) + "%" ,
111
+ weapon_rl_hits : ( ( stats [ i ] . weapons . rl || { acc : null } ) . acc || { virtual : 0 } ) . virtual ,
112
+ weapon_rl_attacks : ( ( stats [ i ] . weapons . rl || { acc : null } ) . acc || { attacks : 0 } ) . attacks ,
113
+ weapon_lg_hits : ( ( stats [ i ] . weapons . lg || { acc : null } ) . acc || { hits : 0 } ) . hits ,
114
+ weapon_lg_attacks : ( ( stats [ i ] . weapons . lg || { acc : null } ) . acc || { attacks : 0 } ) . attacks
115
+ } )
116
+ const team = ( stats [ i ] . team == "red" ? result . teams [ 0 ] : result . teams [ 1 ] )
117
+ team . frags += ( team . frags || 0 ) + result . players [ i ] . frags
118
+ team . kills += ( team . kills || 0 ) + result . players [ i ] . kills
119
+ team . deaths += ( team . deaths || 0 ) + result . players [ i ] . deaths
120
+ team . quad_takes += ( team . quad_takes || 0 ) + result . players [ i ] . quad_takes
121
+ team . pent_takes += ( team . pent_takes || 0 ) + result . players [ i ] . pent_takes
122
+ team . ctf_points += ( team . ctf_points || 0 ) + result . players [ i ] . ctf_points
123
+ team . flag_pickups += ( team . flag_pickups || 0 ) + result . players [ i ] . flag_pickups
124
+ team . flag_captures += ( team . flag_captures || 0 ) + result . players [ i ] . flag_captures
125
+ team . flag_defends += ( team . flag_defends || 0 ) + result . players [ i ] . flag_defends
126
+ team . flag_returns += ( team . flag_returns || 0 ) + result . players [ i ] . flag_returns
127
+ team . flag_carrier_defends += ( team . flag_carrier_defends || 0 ) + result . players [ i ] . flag_carrier_defends
128
+ team . flag_carrier_frags += ( team . flag_carrier_frags || 0 ) + result . players [ i ] . flag_carrier_frags
129
+ team . rune_time_res += ( team . rune_time_res || 0 ) + stats [ i ] . ctf . runes [ 0 ]
130
+ team . rune_time_str += ( team . rune_time_str || 0 ) + stats [ i ] . ctf . runes [ 1 ]
131
+ team . rune_time_hst += ( team . rune_time_hst || 0 ) + stats [ i ] . ctf . runes [ 2 ]
132
+ team . rune_time_reg += ( team . rune_time_reg || 0 ) + stats [ i ] . ctf . runes [ 3 ]
133
+ team . weapon_rl_hits += ( team . weapon_rl_hits || 0 ) + result . players [ i ] . weapon_rl_hits
134
+ team . weapon_rl_attacks += ( team . weapon_rl_attacks || 0 ) + result . players [ i ] . weapon_rl_attacks
135
+ team . weapon_lg_hits += ( team . weapon_lg_hits || 0 ) + result . players [ i ] . weapon_lg_hits
136
+ team . weapon_lg_attacks += ( team . weapon_lg_attacks || 0 ) + result . players [ i ] . weapon_lg_attacks
137
+ }
138
+ result . teams [ 0 ] . rune_time_res = Math . floor ( ( result . teams [ 0 ] . rune_time_res * 100.0 ) / duration ) . toString ( ) + "%"
139
+ result . teams [ 1 ] . rune_time_res = Math . floor ( ( result . teams [ 1 ] . rune_time_res * 100.0 ) / duration ) . toString ( ) + "%"
140
+ result . teams [ 0 ] . rune_time_str = Math . floor ( ( result . teams [ 0 ] . rune_time_str * 100.0 ) / duration ) . toString ( ) + "%"
141
+ result . teams [ 1 ] . rune_time_str = Math . floor ( ( result . teams [ 1 ] . rune_time_str * 100.0 ) / duration ) . toString ( ) + "%"
142
+ result . teams [ 0 ] . rune_time_hst = Math . floor ( ( result . teams [ 0 ] . rune_time_hst * 100.0 ) / duration ) . toString ( ) + "%"
143
+ result . teams [ 1 ] . rune_time_hst = Math . floor ( ( result . teams [ 1 ] . rune_time_hst * 100.0 ) / duration ) . toString ( ) + "%"
144
+ result . teams [ 0 ] . rune_time_reg = Math . floor ( ( result . teams [ 0 ] . rune_time_reg * 100.0 ) / duration ) . toString ( ) + "%"
145
+ result . teams [ 1 ] . rune_time_reg = Math . floor ( ( result . teams [ 1 ] . rune_time_reg * 100.0 ) / duration ) . toString ( ) + "%"
146
+ return result
147
+ }
148
+
149
+
48
150
exports . createPages = async ( { graphql, actions } ) => {
49
151
const { createPage } = actions
50
- const mapMetadata = JSON . parse ( fs . readFileSync ( ' data/map.metadata.json' ) )
152
+ const mapMetadata = JSON . parse ( fs . readFileSync ( " data/map.metadata.json" ) )
51
153
const matchTemplate = path . resolve ( `src/pages/match.js` )
52
154
const result = await graphql ( `
53
155
query Pages {
@@ -81,12 +183,18 @@ exports.createPages = async ({ graphql, actions }) => {
81
183
kills
82
184
frags
83
185
}
186
+ items {
187
+ p {
188
+ took
189
+ }
190
+ q {
191
+ took
192
+ }
193
+ }
84
194
weapons {
85
195
rl {
86
196
acc {
87
197
virtual
88
- real
89
- hits
90
198
attacks
91
199
}
92
200
}
@@ -112,13 +220,13 @@ exports.createPages = async ({ graphql, actions }) => {
112
220
context : {
113
221
demo : edge . node . demo ,
114
222
map : {
115
- " name" : edge . node . map ,
116
- " metadata" : mapMetadata [ edge . node . map ]
223
+ name : edge . node . map ,
224
+ metadata : mapMetadata [ edge . node . map ] ,
117
225
} ,
118
226
directory : edge . node . parent . directory ,
119
227
duration : edge . node . duration ,
120
- stats : edge . node . players
228
+ matchStats : prepareTableData ( edge . node . duration , edge . node . players ) ,
121
229
} ,
122
230
} )
123
231
} )
124
- }
232
+ }
0 commit comments