diff --git a/config-serializer/Serializable.ts b/config-serializer/Serializable.ts index ad85f76b..52f6ffcd 100644 --- a/config-serializer/Serializable.ts +++ b/config-serializer/Serializable.ts @@ -16,9 +16,9 @@ abstract class Serializable { } fromJsObject(jsObject: any): Serializable { - let indentation = new Array(Serializable.depth + 1).join(' '); let isArray = this instanceof ClassArray; - this.dump(`${indentation}${this.constructor.name}.fromJsObject: ${this.strintifyJsObject(jsObject)}` + (isArray ? '\n' : ` => `)); + this.dumpMethodName('fromJsObject'); + this.dump(`${this.strintifyJsObject(jsObject)}` + (isArray ? '\n' : ` => `)); Serializable.depth++; let value = this._fromJsObject(jsObject); Serializable.depth--; @@ -29,9 +29,9 @@ abstract class Serializable { } fromBinary(buffer: UhkBuffer): Serializable { - let indentation = new Array(Serializable.depth + 1).join(' '); let isArray = this instanceof ClassArray; - this.dump(`${indentation}${this.constructor.name}.fromBinary: [`); + this.dumpMethodName('fromBinary'); + this.dump('['); Serializable.depth++; buffer.enableDump = Serializable.enableDump; let value = this._fromBinary(buffer); @@ -44,9 +44,9 @@ abstract class Serializable { } toJsObject(): any { - let indentation = new Array(Serializable.depth + 1).join(' '); let isArray = this instanceof ClassArray; - this.dump(`${indentation}${this.constructor.name}.toJsObject: ${this}` + (isArray ? '\n' : ` => `)); + this.dumpMethodName('toJsObject'); + this.dump(`${this}` + (isArray ? '\n' : ` => `)); Serializable.depth++; let value = this._toJsObject(); Serializable.depth--; @@ -57,9 +57,9 @@ abstract class Serializable { } toBinary(buffer: UhkBuffer): void { - let indentation = new Array(Serializable.depth + 1).join(' '); let isArray = this instanceof ClassArray; - this.dump(`${indentation}${this.constructor.name}.toBinary: ${this} => ['`); + this.dumpMethodName('toBinary'); + this.dump(`${this} => ['`); Serializable.depth++; buffer.enableDump = Serializable.enableDump; let value = this._toBinary(buffer); @@ -76,9 +76,14 @@ abstract class Serializable { abstract _toJsObject(): any; abstract _toBinary(buffer: UhkBuffer): void; - dump(value) { + private dump(value) { if (Serializable.enableDump) { process.stdout.write(value); } } + + private dumpMethodName(methodName: string) { + let indentation = new Array(Serializable.depth + 1).join(' '); + this.dump(`${indentation}${this.constructor.name}.${methodName}: `); + } }