extends Node


static func map_value_to_item(data, item, value_name: StringName):
    var meta = item.get_meta(value_name, '')
    if meta == '':
        return
    if not (meta is String):
        return
    var paths: = Array()
    tools.map_solid_to_array(meta, paths)
    var ret_val: = [null, false, 0]
    var paths_copy = paths.duplicate(true)
    tools.get_value_by_path(data, paths, ret_val)
    if ret_val[1]:
        item.set(value_name, ret_val[0])
    else:
        push_error('не найден путь %s (%s) для $%s.%s (%s)' % [paths_copy, ret_val[2], item.name, value_name, item.tooltip_text])


static func map_error_codes_to_item(data, item, value_name: StringName, value_init: int):
    var metas = item.get_meta(value_name, '')
    if not (metas is Array):
        return
    var paths: = Array()
    var values: = Array()
    for meta in metas:
        tools.map_solid_to_array(meta, paths)
        var ret_val: = [null, false, 0]
        var paths_copy = paths.duplicate(true)
        tools.get_value_by_path(data, paths, ret_val)
        if ret_val[1]:
            values.append(ret_val[0])
        else:
            push_error('не найден путь %s(%s) для $%s.%s (%s)' % [paths_copy, ret_val[2], item.name, value_name, item.tooltip_text])
    if values.size() == metas.size():
        var test_res = 1 if values.count(true) == values.size() else 2
        item.set(value_name, test_res)
    else:
        item.set(value_name, value_init)
