From c59c780743aa46e1d822ee8b1d34a72ba3fc2461 Mon Sep 17 00:00:00 2001 From: Rakuzan Date: Tue, 20 Feb 2024 18:09:36 +0100 Subject: [PATCH 1/3] add ability to dump only islands with players --- ikabot/function/dumpWorld.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/ikabot/function/dumpWorld.py b/ikabot/function/dumpWorld.py index 69ca4395..46bfa3d5 100644 --- a/ikabot/function/dumpWorld.py +++ b/ikabot/function/dumpWorld.py @@ -83,6 +83,7 @@ def dumpWorld(session, event, stdin_fd, predetermined_input): shallow = choice in ["y", "Y"] coords = None radius = None + non_empty_islands = False if not shallow: print("Do you want to only dump a part of the map? (Y|N)") choice = read(values=["y", "Y", "n", "N"]) @@ -92,6 +93,9 @@ def dumpWorld(session, event, stdin_fd, predetermined_input): coords = (int(coords[0]), int(coords[1])) print("Type in a max distance from the center point: (default = 15)") radius = read(min=0, max=200, digit=True, default=15) + print("Do you want to only dump islands with at least 1 town? (Y|N)") + choice = read(values=["y", "Y", "n", "N"]) + non_empty_islands = choice in ["y", "Y"] thread = threading.Thread(target=update_terminal, args=(shared_data,)) thread.start() @@ -99,7 +103,9 @@ def dumpWorld(session, event, stdin_fd, predetermined_input): info = _("\nDumped world data\n") setInfoSignal(session, info) - dump_path = do_it(session, waiting_time, coords, radius, shallow) + dump_path = do_it( + session, waiting_time, coords, radius, shallow, non_empty_islands + ) shared_data[3].set() shared_data[4].acquire() @@ -126,7 +132,7 @@ def dumpWorld(session, event, stdin_fd, predetermined_input): return -def do_it(session, waiting_time, coords, radius, shallow): +def do_it(session, waiting_time, coords, radius, shallow, non_empty_islands): """ Parameters ---------- @@ -272,6 +278,8 @@ def do_it(session, waiting_time, coords, radius, shallow): island_id = int(island["id"]) x = int(island["x"]) y = int(island["y"]) + if non_empty_islands and not int(island["players"]): + continue if ( coords and radius @@ -294,15 +302,13 @@ def do_it(session, waiting_time, coords, radius, shallow): # scan each island all_island = sorted(all_island) - dump_islands(shared_data, all_island, waiting_time, session) - update_status("Got {} individual islands".format(len(all_island)), 100, 100, True) + name_suffix = "_partial" if (radius >= 0 and coords) or non_empty_islands else "" + dump_name = dump_name.replace(".json.gz", name_suffix) + ".json.gz" update_status("Dumping data to {}".format(dump_path + dump_name), 100, 100, True) - dump(shared_data[5], dump_path, dump_name) - return dump_path + dump_name From 915ab6d85ea347a7e7bc0a6cf930a5b58d205076 Mon Sep 17 00:00:00 2001 From: Rakuzan Date: Tue, 20 Feb 2024 18:37:40 +0100 Subject: [PATCH 2/3] add a way to skip limiting scan by area in partial world dump --- ikabot/function/dumpWorld.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/ikabot/function/dumpWorld.py b/ikabot/function/dumpWorld.py index 46bfa3d5..ba2a8c46 100644 --- a/ikabot/function/dumpWorld.py +++ b/ikabot/function/dumpWorld.py @@ -88,11 +88,15 @@ def dumpWorld(session, event, stdin_fd, predetermined_input): print("Do you want to only dump a part of the map? (Y|N)") choice = read(values=["y", "Y", "n", "N"]) if choice in ["y", "Y"]: - print("Type in a center point (x,y):") - coords = read().replace("(", "").replace(")", "").split(",") - coords = (int(coords[0]), int(coords[1])) - print("Type in a max distance from the center point: (default = 15)") - radius = read(min=0, max=200, digit=True, default=15) + print('Type in a center point (x,y): (type "skip" to skip this step)') + input = read() + if input.strip().lower() != "skip": + coords = input.replace("(", "").replace(")", "").split(",") + coords = (int(coords[0]), int(coords[1])) + print( + "Type in a max distance from the center point: (default = 15)" + ) + radius = read(min=0, max=200, digit=True, default=15) print("Do you want to only dump islands with at least 1 town? (Y|N)") choice = read(values=["y", "Y", "n", "N"]) non_empty_islands = choice in ["y", "Y"] @@ -305,7 +309,9 @@ def do_it(session, waiting_time, coords, radius, shallow, non_empty_islands): dump_islands(shared_data, all_island, waiting_time, session) update_status("Got {} individual islands".format(len(all_island)), 100, 100, True) - name_suffix = "_partial" if (radius >= 0 and coords) or non_empty_islands else "" + name_suffix = ( + "_partial" if (coords and radius and radius >= 0) or non_empty_islands else "" + ) dump_name = dump_name.replace(".json.gz", name_suffix) + ".json.gz" update_status("Dumping data to {}".format(dump_path + dump_name), 100, 100, True) dump(shared_data[5], dump_path, dump_name) From 278d8ba7c0e345fec13a02320e907872b30e963e Mon Sep 17 00:00:00 2001 From: Rakuzan Date: Tue, 20 Feb 2024 18:44:24 +0100 Subject: [PATCH 3/3] add information to json file whether the world dump is partial or not --- ikabot/function/dumpWorld.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ikabot/function/dumpWorld.py b/ikabot/function/dumpWorld.py index ba2a8c46..9dd2f4a8 100644 --- a/ikabot/function/dumpWorld.py +++ b/ikabot/function/dumpWorld.py @@ -155,6 +155,9 @@ def do_it(session, waiting_time, coords, radius, shallow, non_empty_islands): """ shared_data[2] = time.time() + partial = ( + True if (coords and radius and radius >= 0) or non_empty_islands else False + ) world = { "name": "s" + str(session.mundo) + "-" + str(session.servidor), "self_name": session.username, @@ -162,6 +165,7 @@ def do_it(session, waiting_time, coords, radius, shallow, non_empty_islands): "dump_end_date": 0, "islands": [], "shallow": shallow, + "partial": partial, } shared_data.append(world) # scan 0 to 50 x and y @@ -309,9 +313,7 @@ def do_it(session, waiting_time, coords, radius, shallow, non_empty_islands): dump_islands(shared_data, all_island, waiting_time, session) update_status("Got {} individual islands".format(len(all_island)), 100, 100, True) - name_suffix = ( - "_partial" if (coords and radius and radius >= 0) or non_empty_islands else "" - ) + name_suffix = "_partial" if partial else "" dump_name = dump_name.replace(".json.gz", name_suffix) + ".json.gz" update_status("Dumping data to {}".format(dump_path + dump_name), 100, 100, True) dump(shared_data[5], dump_path, dump_name)