mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Compress clipboard data
Copy: Remove unneeded fields. Paste: Verify required fields are present.
This commit is contained in:
parent
1b8e3716f0
commit
fe021b1f0e
@ -34,7 +34,14 @@ export class Blueprint {
|
|||||||
* Serialize
|
* Serialize
|
||||||
*/
|
*/
|
||||||
serialize() {
|
serialize() {
|
||||||
return this.serializer.serializeEntityArray(this.entities);
|
let data = this.serializer.serializeEntityArray(this.entities);
|
||||||
|
// Remove unneeded fields
|
||||||
|
for (let i = 0; i < data.length; ++i) {
|
||||||
|
const entry = data[i];
|
||||||
|
delete entry.uid;
|
||||||
|
delete entry.components.WiredPins;
|
||||||
|
}
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,6 +66,10 @@ export class Blueprint {
|
|||||||
if (value.components == undefined || value.components.StaticMapEntity == undefined) {
|
if (value.components == undefined || value.components.StaticMapEntity == undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const staticData = value.components.StaticMapEntity;
|
||||||
|
if (staticData.code == undefined || staticData.origin == undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const result = new SerializerInternal().deserializeEntity(root, value);
|
const result = new SerializerInternal().deserializeEntity(root, value);
|
||||||
if (typeof result === "string") {
|
if (typeof result === "string") {
|
||||||
throw new Error(result);
|
throw new Error(result);
|
||||||
|
@ -10,10 +10,10 @@ import { Blueprint } from "../../blueprint";
|
|||||||
import { enumMouseButton } from "../../camera";
|
import { enumMouseButton } from "../../camera";
|
||||||
import { KEYMAPPINGS } from "../../key_action_mapper";
|
import { KEYMAPPINGS } from "../../key_action_mapper";
|
||||||
import { BaseHUDPart } from "../base_hud_part";
|
import { BaseHUDPart } from "../base_hud_part";
|
||||||
import { Entity } from "../../entity";
|
|
||||||
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
||||||
import { globalConfig } from "../../../core/config";
|
import { globalConfig } from "../../../core/config";
|
||||||
import { paste } from "../../../core/clipboard_paste";
|
import { paste } from "../../../core/clipboard_paste";
|
||||||
|
import { compressX64, decompressX64 } from "../../../core/lzstring";
|
||||||
|
|
||||||
const copy = require("clipboard-copy");
|
const copy = require("clipboard-copy");
|
||||||
|
|
||||||
@ -223,7 +223,7 @@ export class HUDBlueprintPlacer extends BaseHUDPart {
|
|||||||
const serializedBP = this.currentBlueprint.get().serialize();
|
const serializedBP = this.currentBlueprint.get().serialize();
|
||||||
try {
|
try {
|
||||||
const json = JSON.stringify(serializedBP);
|
const json = JSON.stringify(serializedBP);
|
||||||
await copy(json);
|
await copy(compressX64(json));
|
||||||
this.root.soundProxy.playUi(SOUNDS.copy);
|
this.root.soundProxy.playUi(SOUNDS.copy);
|
||||||
logger.debug("Copied blueprint to clipboard");
|
logger.debug("Copied blueprint to clipboard");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -239,7 +239,7 @@ export class HUDBlueprintPlacer extends BaseHUDPart {
|
|||||||
let json;
|
let json;
|
||||||
try {
|
try {
|
||||||
let data = await paste();
|
let data = await paste();
|
||||||
json = JSON.parse(data);
|
json = JSON.parse(decompressX64(data.trim()));
|
||||||
logger.debug("Received data from clipboard");
|
logger.debug("Received data from clipboard");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error("Paste from clipboard failed:", e.message);
|
logger.error("Paste from clipboard failed:", e.message);
|
||||||
|
Loading…
Reference in New Issue
Block a user