library.alc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. include "primitives.alh"
  2. Element function export_node(model_name : String, model_reference : Element):
  3. log("Export to " + model_name)
  4. Element splitted
  5. splitted = string_split(model_name, "/")
  6. Integer length
  7. length = list_len(splitted) - 1
  8. Integer counter_i
  9. counter_i = 0
  10. Element current
  11. current = dict_read(read_root(), "__hierarchy")
  12. while(counter_i < length):
  13. if (bool_not(dict_in(current, splitted[counter_i]))):
  14. // Create the new node
  15. dict_add(current, splitted[counter_i], create_node())
  16. dict_add(current[splitted[counter_i]], "__hierarchy_node", create_node())
  17. // Read out newly created element
  18. current = current[splitted[counter_i]]
  19. counter_i = counter_i + 1
  20. // current now contains the place where we should add the element
  21. if (bool_not(dict_in(current, splitted[length]))):
  22. dict_add(current, splitted[length], model_reference)
  23. else:
  24. log(("Could not export to " + model_name) + ": already in use!")
  25. return model_reference!
  26. Element function import_node(model_name : String):
  27. Element splitted
  28. splitted = string_split(model_name, "/")
  29. Integer length
  30. length = list_len(splitted)
  31. Integer counter_i
  32. counter_i = 0
  33. Element current
  34. current = dict_read(read_root(), "__hierarchy")
  35. while (counter_i < length):
  36. if dict_in(current, splitted[counter_i]):
  37. current = current[splitted[counter_i]]
  38. counter_i = counter_i + 1
  39. else:
  40. return read_root()!
  41. return current!