
--init

local modpath = minetest.get_modpath("eye_spy")

dofile(modpath .. "/functions.lua")
dofile(modpath .. "/target.lua")
dofile(modpath .. "/enrichers.lua")
dofile(modpath .. "/render.lua")
dofile(modpath .. "/preview.lua")
dofile(modpath .. "/ui.lua")

if minetest.get_modpath("default") then
  cg = "minetest_game"
elseif minetest.get_modpath("mcl_core") then
  cg = "mineclone"

  if minetest.get_modpath("vl_legacy") then
    cgs = "voxelibre"
  else
    cgs = "mineclonia"
  end
end

minetest.register_on_joinplayer(function(player)
  local meta = player:get_meta()
  meta:set_string("es_last_obj", "")
  meta:set_int("es_last_health", -1)

  eye_spy.ensure_player_defaults(player)

  local state = eye_spy.get_player_state(player)
  state.timer = 0
  state.edit_mode = false

  eye_spy.edit_mode[player:get_player_name()] = false
end)

minetest.register_on_leaveplayer(function(player)
  if eye_spy.ui_drafts then
    eye_spy.ui_drafts[player:get_player_name()] = nil
  end

  eye_spy.remove_huds(player)
  eye_spy.state.players[player:get_player_name()] = nil
end)

minetest.register_globalstep(function(dtime)
  eye_spy.step(dtime)
end)
