@colyseus/core
Version:
Multiplayer Framework for Node.js.
69 lines (68 loc) • 2.17 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var Query_exports = {};
__export(Query_exports, {
Query: () => Query
});
module.exports = __toCommonJS(Query_exports);
class Query {
constructor(rooms, conditions) {
this.$rooms = rooms.slice(0);
this.conditions = conditions;
}
sort(options) {
this.$rooms = this.$rooms.sort((room1, room2) => {
for (const field in options) {
if (options.hasOwnProperty(field)) {
const direction = options[field];
const isAscending = direction === 1 || direction === "asc" || direction === "ascending";
if (isAscending) {
if (room1[field] > room2[field]) {
return 1;
}
if (room1[field] < room2[field]) {
return -1;
}
} else {
if (room1[field] > room2[field]) {
return -1;
}
if (room1[field] < room2[field]) {
return 1;
}
}
}
}
});
}
then(resolve, reject) {
const result = this.$rooms.find((room) => {
for (const field in this.conditions) {
if (this.conditions.hasOwnProperty(field) && room[field] !== this.conditions[field]) {
return false;
}
}
return true;
});
return resolve(result);
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Query
});