Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.

Commit 7419d25

Browse files
committed
Merge branch 'dev'
2 parents 8a6b694 + 1e249cb commit 7419d25

File tree

4 files changed

+30
-20
lines changed

4 files changed

+30
-20
lines changed

manual-inventory-sort/changelog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.8.0 ##
2+
* Updated for 0.16
3+
* Fixed that opened blueprint books and similar items would close when the inventory was sorted ([4](https://github.com/theRustyKnife/ManualInventorySorting/issues/4))
4+
15
## 1.7.0 ##
26
+ A new option for part inventory sorting for sorting beggining/end of the inventory ([10](https://github.com/theRustyKnife/ManualInventorySorting/pull/10))
37

manual-inventory-sort/data.lua

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ data:extend({
2727
type = "container",
2828
name = "manual-inventory-sort-tmp-chest",
2929
icon = "__manual-inventory-sort__/graphics/trans.png",
30+
icon_size = 32,
3031
flags = {"placeable-neutral", "placeable-off-grid"},
3132
max_health = 10000,
3233
selectable_in_game = false,
@@ -46,20 +47,8 @@ data:extend({
4647
width = 0,
4748
height = 0
4849
},
49-
circuit_wire_connection_point =
50-
{
51-
shadow =
52-
{
53-
red = {0.734375, 0.453125},
54-
green = {0.609375, 0.515625},
55-
},
56-
wire =
57-
{
58-
red = {0.40625, 0.21875},
59-
green = {0.40625, 0.375},
60-
}
61-
},
62-
circuit_connector_sprites = get_circuit_connector_sprites({0.1875, 0.15625}, nil, 18),
50+
circuit_wire_connection_point = circuit_connector_definitions["chest"].points,
51+
circuit_connector_sprites = circuit_connector_definitions["chest"].sprites,
6352
circuit_wire_max_distance = 0
6453
},
6554
})

manual-inventory-sort/info.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "manual-inventory-sort",
3-
"version": "1.7.0",
4-
"factorio_version": "0.15",
3+
"version": "1.8.0",
4+
"factorio_version": "0.16",
55
"title": "Manual Inventory Sorting",
66
"author": "TheRustyKnife",
77
"contact": "[email protected]",
88
"description": "Makes some tweaks to the way inventory sorting works.\nYou can sort your inventory on demand or toggle auto-sort. Auto-sort can be configured to work for just a part of your inventory. \nIt's also possible to sort chests, cars and cargo wagons.",
99
"homepage": "http://mods.factorio.com/mods/theRustyKnife/manual-inventory-sort",
10-
"date": "2017-07-15",
10+
"date": "2017-12-16",
1111
"dependencies": ["base"]
1212
}

manual-inventory-sort/script/sorting.lua

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ function sorting.sort_inventory(arg)
7272

7373
local sorting_player = inventory == nil -- need to remember this for destroying t_chests of non-player entities
7474
local t_chest
75+
local player = player_index and game.players[player_index]
7576

7677
if sorting_player then -- sorting player inventory - use players t_chest
77-
local player = game.players[player_index]
7878
inventory = player.get_inventory(defines.inventory.player_main)
7979

8080
if not global.player_t_chests[player_index] or not global.player_t_chests[player_index].valid then -- this player doesn't have her t_chest yet, so create one
@@ -137,7 +137,7 @@ function sorting.sort_inventory(arg)
137137
if (prototype.order) then order = order .. prototype.order end
138138
order = order .. prototype.name
139139

140-
table.insert(stacks, {stack = stack, prototype = prototype, order = order})
140+
table.insert(stacks, {stack = stack, prototype = prototype, order = order, orig_index = i})
141141
util.add_unique(orders, order)
142142
end
143143
end
@@ -146,6 +146,8 @@ function sorting.sort_inventory(arg)
146146

147147
-- if global.player_settings[player_index].custom_sort_enabled then sort_orders(orders, global.player_settings[player_index].sorting_prefs) end -- WIP custom sorting (waiting for GUI)
148148

149+
local index_map = {} -- This is a table of the new indices indexed by the original indices
150+
149151
-- arrange the stacks in correct order into the t_chest inventory
150152
local i_slots = {i = sort_start - 1, current = sort_start, next = sort_start + 1, filters = filters}
151153
for i = 1, #orders do -- go one order at a time, this also ensures that there's going to be only one item type in each iteration of this loop
@@ -207,6 +209,9 @@ function sorting.sort_inventory(arg)
207209
first = false
208210
end
209211
end
212+
213+
-- If the item is unstackable, save it's index mapping
214+
if c_stack.prototype.stack_size == 1 then index_map[c_stack.orig_index] = i_slots.current; end
210215
end
211216

212217
for i_grid = 1, #stacks_with_grid do -- insert stacks with grid (not sure what vanilla behavior is here, but I'm guessing it doesn't matter all that much)
@@ -222,7 +227,19 @@ function sorting.sort_inventory(arg)
222227

223228
------------ END OF SORTING ------------
224229

225-
for i = sort_start, sort_limit do inventory[i].set_stack(t_chest_inventory[i]) end -- copy the sorted content back to the original inventory
230+
-- copy the sorted content back to the original inventory
231+
local opened_index = nil
232+
local opened_state = player and (player.opened_gui_type == defines.gui_type.item)
233+
for i = sort_start, sort_limit do
234+
inventory[i].set_stack(t_chest_inventory[i])
235+
if opened_state and not opened_index and (player.opened_gui_type == defines.gui_type.none) then
236+
-- This item is currently opened by the player - Reopen it
237+
player.opened = inventory[index_map[i]]
238+
end
239+
end
240+
241+
-- Reopen item if possible
242+
if opened_state and opened_index then player.opened = inventory[index_map[opened_index]]; end
226243

227244
if sorting_player then t_chest_inventory.clear() -- leave the t_chest in place with empty inventory if we were sorting players inventory
228245
else t_chest.destroy() end -- destroy the chest otherwise

0 commit comments

Comments
 (0)