-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54ce821
commit 802e7b8
Showing
5 changed files
with
166 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright (c) 2018 PROPHESSOR | ||
* | ||
* This software is released under the MIT License. | ||
* https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const UDMFBlock = require('./UDMFBlock'); | ||
|
||
module.exports = class Line extends UDMFBlock { // TODO:Direction | ||
constructor(udmfblock, udmfarray) { | ||
super(udmfblock); | ||
|
||
this.udmfblock = udmfblock; | ||
this.udmfarray = udmfarray; | ||
} | ||
|
||
get v1() { | ||
if (typeof this._v1 === 'undefined') | ||
this._v1 = new UDMFBlock(this.udmfarray.filter(e => e[0] === 'vertex')[this.udmfblock.v1]); | ||
return this._v1; | ||
} | ||
|
||
get v2() { | ||
if (typeof this._v2 === 'undefined') | ||
this._v2 = new UDMFBlock(this.udmfarray.filter(e => e[0] === 'vertex')[this.udmfblock.v2]); | ||
return this._v2; | ||
} | ||
|
||
get front() { | ||
if (typeof this._front === 'undefined') | ||
this._front = new UDMFBlock(this.udmfarray.filter(e => e[0] === 'sidedef')[this.udmfblock.sidefront]); | ||
return this._front; | ||
} | ||
|
||
get back() { | ||
if (typeof this.udmfblock.sideback === 'undefined' || this.udmfblock.sideback === -1) return null; | ||
if (typeof this._back === 'undefined') | ||
this._back = new UDMFBlock(this.udmfarray.filter(e => e[0] === 'sidedef')[this.udmfblock.sideback]); | ||
return this._back; | ||
} | ||
|
||
/** Возвращает координаты середины линии | ||
* @returns {array} [x, y] | ||
*/ | ||
get avg() { | ||
return [(this.v1.x + this.v2.x) / 2, (this.v1.y + this.v2.y) / 2]; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Copyright (c) 2018 PROPHESSOR | ||
* | ||
* This software is released under the MIT License. | ||
* https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const UDMFBlock = require('./UDMFBlock'); | ||
const Line = require('./Line'); | ||
|
||
module.exports = class Sector extends UDMFBlock { | ||
constructor(udmfblock, udmfarray) { | ||
super(udmfblock); | ||
|
||
this.udmfblock = udmfblock; | ||
this.udmfarray = udmfarray; | ||
} | ||
|
||
get id() { | ||
return this.udmfblock.id; | ||
} | ||
|
||
get lines() { | ||
if (typeof this._lines === 'undefined') | ||
this._lines = this.udmfarray.filter(e => e[0] === 'linedef' && e[1].sector === this.id).map(e => new Line(new UDMFBlock(e), this.udmfarray)); | ||
return this._lines; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Copyright (c) 2018 PROPHESSOR | ||
* | ||
* This software is released under the MIT License. | ||
* https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = class UDMFBlock { | ||
constructor(udmfblock) { | ||
if (!(udmfblock instanceof Array || udmfblock instanceof UDMFBlock)) throw new TypeError('UDMFBlock must be a Array'); | ||
|
||
[this[0], this[1]] = udmfblock; | ||
this.blocktype = udmfblock[0]; | ||
Object.assign(this, udmfblock); | ||
} | ||
|
||
toUDMFArrayBlock() { | ||
return [this[0], this[1]]; | ||
} | ||
|
||
toString() { | ||
return `[UDMF Block <${this[0]}>]`; | ||
} | ||
|
||
*[Symbol.iterator]() { | ||
yield this[0]; | ||
yield this[1]; | ||
} | ||
|
||
|
||
[Symbol.toStringTag]() { | ||
return this.toString(); | ||
} | ||
|
||
[Symbol.toPrimitive]() { | ||
return this.toString(); | ||
} | ||
|
||
/** Ищет блок в udmf.json массиве и возвращает его | ||
* @param {array} json - udmf.json массив | ||
* @param {string} blockname - Тип блока | ||
* @param {number} no - Номер блока | ||
* @returns {array} udmf.json блок | ||
*/ | ||
static find(json, blockname, no) { | ||
let i = 0; | ||
|
||
for(const block of json) { | ||
if(block[0] === blockname) { | ||
if(no === i) return block[1]; | ||
i++; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Copyright (c) 2018 PROPHESSOR | ||
* | ||
* This software is released under the MIT License. | ||
* https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
UDMFBlock: require('./UDMFBlock'), | ||
Line: require('./Line'), | ||
Sector: require('./Sector') | ||
}; |