init.lua 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. local path = minetest.get_modpath("hivemind")
  2. --set namespace for hivemind functions
  3. hivemind = {}
  4. --------------
  5. ---hivemind Copyright 2020 Francisco "FreeLikeGNU" Athens
  6. --------------
  7. hivemind.version = "20200528"
  8. --https://notabug.org/freelikegnu/hivemind
  9. -- Strips any kind of escape codes (translation, colors) from a string
  10. -- https://github.com/minetest/minetest/blob/53dd7819277c53954d1298dfffa5287c306db8d0/src/util/string.cpp#L777
  11. function hivemind.strip_escapes(input)
  12. local s = function(idx) return input:sub(idx, idx) end
  13. local out = ""
  14. local i = 1
  15. while i <= #input do
  16. if s(i) == "\027" then -- escape sequence
  17. i = i + 1
  18. if s(i) == "(" then -- enclosed
  19. i = i + 1
  20. while i <= #input and s(i) ~= ")" do
  21. if s(i) == "\\" then
  22. i = i + 2
  23. else
  24. i = i + 1
  25. end
  26. end
  27. end
  28. else
  29. out = out .. s(i)
  30. end
  31. i = i + 1
  32. end
  33. --print(("%q -> %q"):format(input, out))
  34. return out
  35. end
  36. local function strip_escapes(input)
  37. hivemind.strip_escapes(input)
  38. end
  39. local function print_s(input)
  40. print(hivemind.strip_escapes(input))
  41. end
  42. local S = minetest.get_translator("hivemind")
  43. local hivemind_version = hivemind.version
  44. minetest.log("action", "the [MOD] hivemind " ..hivemind_version.. " is awakened....")
  45. print_s(S("Please report issues at https://notabug.org/freelikegnu/hivemind/issues "))
  46. print_s(S(" The heart of hivemind beats with the rhythm of encounters, the mind is shared among entities."))
  47. dofile(path .. "/hivemind.lua")