file_functions.lua 895 B

123456789101112131415161718192021222324252627282930313233
  1. function kobo.load()
  2. local file = io.open(core.get_worldpath() .. '/data', 'r')
  3. if file then
  4. local data = core.deserialize(file:read('*a'))
  5. file:close()
  6. kobo.resources = data.resources
  7. kobo.bases = data.bases
  8. kobo.goblins = data.goblins or {}
  9. else
  10. kobo.resources = {} --food, lumber, metal, stone, xp, research points
  11. kobo.bases = {}
  12. local resources = {}
  13. resources.xp = 0
  14. resources.wave = 0
  15. resources.food = 100
  16. resources.lumber = 20
  17. resources.stone = 0
  18. resources.metal = 0
  19. resources.nearest_base = {}
  20. kobo.goblins = resources
  21. end
  22. end
  23. function kobo.save()
  24. local save = {}
  25. save.resources = kobo.resources
  26. save.bases = kobo.bases
  27. save.goblins = kobo.goblins
  28. local file = io.open(core.get_worldpath() .. '/data', 'w')
  29. file:write(core.serialize(save))
  30. file:close()
  31. end