library.alc 1.3 KB

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