1+ /**
2+ * Copyright (c) 2018 PROPHESSOR
3+ *
4+ * This software is released under the MIT License.
5+ * https://opensource.org/licenses/MIT
6+ */
7+
8+ 'use strict' ;
9+
10+ module . exports = class UDMFBlock {
11+ constructor ( udmfblock ) {
12+ if ( ! ( udmfblock instanceof Array || udmfblock instanceof UDMFBlock ) ) throw new TypeError ( 'UDMFBlock must be a Array' ) ;
13+
14+ [ this [ 0 ] , this [ 1 ] ] = udmfblock ;
15+ this . blocktype = udmfblock [ 0 ] ;
16+ Object . assign ( this , udmfblock ) ;
17+ }
18+
19+ toUDMFArrayBlock ( ) {
20+ return [ this [ 0 ] , this [ 1 ] ] ;
21+ }
22+
23+ toString ( ) {
24+ return `[UDMF Block <${ this [ 0 ] } >]` ;
25+ }
26+
27+ * [ Symbol . iterator ] ( ) {
28+ yield this [ 0 ] ;
29+ yield this [ 1 ] ;
30+ }
31+
32+
33+ [ Symbol . toStringTag ] ( ) {
34+ return this . toString ( ) ;
35+ }
36+
37+ [ Symbol . toPrimitive ] ( ) {
38+ return this . toString ( ) ;
39+ }
40+
41+ /** Ищет блок в udmf.json массиве и возвращает его
42+ * @param {array } json - udmf.json массив
43+ * @param {string } blockname - Тип блока
44+ * @param {number } no - Номер блока
45+ * @returns {array } udmf.json блок
46+ */
47+ static find ( json , blockname , no ) {
48+ let i = 0 ;
49+
50+ for ( const block of json ) {
51+ if ( block [ 0 ] === blockname ) {
52+ if ( no === i ) return block [ 1 ] ;
53+ i ++ ;
54+ }
55+ }
56+
57+ return null ;
58+ }
59+ } ;
0 commit comments