Skip to content

Commit 54c5c4e

Browse files
committed
remove metatechnology to figure out allowed recipes
remove unused stuff
1 parent b083967 commit 54c5c4e

5 files changed

Lines changed: 26 additions & 166 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Notes:
1111

1212
***
1313
###Changelog
14+
0.2.2
15+
16+
- requires Factorio 0.13.12
17+
1418
0.2.1
1519

1620
- check for module-inserter item when area is selected

control.lua

Lines changed: 20 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,14 @@ require "gui"
88

99
MOD_NAME = "ModuleInserter"
1010

11-
types = {["mining-drill"]=true,["assembling-machine"]=true,lab=true, ["rocket-silo"] = true, furnace=true, beacon=true}
12-
1311
typeToSlot = {}
1412
typeToSlot.lab = defines.inventory.lab_modules
1513
typeToSlot["assembling-machine"] = defines.inventory.assembling_machine_modules
1614
typeToSlot["mining-drill"] = defines.inventory.mining_drill_modules
17-
typeToSlot["furnace"] = defines.inventory.assembling_machine_modules --TODO 0.13 change to furnace_modules
15+
typeToSlot["furnace"] = defines.inventory.furnace_modules --TODO 0.13 change to furnace_modules
1816
typeToSlot["rocket-silo"] = defines.inventory.assembling_machine_modules
1917
typeToSlot["beacon"] = 1
2018

21-
function subPos(p1,p2)
22-
p2 = p2 or {x=0,y=0}
23-
return {x=p1.x-p2.x, y=p1.y-p2.y}
24-
end
25-
26-
function expandPos(pos, range)
27-
range = range or 0.5
28-
if not pos or not pos.x then error("invalid pos",3) end
29-
return {{pos.x - range, pos.y - range}, {pos.x + range, pos.y + range}}
30-
end
31-
3219
function entityKey(ent)
3320
if ent.position and ent.direction then
3421
return ent.position.x..":"..ent.position.y--..":"..ent.direction
@@ -45,7 +32,7 @@ function count_keys(hashmap)
4532
end
4633

4734
--/c game.player.print(serpent.dump(game.player.surface.find_logistic_network_by_position(game.player.position, game.player.force.name).find_cell_closest_to(game.player.position)))
48-
function hasPocketBots(player)
35+
local function hasPocketBots(player)
4936
local logisticCell = player.character.logistic_cell
5037
local port = false
5138
if logisticCell and logisticCell.transmitting and logisticCell.mobile then
@@ -156,17 +143,15 @@ function on_player_selected_area(event)
156143
player.print("Can't insert "..module.." in "..entity.name)
157144
valid_modules = false
158145
end
159-
if global.productivityAllowed and entity.type == "assembling-machine" then
160-
if entity.recipe and not global.productivityAllowed[entity.recipe.name] == true then
161-
player.print("Can't use "..module.." with recipe: " .. entity.recipe.name)
162-
valid_modules = false
163-
end
146+
if entity.type == "assembling-machine" and entity.recipe and next(prototype.limitations) and not prototype.limitations[entity.recipe] then
147+
player.print({"", "Can't use ", module.localised_name, " with recipe: ", entity.recipe.localised_name})
148+
valid_modules = false
164149
end
165150
end
166151
end
167152
end
168-
local inventory = entity.get_inventory(typeToSlot[entity.type])
169-
local contents = inventory.get_contents()
153+
154+
local contents = entity.get_inventory(typeToSlot[entity.type]).get_contents()
170155
if valid_modules and not util.table.compare(cTable,contents) then
171156
-- proxy entity that the robots fly to
172157
local new_entity = {
@@ -177,13 +162,13 @@ function on_player_selected_area(event)
177162
force = entity.force
178163
}
179164
--game.player.surface.create_entity{name = "item-request-proxy", position = game.player.selected.position, force = game.player.force, target = game.player.selected, modules={{item="speed-module-3", count=2}}}
180-
-- local module_proxy = {
181-
-- name = "item-request-proxy",
182-
-- position = game.player.selected.position,
183-
-- force = game.player.force,
184-
-- target = game.player.selected,
185-
-- request_filters = {count=2, item="speed-module-3"}
186-
-- }
165+
-- local module_proxy = {
166+
-- name = "item-request-proxy",
167+
-- position = game.player.selected.position,
168+
-- force = game.player.force,
169+
-- target = game.player.selected,
170+
-- request_filters = {count=2, item="speed-module-3"}
171+
-- }
187172

188173
local key = entityKey(new_entity)
189174
if global.entitiesToInsert[key] then
@@ -253,12 +238,6 @@ local function getMetaItemData()
253238
global.nameToSlots[ent.name] = ent.amount
254239
end
255240

256-
game.forces.player.technologies["mi-meta-productivityRecipes"].reload()
257-
productivityRecipes = game.forces.player.technologies["mi-meta-productivityRecipes"].effects
258-
global.productivityAllowed = #productivityRecipes > 0 and global.productivityAllowed or false
259-
for _, recipe in pairs(productivityRecipes) do
260-
global.productivityAllowed[recipe.recipe] = true
261-
end
262241
end
263242

264243
local function remove_invalid_items()
@@ -320,7 +299,6 @@ local function init_global()
320299
global["config-tmp"] = global["config-tmp"] or {}
321300
global["storage"] = global["storage"] or {}
322301
global.nameToSlots = global.nameToSlots or {}
323-
global.productivityAllowed = global.productivityAllowed or {}
324302
global.settings = global.settings or {}
325303
end
326304

@@ -439,6 +417,10 @@ local function on_configuration_changed(data)
439417
end
440418
on_load()
441419
end
420+
421+
if oldVersion < "0.2.2" then
422+
global.productivityAllowed = nil
423+
end
442424
global.version = newVersion
443425
--mod was updated
444426
-- update/change gui for all players via game.players.gui ?
@@ -467,17 +449,6 @@ script.on_event(defines.events.on_player_created, on_player_created)
467449
script.on_event(defines.events.on_force_created, on_force_created)
468450
script.on_event(defines.events.on_forces_merging, on_forces_merging)
469451

470-
function get_config_item(player, index, type1)
471-
if not global["config-tmp"][player.index]
472-
or index > #global["config-tmp"][player.index]
473-
or global["config-tmp"][player.index][index][type1] == "" or type(global["config-tmp"][player.index][index][type1]) == "table" then
474-
475-
return {"upgrade-planner-item-not-set"}
476-
477-
end
478-
return game.item_prototypes[global["config-tmp"][player.index][index][type1]].localised_name
479-
end
480-
481452
script.on_event(defines.events.on_robot_built_entity, function(event)
482453
local status, err = pcall(function()
483454
local entity = event.created_entity
@@ -588,10 +559,7 @@ script.on_event(defines.events.on_research_finished, function(event)
588559
gui_init(player, true)
589560
end
590561
end
591-
if event.research.name == 'mi-meta-productivityRecipes' then
592-
event.research.force.technologies["mi-meta-productivityRecipes"].enabled = false
593-
event.research.force.technologies["mi-meta-productivityRecipes"].researched = false
594-
end
562+
595563
end)
596564

597565
function debugDump(var, force)
@@ -619,10 +587,7 @@ remote.add_interface("mi",
619587
saveVar = function(name)
620588
saveVar(global, name)
621589
end,
622-
limits = function()
623-
debugDump(productivityAllowed,true)
624-
debugDump(productivityRecipes,true)
625-
end,
590+
626591
init = function()
627592
init_global()
628593
init_players()

data-final-fixes.lua

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ metarecipe.ingredients = {}
99
metarecipe.enabled = false
1010
metarecipe.hidden = true
1111

12-
local metaProductivityRecipesR = copyPrototype("technology", "automated-construction", "mi-meta-productivityRecipes")
13-
metaProductivityRecipesR.ingredients = {}
14-
metaProductivityRecipesR.enabled = false
15-
metaProductivityRecipesR.hidden = true
16-
metaProductivityRecipesR.effects = {}
17-
18-
1912
for t, _ in pairs(types) do
2013
for _, ent in pairs(data.raw[t]) do
2114
if type(ent.module_specification) == "table" and type(ent.module_specification.module_slots) == "number" then
@@ -60,8 +53,6 @@ for t, _ in pairs(types) do
6053
end
6154
data:extend({metaitem, metarecipe})
6255

63-
local tmpTable = {}
64-
6556
for k,prototype in pairs(data.raw["module"]) do
6657
local style =
6758
{
@@ -94,20 +85,9 @@ for k,prototype in pairs(data.raw["module"]) do
9485
height = 32
9586
}
9687
}
97-
-- get allowed recipes for module
98-
if prototype.limitation and type(prototype.limitation) == "table" then
99-
for _, recipe in pairs(prototype.limitation) do
100-
tmpTable[recipe] = true
101-
end
102-
end
10388
data.raw["gui-style"].default["mi-icon-"..prototype.name] = style
10489
end
10590

106-
for r,_ in pairs(tmpTable) do
107-
table.insert(metaProductivityRecipesR.effects, {type="unlock-recipe", recipe=r})
108-
end
109-
data:extend({metaProductivityRecipesR})
110-
11191
data.raw["gui-style"].default["mi-icon-style"] =
11292
{
11393
type = "checkbox_style",

gui.lua

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,3 @@
1-
GUI = {
2-
styleprefix = "st_",
3-
4-
defaultStyles = {
5-
label = "label",
6-
button = "button",
7-
checkbox = "checkbox"
8-
},
9-
10-
windows = {
11-
root = "stGui",
12-
settings = {"settings"},
13-
trainInfo = {"trainInfo"}},
14-
15-
position = "left",
16-
17-
new = function(index, player)
18-
local new = {}
19-
setmetatable(new, {__index=GUI})
20-
return new
21-
end,
22-
23-
destroyGui = function (guiA)
24-
if guiA ~= nil and guiA.valid then
25-
guiA.destroy()
26-
end
27-
end,
28-
29-
add = function(parent, e, bind)
30-
local type = e.type
31-
if not e.style and (type == "button" or type == "label") then
32-
e.style = "st_"..type
33-
end
34-
if bind then
35-
if type == "checkbox" then
36-
e.state = global[bind]
37-
end
38-
end
39-
if type == "checkbox" and not (e.state == true or e.state == false) then
40-
e.state = false
41-
end
42-
return parent.add(e)
43-
end,
44-
45-
addButton = function(parent, e, bind)
46-
e.type="button"
47-
return GUI.add(parent, e, bind)
48-
end,
49-
50-
addLabel = function(parent, e_, bind)
51-
local e = e_
52-
if type1(e) == "string" or type1(e) == "number" or (type1(e) == "table" and e[1]) then
53-
e = {caption=e}
54-
end
55-
e.type="label"
56-
return GUI.add(parent,e,bind)
57-
end,
58-
59-
addTextfield = function(parent, e, bind)
60-
e.type="textfield"
61-
return GUI.add(parent, e, bind)
62-
end,
63-
64-
addPlaceHolder = function(parent, count)
65-
local c = count or 1
66-
for i=1,c do
67-
GUI.add(parent, {type="label", caption=""})
68-
end
69-
end,
70-
71-
sanitizeName = function(name_)
72-
local name = string.gsub(name_, "_", " ")
73-
name = string.gsub(name, "^%s", "")
74-
name = string.gsub(name, "%s$", "")
75-
local pattern = "(%w+)__([%w%s%-%#%!%$]*)_*([%w%s%-%#%!%$]*)_*(%w*)"
76-
local element = "activeLine__"..name.."__".."something"
77-
local t1, t2, t3, _ = element:match(pattern)
78-
if t1 == "activeLine" and t2 == name and t3 == "something" then
79-
return name
80-
else
81-
return false
82-
end
83-
end,
84-
85-
sanitizeNumber = function(number, default)
86-
return tonumber(number) or default
87-
end
88-
}
89-
901
function gui_init(player, after_research)
912
if not player.gui.top["module-inserter-config-button"]
923
and (player.force.technologies["automated-construction"].researched or after_research) then
@@ -135,7 +46,7 @@ function gui_open_frame(player)
13546
if remote.interfaces.YARM and remote.interfaces.YARM.hide_expando then
13647
global.settings[player.index].YARM_old_expando = remote.call("YARM", "hide_expando", player.index)
13748
end
138-
-- Now we can build the GUI.
49+
-- Now we can build the GUI
13950
frame = player.gui.left.add{
14051
type = "frame",
14152
caption = {"module-inserter-config-frame-title"},

info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"title": "Module Inserter",
66
"author": "Choumiko",
77
"homepage": "",
8-
"dependencies": ["base >= 0.13.0"],
8+
"dependencies": ["base >= 0.13.12"],
99
"description": "Mass insert modules into machines with pocket bots"
1010
}

0 commit comments

Comments
 (0)