Browse Source

fix tower hexes deserialize thing

master
Nicholas Hayashi 4 years ago
parent
commit
d7a622df39
  1. 11
      main.lua
  2. 5
      src/game.lua
  3. 2
      src/mob.lua
  4. 2
      src/tower.lua

11
main.lua

@ -44,7 +44,7 @@ require "src/tower"
function main_action(self) function main_action(self)
self"hex_backdrop""rotate".angle = math.wrapf(self"hex_backdrop""rotate".angle - 0.002 * am.delta_time, math.pi*2)
self"hex_backdrop""rotate".angle = math.wrapf(self"hex_backdrop""rotate".angle - 0.005 * am.delta_time, math.pi*2)
end end
function make_main_scene_toolbelt() function make_main_scene_toolbelt()
@ -54,23 +54,19 @@ function make_main_scene_toolbelt()
false, false,
false, false,
{ {
label = "new game",
texture = TEXTURES.NEW_GAME_HEX, texture = TEXTURES.NEW_GAME_HEX,
action = function() end
action = function() game_init() end
}, },
{ {
label = "load game",
texture = TEXTURES.LOAD_GAME_HEX, texture = TEXTURES.LOAD_GAME_HEX,
action = function() game_init(am.load_state("save", "json")) end action = function() game_init(am.load_state("save", "json")) end
}, },
false, false,
{ {
label = "settings",
texture = TEXTURES.SETTINGS_HEX, texture = TEXTURES.SETTINGS_HEX,
action = function() end action = function() end
}, },
{ {
label = "about",
texture = TEXTURES.ABOUT_HEX, texture = TEXTURES.ABOUT_HEX,
action = function() end action = function() end
}, },
@ -78,7 +74,6 @@ function make_main_scene_toolbelt()
false, false,
false, false,
{ {
label = "map editor",
texture = TEXTURES.MAP_EDITOR_HEX, texture = TEXTURES.MAP_EDITOR_HEX,
action = function() log("map editor not implemented") end action = function() log("map editor not implemented") end
}, },
@ -167,8 +162,6 @@ function main_scene()
return group return group
end end
win.scene = am.group()
win.scene = main_scene() win.scene = main_scene()
--game_init()
noglobals() noglobals()

5
src/game.lua

@ -146,6 +146,11 @@ local function game_deserialize(json_string)
if t then if t then
new_state.towers[i] = tower_deserialize(t) new_state.towers[i] = tower_deserialize(t)
for _,h in pairs(new_state.towers[i].hexes) do
local tile = hex_map_get(new_state.map, h.x, h.y)
tile.elevation = tile.elevation + new_state.towers[i].height
end
-- @STATEFUL, shouldn't be done here -- @STATEFUL, shouldn't be done here
new_state.world:append(new_state.towers[i].node) new_state.world:append(new_state.towers[i].node)
end end

2
src/mob.lua

@ -100,7 +100,7 @@ function make_mob_node(mob_type, mob)
if mob_type == MOB_TYPE.BEEPER then if mob_type == MOB_TYPE.BEEPER then
return am.group{ return am.group{
am.rotate(state.time)
am.rotate(am.current_time()) -- state.time is not garunteed to be set when deserializing
^ pack_texture_into_sprite(TEXTURES.MOB_BEEPER, MOB_SIZE, MOB_SIZE), ^ pack_texture_into_sprite(TEXTURES.MOB_BEEPER, MOB_SIZE, MOB_SIZE),
am.translate(0, -10) am.translate(0, -10)
^ healthbar ^ healthbar

2
src/tower.lua

@ -230,8 +230,8 @@ end
function tower_deserialize(json_string) function tower_deserialize(json_string)
local tower = entity_basic_json_parse(json_string) local tower = entity_basic_json_parse(json_string)
tower.hexes = {}
for i,h in pairs(tower.hexes) do for i,h in pairs(tower.hexes) do
log(h)
tower.hexes[i] = vec2(tower.hexes[i][1], tower.hexes[i][2]) tower.hexes[i] = vec2(tower.hexes[i][1], tower.hexes[i][2])
end end

Loading…
Cancel
Save