mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-09 16:21:51 +00:00
Replace Object#hasOwnProperty with Object.hasOwn
Change most, but not all usages. This is mostly to please the linter, but Object.hasOwn is also slightly shorter, especially when compared to the proper form, Object.prototype.hasOwnProperty...
This commit is contained in:
parent
9876d5305b
commit
d6390e88a4
@ -69,7 +69,7 @@ export class StateManager {
|
|||||||
|
|
||||||
// Remove all references
|
// Remove all references
|
||||||
for (const stateKey in this.currentState) {
|
for (const stateKey in this.currentState) {
|
||||||
if (this.currentState.hasOwnProperty(stateKey)) {
|
if (Object.hasOwn(this.currentState, stateKey)) {
|
||||||
delete this.currentState[stateKey];
|
delete this.currentState[stateKey];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -159,7 +159,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
return this.currentBaseRotationGeneral;
|
return this.currentBaseRotationGeneral;
|
||||||
}
|
}
|
||||||
const metaBuilding = this.currentMetaBuilding.get();
|
const metaBuilding = this.currentMetaBuilding.get();
|
||||||
if (metaBuilding && this.preferredBaseRotations.hasOwnProperty(metaBuilding.getId())) {
|
if (metaBuilding && Object.hasOwn(this.preferredBaseRotations, metaBuilding.getId())) {
|
||||||
return this.preferredBaseRotations[metaBuilding.getId()];
|
return this.preferredBaseRotations[metaBuilding.getId()];
|
||||||
} else {
|
} else {
|
||||||
return this.currentBaseRotationGeneral;
|
return this.currentBaseRotationGeneral;
|
||||||
|
|||||||
@ -224,8 +224,8 @@ export class GameRoot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Finally free all properties
|
// Finally free all properties
|
||||||
for (let prop in this) {
|
for (const prop in this) {
|
||||||
if (this.hasOwnProperty(prop)) {
|
if (Object.hasOwn(this, prop)) {
|
||||||
delete this[prop];
|
delete this[prop];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -375,7 +375,7 @@ export class ApplicationSettings extends ReadWriteProxy {
|
|||||||
* @param {string} key
|
* @param {string} key
|
||||||
*/
|
*/
|
||||||
getSetting(key) {
|
getSetting(key) {
|
||||||
assert(this.getAllSettings().hasOwnProperty(key), "Setting not known: " + key);
|
assert(Object.hasOwn(this.getAllSettings(), key), "Setting not known: " + key);
|
||||||
return this.getAllSettings()[key];
|
return this.getAllSettings()[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,11 +18,11 @@ import {
|
|||||||
TypeNumber,
|
TypeNumber,
|
||||||
TypePair,
|
TypePair,
|
||||||
TypePositiveInteger,
|
TypePositiveInteger,
|
||||||
|
TypePositiveIntegerOrString,
|
||||||
TypePositiveNumber,
|
TypePositiveNumber,
|
||||||
TypeString,
|
TypeString,
|
||||||
TypeStructuredObject,
|
TypeStructuredObject,
|
||||||
TypeVector,
|
TypeVector,
|
||||||
TypePositiveIntegerOrString,
|
|
||||||
} from "./serialization_data_types";
|
} from "./serialization_data_types";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -239,12 +239,9 @@ export class BasicSerializableObject {
|
|||||||
*/
|
*/
|
||||||
export function serializeSchema(obj, schema, mergeWith = {}) {
|
export function serializeSchema(obj, schema, mergeWith = {}) {
|
||||||
for (const key in schema) {
|
for (const key in schema) {
|
||||||
if (!obj.hasOwnProperty(key)) {
|
if (!Object.hasOwn(obj, key)) {
|
||||||
logger.error("Invalid schema, property", key, "does not exist on", obj, "(schema=", schema, ")");
|
logger.error("Invalid schema, property", key, "does not exist on", obj, "(schema=", schema, ")");
|
||||||
assert(
|
assert(false, "serialization: invalid schema, property does not exist on object: " + key);
|
||||||
obj.hasOwnProperty(key),
|
|
||||||
"serialization: invalid schema, property does not exist on object: " + key
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (!schema[key]) {
|
if (!schema[key]) {
|
||||||
assert(false, "Invalid schema (bad key '" + key + "'): " + JSON.stringify(schema));
|
assert(false, "Invalid schema (bad key '" + key + "'): " + JSON.stringify(schema));
|
||||||
@ -292,7 +289,7 @@ export function deserializeSchema(obj, schema, data, baseclassErrorResult = null
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const key in schema) {
|
for (const key in schema) {
|
||||||
if (!data.hasOwnProperty(key)) {
|
if (!Object.hasOwn(data, key)) {
|
||||||
logger.error("Data", data, "does not contain", key, "(schema:", schema, ")");
|
logger.error("Data", data, "does not contain", key, "(schema:", schema, ")");
|
||||||
return "Missing key in schema: " + key + " of class " + obj.constructor.name;
|
return "Missing key in schema: " + key + " of class " + obj.constructor.name;
|
||||||
}
|
}
|
||||||
@ -325,7 +322,7 @@ export function deserializeSchema(obj, schema, data, baseclassErrorResult = null
|
|||||||
*/
|
*/
|
||||||
export function verifySchema(schema, data) {
|
export function verifySchema(schema, data) {
|
||||||
for (const key in schema) {
|
for (const key in schema) {
|
||||||
if (!data.hasOwnProperty(key)) {
|
if (!Object.hasOwn(data, key)) {
|
||||||
logger.error("Data", data, "does not contain", key, "(schema:", schema, ")");
|
logger.error("Data", data, "does not contain", key, "(schema:", schema, ")");
|
||||||
return "verify: missing key required by schema in stored data: " + key;
|
return "verify: missing key required by schema in stored data: " + key;
|
||||||
}
|
}
|
||||||
@ -352,7 +349,7 @@ export function extendSchema(base, newOne) {
|
|||||||
/** @type {Schema} */
|
/** @type {Schema} */
|
||||||
const result = Object.assign({}, base);
|
const result = Object.assign({}, base);
|
||||||
for (const key in newOne) {
|
for (const key in newOne) {
|
||||||
if (result.hasOwnProperty(key)) {
|
if (Object.hasOwn(result, key)) {
|
||||||
logger.error("Extend schema got duplicate key:", key);
|
logger.error("Extend schema got duplicate key:", key);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user