Browse Source

fix some menu buggies

master
Nicholas Hayashi 3 years ago
parent
commit
8169c91e5c
  1. 26
      main.lua
  2. 121
      src/game.lua
  3. 82
      src/map-editor.lua

26
main.lua

@ -1,4 +1,5 @@
-- @TODO
-- @TODO @TODO @TODO @TODO
-- main
-- -- scale menu hexes to window size, right now they look bad on smaller resolutions
@ -164,7 +165,7 @@ function main_action(self)
end
end
function make_scene_menu(scene_options)
function make_scene_menu(scene_options, tag)
-- calculate the dimensions of the whole grid
local spacing = 150
@ -178,7 +179,7 @@ function make_scene_menu(scene_options)
-- generate a map of hexagons (the menu is made up of two rows of hexes) and populate their locations with buttons from the provided options
local map = hex_rectangular_map(grid_width, grid_height, HEX_ORIENTATION.POINTY)
local group = am.group()
local group = am.group():tag(tag or "menu")
local option_index = 1
for i,_ in pairs(map) do
for j,_ in pairs(map[i]) do
@ -228,7 +229,7 @@ function make_scene_menu(scene_options)
end
function main_scene(do_backdrop, do_logo)
local group = am.group()
local group = am.group():tag"main_scene"
if do_backdrop then
local map = hex_hexagonal_map(30)
@ -292,8 +293,7 @@ function main_scene(do_backdrop, do_logo)
{
texture = TEXTURES.NEW_GAME_HEX,
action = function()
win.scene:remove"map_editor"
win.scene:remove"menu"
win.scene:remove"main_scene"
game_init()
end
},
@ -306,7 +306,7 @@ function main_scene(do_backdrop, do_logo)
local save = am.load_state("save", "json")
if save then
win.scene:remove("menu")
win.scene:remove("main_scene")
game_init(save)
else
gui_alert("no saved games")
@ -316,18 +316,22 @@ function main_scene(do_backdrop, do_logo)
{
texture = TEXTURES.MAP_EDITOR_HEX,
action = function()
win.scene:remove("menu")
win.scene:remove("main_scene")
map_editor_init()
end
},
false,
{
texture = TEXTURES.SETTINGS_HEX,
action = function() gui_alert("not yet :)") end
action = function()
gui_alert("not yet :)")
end
},
{
texture = TEXTURES.QUIT_HEX,
action = function() win:close() end
action = function()
win:close()
end
},
false
}
@ -336,7 +340,7 @@ function main_scene(do_backdrop, do_logo)
group:action(main_action)
return group:tag"menu"
return group
end
win.scene = am.group(

121
src/game.lua

@ -2,6 +2,63 @@
game = false -- flag to tell if there is a game running
game_state = {}
local game_scene_options = {
false,
{
texture = TEXTURES.NEW_GAME_HEX,
action = function()
game_init()
end
},
false,
{
texture = TEXTURES.SAVE_GAME_HEX,
action = function()
game_save()
gui_alert("succesfully saved!")
end
},
false,
{
texture = TEXTURES.LOAD_GAME_HEX,
action = function()
local save = am.load_state("save", "json")
if save then
game_init(save)
else
gui_alert("no saved games")
end
end
},
{
texture = TEXTURES.MAP_EDITOR_HEX,
action = function()
win.scene:remove("game")
map_editor_init(game_state.map.seed)
end
},
{
texture = TEXTURES.UNPAUSE_HEX,
action = function()
end
},
{
texture = TEXTURES.SETTINGS_HEX,
action = function()
gui_alert("not yet :)")
end
},
{
texture = TEXTURES.QUIT_HEX,
action = function()
win:close()
end
},
false
}
local function get_initial_game_state(seed)
local STARTING_MONEY = 75
@ -91,68 +148,11 @@ end
local function game_pause()
win.scene("game").paused = true
local game_scene_options = {
false,
{
texture = TEXTURES.NEW_GAME_HEX,
action = function()
game_init()
end
},
false,
{
texture = TEXTURES.SAVE_GAME_HEX,
action = function()
game_save()
gui_alert("succesfully saved!")
end
},
false,
{
texture = TEXTURES.LOAD_GAME_HEX,
action = function()
local save = am.load_state("save", "json")
if save then
game_init(save)
else
gui_alert("no saved games")
end
end
},
{
texture = TEXTURES.MAP_EDITOR_HEX,
action = function()
win.scene:remove("game")
map_editor_init(game_state.map.seed)
end
},
{
texture = TEXTURES.UNPAUSE_HEX,
action = function()
end
},
{
texture = TEXTURES.SETTINGS_HEX,
action = function()
gui_alert("not yet :)")
end
},
{
texture = TEXTURES.QUIT_HEX,
action = function()
win:close()
end
},
false
}
win.scene:append(make_scene_menu(game_scene_options))
end
local function game_deserialize(json_string)
local new_state = am.parse_json(json_string)
local new_game_state = am.parse_json(json_string)
if new_game_state.version ~= version then
log("loading incompatible old save data. starting a fresh game instead.")
@ -199,7 +199,7 @@ local function game_deserialize(json_string)
end
end
return new_state
return new_game_state
end
local function game_serialize()
@ -726,8 +726,9 @@ function game_init(saved_state)
if saved_state then
game_state = game_deserialize(saved_state)
if not state then
if not game_state then
-- failed to load a save
log("failed to load a save :(")
win.scene:append(main_scene(true, true))
return
end

82
src/map-editor.lua

@ -2,10 +2,71 @@
local map_editor_state = {
map = {},
world = {},
ui = {},
selected_tile = false
}
local map_editor_scene_options = {
false,
{
texture = TEXTURES.NEW_GAME_HEX,
action = function()
win.scene:remove("menu")
game_init()
end
},
false,
{
texture = TEXTURES.SAVE_GAME_HEX,
action = function()
game_save()
gui_alert("succesfully saved!")
end
},
false,
{
texture = TEXTURES.LOAD_GAME_HEX,
action = function()
local save = am.load_state("save", "json")
if save then
win.scene:remove("menu")
game_init(save)
else
gui_alert("no saved games")
end
end
},
{
texture = TEXTURES.MAP_EDITOR_HEX,
action = function()
win.scene:remove("menu")
map_editor_init(game_state and game_state.map and game_state.map.seed)
end
},
{
texture = TEXTURES.UNPAUSE_HEX,
action = function()
win.scene:remove("menu")
win.scene("map_editor").paused = false
end
},
{
texture = TEXTURES.SETTINGS_HEX,
action = function()
gui_alert("not yet :)")
end
},
{
texture = TEXTURES.QUIT_HEX,
action = function()
win:close()
end
},
false
}
local function deselect_tile()
map_editor_state.selected_tile = false
win.scene:remove("tile_select_box")
@ -84,22 +145,25 @@ function map_editor_action()
end
function map_editor_init()
-- remove existing map_editor scene from the graph if it's there
win.scene:remove("map_editor")
local map_editor_scene = am.group():tag"map_editor"
map_editor_scene:late_action(map_editor_action)
map_editor_state.map = default_map_editor_map(1)
map_editor_state.world = make_hex_grid_scene(map_editor_state.map, false)
map_editor_scene:append(map_editor_state.world)
win.scene:remove("map_editor")
win.scene:append(map_editor_scene)
win.scene:append(
map_editor_state.ui = am.group(
am.translate(HEX_GRID_CENTER):tag"cursor_translate"
^ make_hex_cursor_node(0, COLORS.TRANSPARENT):tag"cursor"
^ make_hex_cursor_node(0, COLORS.TRANSPARENT):tag"cursor",
make_top_right_display_node()
)
win.scene:append(make_top_right_display_node())
-- add the top level nodes to the scene
map_editor_scene:append(map_editor_state.world)
map_editor_scene:append(map_editor_state.ui)
win.scene:late_action(map_editor_action)
-- add the scene to the window
win.scene:append(map_editor_scene)
end
Loading…
Cancel
Save