Skip to content

Commit

Permalink
use icons instead of text
Browse files Browse the repository at this point in the history
clearing slots/entities is done by clicking with empty cursor
only go to entity if not already in list
check if trying to insert productivity in beacon or assembler with forbidden recipe
  • Loading branch information
Choumiko committed Aug 25, 2015
1 parent 640b017 commit b181cae
Show file tree
Hide file tree
Showing 5 changed files with 261 additions and 137 deletions.
69 changes: 52 additions & 17 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ for i, ent in pairs(metaitem) do
nameToSlots[ent.name] = ent.amount
end

productivityRecipes = game.forces.player.technologies["mi-meta-productivityRecipes"].effects
productivityAllowed = {}
for _, recipe in pairs(productivityRecipes) do
productivityAllowed[recipe.recipe] = true
end


function expandPos(pos, range)
local range = range or 0.5
if not pos or not pos.x then error("invalid pos",3) end
Expand Down Expand Up @@ -88,7 +95,10 @@ game.on_event(defines.events.on_marked_for_deconstruction, function(event)
if entity.type ~= "rocket-silo" then

-- Check if player has space for proxy item
if player.can_insert{name="module-inserter-proxy", count=1} then
--/c game.player.print(serpent.dump(game.player.get_inventory(defines.inventory.player_main).can_insert{name="module-inserter-proxy", count=1} or game.player.get_inventory(defines.inventory.player_quickbar).can_insert{name="module-inserter-proxy", count=1}))

local proxy = {name="module-inserter-proxy", count=1}
if player.get_inventory(defines.inventory.player_main).can_insert(proxy) or player.get_inventory(defines.inventory.player_quickbar).can_insert(proxy) then

-- Check if entity is valid and stored in config as a source.
local index = 0
Expand All @@ -103,6 +113,21 @@ game.on_event(defines.events.on_marked_for_deconstruction, function(event)
return
end
local modules = util.table.deepcopy(config[index].to)
for i, module in pairs(modules) do
if module and module:find("productivity") then
if entity.type == "beacon" then
player.print("Can't insert "..module.." in "..entity.name)
entity.cancel_deconstruction(entity.force)
return
end
if entity.recipe and not productivityAllowed[entity.recipe.name] then
player.print("Can't use "..module.." with recipe: " .. entity.recipe.name)
entity.cancel_deconstruction(entity.force)
return
end
end
end

-- proxy entity that the robots fly to
local new_entity = {
name = "entity-ghost",
Expand All @@ -111,25 +136,36 @@ game.on_event(defines.events.on_marked_for_deconstruction, function(event)
direction = entity.direction,
force = entity.force
}

entity.surface.create_entity(new_entity)
global.entitiesToInsert[entityKey(new_entity)] = {entity = entity, player = player, modules = modules}
player.insert{name="module-inserter-proxy", count=1}
if not global.entitiesToInsert[entityKey(new_entity)] then
entity.surface.create_entity(new_entity)
global.entitiesToInsert[entityKey(new_entity)] = {entity = entity, player = player, modules = modules}
player.insert{name="module-inserter-proxy", count=1}
end
end
end
entity.cancel_deconstruction(entity.force)
end)

local function initGlob()

if not global.version or global.version < "0.0.2" then
global.config = {}
global["config-tmp"] = {}
global["storage"] = {}
global.entitiesToInsert = {}
end

global.entitiesToInsert = global.entitiesToInsert or {}
--global["entity-recipes"] = global["entity-recipes"] or {}
global["config"] = global["config"] or {}
global["config-tmp"] = global["config-tmp"] or {}
global["storage"] = global["storage"] or {}

for _, player in pairs(game.players) do
gui_init(player, false)
end

global.version = "0.0.2"
end

local function oninit() initGlob() end
Expand Down Expand Up @@ -182,14 +218,12 @@ game.on_event(defines.events.on_robot_built_entity, function(event)
end
end
end
if modules.total then
for k,v in pairs(modules) do
if k ~= "total" and v ~= 0 then
for i=1,v do
if player.get_item_count(k) > 0 then
inventory.insert{name = k, count = 1}
player.remove_item{name = k, count = 1}
end
if type(modules) == "table" then
for i,module in pairs(modules) do
if module then
if player.get_item_count(module) > 0 and inventory.can_insert{name = module, count = 1} then
inventory.insert{name = module, count = 1}
player.remove_item{name = module, count = 1}
end
end
end
Expand All @@ -202,6 +236,7 @@ end)

game.on_event(defines.events.on_gui_click, function(event)
local element = event.element
--debugDump(element.name, true)
local player = game.get_player(event.player_index)

if element.name == "module-inserter-config-button" then
Expand All @@ -213,18 +248,18 @@ game.on_event(defines.events.on_gui_click, function(event)
elseif element.name == "module-inserter-storage-store" then
gui_store(player)
else
local type, index = string.match(element.name, "module%-inserter%-(%a+)%-(%d+)")
event.element.name:match("(%w+)__([%w%s%-%#%!%$]*)_*([%w%s%-%#%!%$]*)_*(%w*)")
local type, index, slot = string.match(element.name, "module%-inserter%-(%a+)%-(%d+)%-*(%d*)")
--debugDump({t=type,i=index,s=slot},true)
if type and index then
if type == "from" then
gui_set_rule(player, type, tonumber(index))
elseif type == "to" then
gui_set_modules(player, tonumber(index))
gui_set_modules(player, tonumber(index), tonumber(slot))
elseif type == "restore" then
gui_restore(player, tonumber(index))
elseif type == "remove" then
gui_remove(player, tonumber(index))
elseif type == "clear" then
gui_clear_rule(player, tonumber(index))
end
end
end
Expand Down
130 changes: 129 additions & 1 deletion data-final-fixes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,140 @@ metarecipe.ingredients = {}
metarecipe.enabled = false
metarecipe.hidden = true

local metaProductivityRecipesR = copyPrototype("technology", "automated-construction", "mi-meta-productivityRecipes")
metaProductivityRecipesR.ingredients = {}
metaProductivityRecipesR.enabled = false
metaProductivityRecipesR.hidden = false
metaProductivityRecipesR.effects = {}


for t, _ in pairs(types) do
for _, ent in pairs(data.raw[t]) do
if type(ent.module_specification) == "table" and type(ent.module_specification.module_slots) == "number" then
table.insert(metarecipe.ingredients, {ent.name, ent.module_specification.module_slots})
if data.raw["item"][ent.name] then
table.insert(metarecipe.ingredients, {ent.name, ent.module_specification.module_slots})
local prototype = data.raw["item"][ent.name]
local style =
{
type = "checkbox_style",
parent = "mi-icon-style",
default_background =
{
filename = prototype.icon,
width = 32,
height = 32
},
hovered_background =
{
filename = prototype.icon,
width = 32,
height = 32
},
checked_background =
{
filename = prototype.icon,
width = 32,
height = 32
},
clicked_background =
{
filename = prototype.icon,
width = 32,
height = 32
}
}
data.raw["gui-style"].default["mi-icon-"..prototype.name] = style
end
end
end
end
data:extend({metaitem, metarecipe})

local tmpTable = {}

for k,prototype in pairs(data.raw["module"]) do
local style =
{
type = "checkbox_style",
parent = "mi-icon-style",
default_background =
{
filename = prototype.icon,
width = 32,
height = 32
},
hovered_background =
{
filename = prototype.icon,
width = 32,
height = 32
},
checked_background =
{
filename = prototype.icon,
width = 32,
height = 32
},
clicked_background =
{
filename = prototype.icon,
width = 32,
height = 32
}
}
-- get allowed recipes for module
if prototype.limitation and type(prototype.limitation) == "table" then
for _, recipe in pairs(prototype.limitation) do
tmpTable[recipe] = true
end
end
data.raw["gui-style"].default["mi-icon-"..prototype.name] = style
end

for r,_ in pairs(tmpTable) do
table.insert(metaProductivityRecipesR.effects, {type="unlock-recipe", recipe=r})
end


data:extend({metaProductivityRecipesR})

data.raw["gui-style"].default["mi-icon-style"] =
{
type = "checkbox_style",
parent = "checkbox_style",
width = 32,
height = 32,
bottom_padding = 8,
default_background =
{
filename = "__core__/graphics/gui.png",
priority = "extra-high-no-scale",
width = 32,
height = 32,
x = 111
},
hovered_background =
{
filename = "__core__/graphics/gui.png",
priority = "extra-high-no-scale",
width = 32,
height = 32,
x = 111
},
clicked_background =
{
filename = "__core__/graphics/gui.png",
priority = "extra-high-no-scale",
width = 32,
height = 32,
x = 111
},
checked =
{
filename = "__core__/graphics/gui.png",
priority = "extra-high-no-scale",
width = 32,
height = 32,
x = 111
}
}
Loading

0 comments on commit b181cae

Please sign in to comment.