From 2cd78ceaf06376c5cc9b8c810f4a9b8bc8e60c72 Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Thu, 17 Nov 2022 18:33:34 +0800 Subject: [PATCH] Parse [VERTICES] --- api/s25_vertices.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/api/s25_vertices.py b/api/s25_vertices.py index f9a5cc7..d6a73e8 100644 --- a/api/s25_vertices.py +++ b/api/s25_vertices.py @@ -78,3 +78,29 @@ def delete_vertex(name: str, cs: ChangeSet) -> ChangeSet: result.redo_cs |= g_delete_prefix result.undo_cs |= g_add_prefix return execute_command(name, result) + + +def inp_in_vertex(section: list[str]) -> ChangeSet: + vertices: dict[str, list[dict[str, float]]] = {} + + for s in section: + tokens = s.split() + if tokens[0] not in vertices: + vertices[tokens[0]] = [] + vertices[tokens[0]].append({'x': float(tokens[1]), 'y': float(tokens[2])}) + + cs = ChangeSet() + for link, coords in vertices.items(): + cs.append(g_add_prefix | {'type': 'vertex', 'link' : link, 'coords' : coords}) + return cs + + +def inp_out_vertex(name: str) -> list[str]: + lines = [] + objs = read_all(name, f"select * from vertices order by _order") + for obj in objs: + link = obj['link'] + x = obj['x'] + y = obj['y'] + lines.append(f"{link} {x} {y}") + return lines