use funkyarray package
This commit is contained in:
parent
61586092d1
commit
f606d1547b
9 changed files with 40 additions and 90 deletions
|
@ -1,77 +0,0 @@
|
|||
export class FunkyArray<T, TT> {
|
||||
private items:Map<T, TT> = new Map<T, TT>();
|
||||
private itemKeys:Array<T> = new Array<T>();
|
||||
|
||||
private _getKeys() : Array<T> {
|
||||
const keyArray = new Array<T>();
|
||||
let result:IteratorResult<T, T>;
|
||||
const iterator = this.items.keys();
|
||||
while (!(result = iterator.next()).done) {
|
||||
keyArray.push(result.value);
|
||||
}
|
||||
return keyArray;
|
||||
}
|
||||
|
||||
public set(key:T, item:TT, regenerate:boolean = true) : TT {
|
||||
this.items.set(key, item);
|
||||
if (regenerate) {
|
||||
this.itemKeys = this._getKeys();
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public remove(key:T, regenerate:boolean = true) {
|
||||
const success = this.items.delete(key);
|
||||
if (regenerate) {
|
||||
this.itemKeys = this._getKeys();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
public removeFirst(regenerate:boolean = true) {
|
||||
const success = this.items.delete(this.items.keys().next().value);
|
||||
if (regenerate) {
|
||||
this.itemKeys = this._getKeys();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
public first() : TT {
|
||||
return this.items.values().next().value;
|
||||
}
|
||||
|
||||
public get length() : number {
|
||||
return this.items.size;
|
||||
}
|
||||
|
||||
public get(key:T) : TT | undefined {
|
||||
return this.items.get(key);
|
||||
}
|
||||
|
||||
public has(key:T) : boolean {
|
||||
return this.itemKeys.includes(key);
|
||||
}
|
||||
|
||||
public get keys() : Array<T> {
|
||||
return this.itemKeys;
|
||||
}
|
||||
|
||||
public forEach(callback: (value:TT) => void) {
|
||||
return new Promise<boolean>(async (resolve, reject) => {
|
||||
if (this.items.size === 0) {
|
||||
return resolve(true);
|
||||
}
|
||||
|
||||
try {
|
||||
const iterator = this.items.values();
|
||||
let result:IteratorResult<TT, TT>;
|
||||
while (!(result = iterator.next()).done) {
|
||||
await callback(result.value);
|
||||
}
|
||||
resolve(true);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
40
package-lock.json
generated
40
package-lock.json
generated
|
@ -10,6 +10,7 @@
|
|||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bufferstuff": "^1.4.2",
|
||||
"funky-array": "^1.0.0",
|
||||
"hsconsole": "^1.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -512,12 +513,13 @@
|
|||
}
|
||||
},
|
||||
"node_modules/braces": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
|
||||
"integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
|
||||
"integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"fill-range": "^7.0.1"
|
||||
"fill-range": "^7.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
|
@ -963,10 +965,11 @@
|
|||
"peer": true
|
||||
},
|
||||
"node_modules/fill-range": {
|
||||
"version": "7.0.1",
|
||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
|
||||
"integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
|
||||
"version": "7.1.1",
|
||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
|
||||
"integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"to-regex-range": "^5.0.1"
|
||||
},
|
||||
|
@ -983,6 +986,21 @@
|
|||
"is-callable": "^1.1.3"
|
||||
}
|
||||
},
|
||||
"node_modules/fsevents": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
|
||||
"integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/function-bind": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
|
||||
|
@ -1016,6 +1034,12 @@
|
|||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/funky-array": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/funky-array/-/funky-array-1.0.0.tgz",
|
||||
"integrity": "sha512-1oMg2rdLkvQV+RzV6IwaPw0wngQkVb/9bIfr+Twj/MqWKaBVM6KPwkq2IBSjTf0PC3GLeiMZ6weeG3jdhOlIYg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/get-intrinsic": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.1.tgz",
|
||||
|
@ -1351,6 +1375,7 @@
|
|||
"resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
|
||||
"integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.12.0"
|
||||
}
|
||||
|
@ -2395,6 +2420,7 @@
|
|||
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
|
||||
"integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"is-number": "^7.0.0"
|
||||
},
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
"homepage": "https://github.com/tgpholly/mc-beta-server#readme",
|
||||
"dependencies": {
|
||||
"bufferstuff": "^1.4.2",
|
||||
"funky-array": "^1.0.0",
|
||||
"hsconsole": "^1.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { FunkyArray } from "../funkyArray";
|
||||
import FunkyArray from "funky-array";
|
||||
import Vec3 from "./Vec3";
|
||||
|
||||
// Based on this MDN article:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { FunkyArray } from "../funkyArray";
|
||||
import FunkyArray from "funky-array";
|
||||
import { NibbleArray } from "../nibbleArray";
|
||||
import { Block } from "./blocks/Block";
|
||||
import { Player } from "./entities/Player";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { createWriter, Endian } from "bufferstuff";
|
||||
import { FunkyArray } from "../funkyArray";
|
||||
import FunkyArray from "funky-array";
|
||||
import { MetadataFieldType } from "./enums/MetadataFieldType";
|
||||
import Vec3 from "./Vec3";
|
||||
import { ItemStack } from "./inventories/ItemStack";
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Config } from "../config";
|
||||
import { Console } from "hsconsole";
|
||||
import { createReader, IReader, Endian } from "bufferstuff";
|
||||
import { FunkyArray } from "../funkyArray";
|
||||
import FunkyArray from "funky-array";
|
||||
import { Server, Socket } from "net";
|
||||
import { MPClient } from "./MPClient";
|
||||
import { Packet } from "./enums/Packet";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Endian, createWriter } from "bufferstuff";
|
||||
import { FunkyArray } from "../funkyArray";
|
||||
import FunkyArray from "funky-array";
|
||||
import { Chunk } from "./Chunk";
|
||||
import { WorldSaveManager } from "./WorldSaveManager";
|
||||
import { Block } from "./blocks/Block";
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Chunk } from "./Chunk";
|
|||
import { SaveCompressionType } from "./enums/SaveCompressionType";
|
||||
import { deflate, inflate } from "zlib";
|
||||
import { World } from "./World";
|
||||
import { FunkyArray } from "../funkyArray";
|
||||
import FunkyArray from "funky-array";
|
||||
import { Console } from "hsconsole";
|
||||
|
||||
enum FileMagic {
|
||||
|
|
Loading…
Reference in a new issue