test.lua 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. -- Test, and example of how to use the map API
  2. require("map")
  3. local function slowLoadMap(map, chunkTime, func, funcDone)
  4. TestMapUpdateSched = nil
  5. local loadNextChunk
  6. local x, y = 1, 1
  7. loadNextChunk = function()
  8. func(map, x, y)
  9. if x>=map.xChunks then
  10. x = 1
  11. y = y+1
  12. if y > map.yChunks then
  13. schedule(chunkTime, funcDone)
  14. return
  15. end
  16. else
  17. x = x+1
  18. end
  19. TestMapUpdateSched = schedule(chunkTime, loadNextChunk)
  20. end
  21. loadNextChunk()
  22. end
  23. function DeleteTestMap()
  24. talk("Deleting map")
  25. schedule(1000, slowLoadMap, TestMap, 50, UnloadMapChunk, function()
  26. TestMap = nil
  27. talk("Done deleting map")
  28. end)
  29. end
  30. function TestGenerateMap()
  31. if not exists("TestMap") then
  32. talk("Creating map object")
  33. TestMap = CreateMap(
  34. vector{0, 0, 0}, -- position
  35. vector{1, 1, 0.1}, -- scale
  36. 16, -- cubeWidth
  37. 0.5, -- cubeHeight
  38. "modter/pixelated", -- printName
  39. 16 -- chunkSize
  40. )
  41. end
  42. talk("Importing map data")
  43. SetMapDataFile(TestMap, 256, 256, "Add-ons/Support_MapGeneration/maps/hawaii256.map")
  44. talk("Building map")
  45. schedule(1000, slowLoadMap, TestMap, 50, UpdateMapChunk, function() talk("Done updating map") end)
  46. end
  47. function StopMap()
  48. if TestMapUpdateSched then
  49. talk("Stopping map generation")
  50. cancel(TestMapUpdateSched)
  51. TestMapUpdateSched = nil
  52. else
  53. talk("No map generation in progress")
  54. end
  55. end
  56. StopMap()
  57. TestGenerateMap()
  58. --DeleteTestMap()