From c3fe42cd30f754422dbf2ea3a9919031f5a9299c Mon Sep 17 00:00:00 2001 From: ghostlyzsh Date: Sat, 6 Apr 2024 20:04:04 -0500 Subject: [PATCH] ship editor saving finished, but no api server --- .../src/pages/ShipEditor.svelte | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/starkingdoms-client/src/pages/ShipEditor.svelte b/starkingdoms-client/src/pages/ShipEditor.svelte index 152369483fb0a067c109caf1be74dbf454e4f96f..e58c7e6d70ce2e14f2422768f0024d9af55a9875 100644 --- a/starkingdoms-client/src/pages/ShipEditor.svelte +++ b/starkingdoms-client/src/pages/ShipEditor.svelte @@ -264,13 +264,13 @@ }); if (children[0] !== null) { - place(x, y + 1, children[0], rotation); + place(x, y + 1, children[0], (rotation + 2) % 4); } if (children[1] !== null) { place(x + 1, y, children[1], (rotation + 1) % 4); } if (children[2] !== null) { - place(x, y - 1, children[2], (rotation + 2) % 4); + place(x, y - 1, children[2], rotation); } if (children[3] !== null) { place(x - 1, y, children[3], (rotation + 3) % 4); @@ -296,10 +296,41 @@ }, 5000); } + function save_recursive(x: number, y: number) { + let [part_type, rotation] = grid.get(x)!.get(y)!; + let children = [null, null, null, null]; + if (part_type == PartType.Hearty) { + if (grid.get(x+1)?.get(y)?.[1] == 1) { // right + children[1] = save_recursive(x+1, y); + } + if (grid.get(x-1)?.get(y)?.[1] == 3) { // left + children[3] = save_recursive(x-1, y); + } + if (grid.get(x)?.get(y-1)?.[1] == 0) { // up + children[2] = save_recursive(x, y-1); + } + if (grid.get(x)?.get(y+1)?.[1] == 2) { // down + children[0] = save_recursive(x, y+1); + } + } else if (part_type == PartType.Cargo) {} + + return {part_type: part_type, children: children}; + } + function save_btn() { if (confirm_save) { // todo: @ghostly you need to turn this back into a savefile and then call pack_partial on it - window.location.href = "/"; + let children = save_recursive(0, 0).children; + let unused_modules = []; + for (let [part_type, value] of part_counts) { + let unused = value.available - value.used; + if (unused != 0 && part_type != PartType.Hearty) { + unused_modules.push([part_type, unused]); + } + } + let save_data = { children: children, unused_modules: unused_modules }; + console.log(save_data); + //window.location.href = "/"; } confirm_save = !confirm_save; setTimeout(() => { @@ -368,7 +399,6 @@ } function keydown(e: KeyboardEvent) { - console.log("here"); if (e.code == "KeyQ") { rotation = (rotation - 1) % 4; }