Skip to content

Commit

Permalink
fix regression on analysis page
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleretters committed Sep 12, 2020
1 parent 04be1f0 commit f9c8f23
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion arcologies.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
--
--
-- ........................................
-- v1.1.2 "eternal september"
-- v1.1.3 "eternal september"
-- <3 @tyleretters
-- nor.the-rn.info
-- GNU GPL v3.0
Expand Down
3 changes: 2 additions & 1 deletion lib/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ config = {}
config["settings"] = {
["version_major"] = 1,
["version_minor"] = 1,
["version_patch"] = 2,
["version_patch"] = 3,
["playback"] = 0,
["length"] = 16,
["root"] = 0,
Expand Down Expand Up @@ -40,6 +40,7 @@ to add new structures, minimally:
- config.structures
- config.structure_attribute_map
- keepper:collision()
- new glyphs
structure names must be a single word
Expand Down
27 changes: 17 additions & 10 deletions lib/graphics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,19 @@ function graphics:analysis(items, selected_item_key)
self:structure_palette_analysis(selected_item_key)

-- values
local analysis_items = keeper:get_analysis_items()
local chart = {}

chart.values = {}
chart.values[1] = #keeper.signals
for i = 1, #config.structures do chart.values[i+1] = keeper:count_cells(config.structures[i]) end
for i = 1, #analysis_items do
if analysis_items[i] == "SIGNALS" then
table.insert(chart.values, keeper:count_signals())
else
table.insert(chart.values, keeper:count_cells(analysis_items[i]))
end
end

self.test = chart.values

chart.values_total = 0
for i = 1, #chart.values do chart.values_total = chart.values_total + chart.values[i] end
Expand Down Expand Up @@ -401,35 +409,34 @@ function graphics:analysis(items, selected_item_key)
end

-- line graph
-- disabled for v1.1.0 -- too many lines
local line_graph_start_x = 127
local line_graph_start_y = 10
local line_graph_spacing = 2
local line_graph_x = 0
local line_highlight = 0
self:mls(line_graph_start_x+1, line_graph_start_y, line_graph_start_x+1, (line_graph_start_y + (#chart.values * line_graph_spacing)), 1)
for i = 1, #chart.values do
if chart.values[i] ~= 0 then
line_highlight = (i == selected_item_key) and 5 or 1
line_graph_y = line_graph_start_y + ((i - 1) * line_graph_spacing)
local this_line_percentage = chart.percentages[i] * 100
local this_width = util.round_up(math.floor(util.linlin(0, 100, 0, 10, this_line_percentage)), 1)
self:mlrs(line_graph_start_x, line_graph_y, -this_width, 1, line_highlight)
self:mls(128, line_graph_start_y, 128, (line_graph_start_y + (i * line_graph_spacing)), 1)
end
end

-- grid (thank you @okyeron)
for i = 1, fn.grid_width() * fn.grid_height() do
self.analysis_pixels[i] = 0
if selected_item_key ~= 1 then -- 1 is signals
for k,v in pairs(keeper.cells) do
if v.structure_key == selected_item_key - 1 and v.index == i then
if selected_item_key== 1 then -- 1 is signals
for k,v in pairs(keeper.signals) do
if v.index == i then
self.analysis_pixels[i] = 15
end
end
elseif selected_item_key == 1 then
for k,v in pairs(keeper.signals) do
if v.index == i then
else
for k,v in pairs(keeper.cells) do
if v.structure_value == analysis_items[selected_item_key] and v.index == i then
self.analysis_pixels[i] = 15
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/keeper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ function keeper:count_cells(name)
return count
end

function keeper:count_signals()
return #self.signals
end

function keeper:get_analysis_items()
local analysis_items = {}
table.insert(analysis_items, "SIGNALS")
Expand Down
1 change: 1 addition & 0 deletions lib/menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ function menu:scroll_value(d)
end

function menu:scroll(d)
if page.active_page == 3 then keeper:deselect_cell() end
self:select_item(util.clamp(self.selected_item + d, 1, #self.items))
end

Expand Down
6 changes: 5 additions & 1 deletion lib/page.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ function page:analysis()
popup:render()
else
menu:set_items(keeper:get_analysis_items())
menu:select_item()
if keeper.is_cell_selected then
menu:select_item_by_name(keeper.selected_cell.structure_value)
else
menu:select_item()
end
graphics:analysis(menu.items, menu.selected_item)
end
graphics:title_bar_and_tabs()
Expand Down

0 comments on commit f9c8f23

Please sign in to comment.