diff options
| author | dam <dam@gudinoff> | 2022-02-07 01:59:25 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2022-02-07 01:59:25 +0000 |
| commit | 7931eadbdbf80b4c3b7388c114ff8accb1ea307c (patch) | |
| tree | bf9949c52c31e0cbe0c44276680a288ee30af9cb /logic | |
| parent | 9e96569d70660cb18b2d4669e6a71efcb4f863d6 (diff) | |
| download | surgery-log-7931eadbdbf80b4c3b7388c114ff8accb1ea307c.tar.zst surgery-log-7931eadbdbf80b4c3b7388c114ff8accb1ea307c.zip | |
Implement option sets.
Diffstat (limited to 'logic')
| -rw-r--r-- | logic/stage.gd | 233 |
1 files changed, 61 insertions, 172 deletions
diff --git a/logic/stage.gd b/logic/stage.gd index 0c2f97b..1352816 100644 --- a/logic/stage.gd +++ b/logic/stage.gd @@ -19,100 +19,7 @@ const OPTION_SETS_TREE_STRUCTURE := { } } -var option_sets := { - "thing": {}, - "place": { - "P0": null, - "P1": null, - "P2": null, - "xpto_01": null, - "xpto_02": null, - "xpto_03": null, - "xpto_04": null, - "xpto_05": null, - "xpto_06": null, - "xpto_07": null, - "xpto_08": null, - "xpto_09": null, - "xpto_10": null, - "xpto_11": null, - "xpto_12": null, - "xpto_13": null, - "xpto_14": null, - "xpto_15": null, - "xpto_16": null, - "xpto_17": null, - "xpto_18": null, - "xpto_19": null, - "xpto_20": null, - "xpto_21": null, - "xpto_22": null, - "xpto_23": null, - "xpto_24": null, - "xpto_25": null, - "xpto_26": null, - "xpto_27": null, - "xpto_28": null, - "xpto_29": null, - }, - "first_assistant": { - "FA0": null, - "FA1": null, - "FA2": null, - }, -# "anesthesia": { -# "AN0": null, -# "AN1": null, -# "AN2": null, -# }, - "type": { - "A": { - "sub_type": { - "aA": { - "sub_sub_type": { - "aaA": null, - "aaB": null, - "aaC": null, - }, - "pathology": { - "aaP0": null, - "aaP1": null, - "aaP2": null, - }, - "intervention": { - "aaI0": null, - "aaI1": null, - "aaI2": null, - }, - }, - "aB": { - "sub_sub_type": { - "abA": null, - "abB": null, - "abC": null, - }, - "pathology": { - "abP0": null, - "abP1": null, - "abP2": null, - }, - "intervention": { - "abI0": null, - "abI1": null, - "abI2": null, - }, - }, - }, - }, - "B": { - "sub_type": { - "bA": null, - "bB": null, - }, - }, - "C": null, - }, -} +var option_sets: Dictionary onready var process_id := get_node("controls/process_id") as LineEdit onready var surgery_id := get_node("controls/surgery_id") as LineEdit @@ -129,16 +36,7 @@ onready var is_urgency := get_node("controls/is_urgency") as Button onready var notes := get_node("controls/notes") as LineEdit onready var save_button := get_node("controls/save") as Button onready var discard_button := get_node("controls/discard") as Button -onready var option_sets_map := { - "place": place, - "anesthesia": anesthesia, - "first_assistant": first_assistant, - "type": type, - "sub_type": sub_type, - "sub_sub_type": sub_sub_type, - "pathology": pathology, - "intervention": intervention -} + func _init(): exclude_controls = ["date_picker", "save", "discard"] @@ -156,38 +54,31 @@ func _ready(): it.connect("focus_exited", it, "deselect") # Map option sets buttons. - # @DAM TEST defining he option_sets_map onready -# var option_sets_map := { -# "place": place, -# "anesthesia": anesthesia, -# "first_assistant": first_assistant, -# "type": type, -# "sub_type": sub_type, -# "sub_sub_type": sub_sub_type, -# "pathology": pathology, -# "intervention": intervention -# } + var option_sets_map := { + "place": place, + "anesthesia": anesthesia, + "first_assistant": first_assistant, + "type": type, + "sub_type": sub_type, + "sub_sub_type": sub_sub_type, + "pathology": pathology, + "intervention": intervention + } for key in option_sets_map: var button := option_sets_map[key].get_node("auto") as Button button.connect("pressed", self, "auto_populate", [key]) -func is_sub_dictionary(dictionary: Dictionary, key: String) -> bool: - return dictionary.has(key) && dictionary[key] is Dictionary - - func get_option_sets(field: String): var options: Array match field: "sub_type": - if option_sets["type"].get(type.text) != null: - options = option_sets["type"][type.text][field].keys() + options = option_sets.get("type", {}).get(type.text, {}).get(field, {}).keys() "sub_sub_type", "pathology", "intervention": - if option_sets["type"].get(type.text) != null && option_sets["type"][type.text]["sub_type"].get(sub_type.text) != null: - options = option_sets["type"][type.text]["sub_type"][sub_type.text][field].keys() + options = option_sets.get("type", {}).get(type.text, {}).get("sub_type", {}).get(sub_type.text, {}).get(field, {}).keys() _: - options = option_sets[field].keys() + options = option_sets.get(field, {}).keys() if options.size() == 0: options.append(OPTION_SETS_NOT_AVAILABLE) @@ -209,8 +100,9 @@ func auto_selected(index: int, field: String): func save_action(): self.visible = false - var staged_entry = get_stage() - gather_new_option_sets(staged_entry) + var staged_entry := get_stage() + gather_option_sets(staged_entry) + store_option_sets() emit_signal("save", staged_entry) @@ -257,6 +149,49 @@ func get_stage() -> Dictionary: return entry +func sanitize_option_sets(entry: Dictionary, blueprint: Dictionary = OPTION_SETS_TREE_STRUCTURE): + # Delete extra keys. + var keys_to_delete: Array + for key in entry: + if blueprint.has(key) == false: + keys_to_delete.append(key) + for key in keys_to_delete: + entry.erase(key) + + for key in blueprint: + # Add missing keys. + if typeof(entry.get(key)) != TYPE_DICTIONARY: + entry[key] = {} + # Process sub-keys + if blueprint[key] != null: + for sub_key in entry[key]: + if typeof(entry[key][sub_key]) != TYPE_DICTIONARY: + entry[key][sub_key] = {} + sanitize_option_sets(entry[key][sub_key], blueprint[key]) + + +func gather_option_sets(entry: Dictionary, target: Dictionary = option_sets, blueprint: Dictionary = OPTION_SETS_TREE_STRUCTURE): + for key in blueprint: + if target.get(key) == null: + target[key] = {} + + var value := (entry[key] as String).strip_edges() + if value == "" || value == OPTION_SETS_NOT_AVAILABLE: + continue + + if target[key].has(value) == false: + target[key][value] = null if blueprint[key] == null else {} + + if blueprint[key] != null: + gather_option_sets(entry, target[key][value], blueprint[key]) + + +func import_option_sets(file_path: String = OPTION_SETS_FILE_PATH): + load_option_sets(file_path) + sanitize_option_sets(option_sets) + store_option_sets() + + func load_option_sets(file_path: String = OPTION_SETS_FILE_PATH): var file := File.new() file.open(file_path, File.READ_WRITE) @@ -269,52 +204,6 @@ func load_option_sets(file_path: String = OPTION_SETS_FILE_PATH): option_sets = {} push_error("Failed to parse option sets file: '%s'.") - # @DAM Only do sanitize_option_sets_dict if file_path is no the default one. - sanitize_option_sets_dict(OPTION_SETS_TREE_STRUCTURE, option_sets) -# if file_path != OPTION_SETS_FILE_PATH: -# sanitize_option_sets() - - -func sanitize_option_sets_dict(blueprint: Dictionary, test: Dictionary): - for key in blueprint: - if test.get(key) == null: - test[key] = {} - if blueprint[key] != null: - for sub_value in test[key]: - if test[key][sub_value] == null: - test[key][sub_value] = {} - sanitize_option_sets_dict(blueprint[key], test[key][sub_value]) - - -func gather_new_option_sets(entry: Dictionary): - pass - # @DAM TODO WIP -# WIP WIP WIP - if entry["type"] != OPTION_SETS_NOT_AVAILABLE: - if option_sets["type"].has(entry["type"]) == false: - -# option_sets["type"][entry["type"]] = {} - - -func sanitize_option_sets(): - for key in OPTION_SETS_TREE_STRUCTURE: - if option_sets.get(key) == null: - option_sets[key] = {} - - for type_key in option_sets["type"]: - var type_value := option_sets["type"][type_key] as Dictionary - if type_value.get("sub_type") == null: - type_value["sub_type"] = {} - else: - for sub_type_key in type_value["sub_type"]: - var sub_type_value := type_value["sub_type"][sub_type_key] as Dictionary - if sub_type_value.get("sub_sub_type") == null: - sub_type_value["sub_sub_type"] = {} - if sub_type_value.get("pathology") == null: - sub_type_value["pathology"] = {} - if sub_type_value.get("intervention") == null: - sub_type_value["intervention"] = {} - func store_option_sets(file_path: String = OPTION_SETS_FILE_PATH): var file := File.new() |
