mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 23:33:13 +09:00
Update with comments from review
This commit is contained in:
1 parent
a9e1bdcc65
commit
ebafda5407
2 files changed
+7
-9
No files matched your search
@@ -9,6 +9,7 @@ import fs from "fs-extra";
|
|||||||
import * as libFileOps from "./file_ops";
|
import * as libFileOps from "./file_ops";
|
||||||
import { basicType } from "./helpers";
|
import { basicType } from "./helpers";
|
||||||
|
|
||||||
|
export type ItemCountWithQuality = { [quality: string]: number };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a Map with only string keys to a JavaScript object.
|
* Converts a Map with only string keys to a JavaScript object.
|
||||||
@@ -169,7 +170,7 @@ function checkQuality(quality: unknown): asserts quality is string {
|
|||||||
* deserialized the content is verified.
|
* deserialized the content is verified.
|
||||||
*/
|
*/
|
||||||
export class ItemDatabase {
|
export class ItemDatabase {
|
||||||
private _items: Map<string, { [quality: string]: number }> = new Map();
|
private _items: Map<string, ItemCountWithQuality> = new Map();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new item database
|
* Create a new item database
|
||||||
@@ -206,10 +207,10 @@ export class ItemDatabase {
|
|||||||
* @returns Serialized representation of the database
|
* @returns Serialized representation of the database
|
||||||
*/
|
*/
|
||||||
serialize() {
|
serialize() {
|
||||||
let obj: Record<string, { [quality: string]: number }> = {};
|
let obj: Record<string, ItemCountWithQuality> = {};
|
||||||
for (let [name, qualities] of this._items) {
|
for (let [name, qualities] of this._items) {
|
||||||
for (const quality in qualities) {
|
for (const quality of Object.getOwnPropertyNames(qualities)) {
|
||||||
if (Object.prototype.hasOwnProperty.call(qualities, quality) && qualities[quality] !== 0) {
|
if (qualities[quality] !== 0) {
|
||||||
if (!obj[name]) {
|
if (!obj[name]) {
|
||||||
obj[name] = {};
|
obj[name] = {};
|
||||||
}
|
}
|
||||||
@@ -288,9 +289,6 @@ export class ItemDatabase {
|
|||||||
* @param quality - The quality of the item to remove.
|
* @param quality - The quality of the item to remove.
|
||||||
*/
|
*/
|
||||||
removeItem(name: string, count: number, quality: string) {
|
removeItem(name: string, count: number, quality: string) {
|
||||||
checkName(name);
|
|
||||||
checkCount(count);
|
|
||||||
|
|
||||||
this.addItem(name, -count, quality);
|
this.addItem(name, -count, quality);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -298,7 +296,7 @@ export class ItemDatabase {
|
|||||||
* Allow to iterate through the items.
|
* Allow to iterate through the items.
|
||||||
* @returns array of items.
|
* @returns array of items.
|
||||||
*/
|
*/
|
||||||
getEntries(): IterableIterator<[string, { [quality: string]: number }]> {
|
getEntries(): IterableIterator<[string, ItemCountWithQuality]> {
|
||||||
return this._items.entries();
|
return this._items.entries();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ async function saveDatabase(
|
|||||||
export class ControllerPlugin extends BaseControllerPlugin {
|
export class ControllerPlugin extends BaseControllerPlugin {
|
||||||
items!: lib.ItemDatabase;
|
items!: lib.ItemDatabase;
|
||||||
itemUpdateRateLimiter!: lib.RateLimiter;
|
itemUpdateRateLimiter!: lib.RateLimiter;
|
||||||
itemsLastUpdate: Map<string, { [quality: string]: number }> = new Map();
|
itemsLastUpdate: Map<string, lib.ItemCountWithQuality> = new Map();
|
||||||
subscribedControlLinks!: Set<ControlConnection>;
|
subscribedControlLinks!: Set<ControlConnection>;
|
||||||
doleMagicId!: ReturnType<typeof setInterval>;
|
doleMagicId!: ReturnType<typeof setInterval>;
|
||||||
neuralDole!: dole.NeuralDole;
|
neuralDole!: dole.NeuralDole;
|
||||||
|
|||||||
Reference in new issue
Block a user