gamesocket.io
Version:
Simple event-oriented API for uWebSocket.js
63 lines (62 loc) • 1.71 kB
JavaScript
'use strict'
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
return mod && mod.__esModule ? mod : { default: mod }
}
Object.defineProperty(exports, '__esModule', { value: true })
exports.DataEscort = void 0
const Logger_js_1 = __importDefault(require('../../Logger/Logger.js'))
class DataEscort {
_id
_event
_data
constructor(_id, _event, data) {
this._id = _id
this._event = _event
if (data != null) this._data = data
}
get(property) {
if (!property) return this.used
return this.getPropertyByPath(property)
}
get event() {
return this._event
}
get id() {
return this._id
}
get used() {
return this._data
}
get isPrimitive() {
return typeof this.used != 'object' && this.used != null
}
getPropertyPath(propertyName) {
if (~propertyName.indexOf('/')) return propertyName.split('/')
}
getPropertyByPath(propertyName) {
if (!this.used) return undefined
let tempData = this.used
if (Logger_js_1.default.flags.debug)
Logger_js_1.default.debug(`escort#${this._id}: find property ${propertyName} in ${tempData}`)
if (!this.isPrimitive) {
if (propertyName in tempData) return tempData[propertyName]
let propertyPath = this.getPropertyPath(propertyName)
if (propertyPath) {
let changeFlag = false
for (let part of propertyPath.values()) {
if (typeof tempData == 'object') {
if (part in tempData) {
tempData = tempData[part]
changeFlag = true
}
}
}
return changeFlag ? tempData : undefined
}
}
return undefined
}
}
exports.DataEscort = DataEscort