[MOD 0.12.33+] Sort Inventory button

Topics and discussion about specific mods
Post Reply
Kruparker
Burner Inserter
Burner Inserter
Posts: 16
Joined: Wed May 25, 2016 6:16 pm
Contact:

[MOD 0.12.33+] Sort Inventory button

Post by Kruparker »

Hi,
here's a little mod to sort your inventory (group items, stack them)
only works for your main inventory

Because the always sorted option annoy me, but sometimes, I want to sort my items.

Type: Mod
Description: Add a 'S' button in top left corner to sort your inventory
License: modified MIT (my personnal version)
Version: 0.0.21
Release: 2016-05-29
Factorio Version: tested on 0.12.33
Category: Helper mod

dowload :
sort-inventory_0.0.21.zip
should be multiplayer compatible
(3.98 KiB) Downloaded 276 times
ps :
Should be multiplayer compatible with version 0.0.21
Attachments
preview
preview
sort.jpg (145.58 KiB) Viewed 6270 times
Last edited by Kruparker on Sun May 29, 2016 3:42 pm, edited 1 time in total.

User avatar
sporefreak
Fast Inserter
Fast Inserter
Posts: 181
Joined: Sun Apr 17, 2016 12:55 am
Contact:

Re: [MOD 0.12.33+] Sort Inventory button

Post by sporefreak »

This is a great idea but I like sorted inventories. but I also like being able to move some things around as needed would it be possible to make it sort when you close your inventory?

Kruparker
Burner Inserter
Burner Inserter
Posts: 16
Joined: Wed May 25, 2016 6:16 pm
Contact:

Re: [MOD 0.12.33+] Sort Inventory button

Post by Kruparker »

sporefreak wrote: would it be possible to make it sort when you close your inventory?
I don't think so.
I didn't find any event related to inventory (or key press), this is why the button is always visible.
You can click it whenever you want to sort your inventory.

MrDoomah
Fast Inserter
Fast Inserter
Posts: 196
Joined: Mon Jun 01, 2015 1:11 pm
Contact:

Re: [MOD 0.12.33+] Sort Inventory button

Post by MrDoomah »

Kruparker wrote:I'm not sure how game.players[] work, so it could not work in multi, I still have to test it.
When someone presses the button, you'll get a player_index. You can put this into game.players[player_index] instead of game.players[1].

You also want to initialise the button with the on_player_created event. (This one also gives you a player_index).

Kruparker
Burner Inserter
Burner Inserter
Posts: 16
Joined: Wed May 25, 2016 6:16 pm
Contact:

Re: [MOD 0.12.33+] Sort Inventory button

Post by Kruparker »

MrDoomah wrote: When someone presses the button, you'll get a player_index. You can put this into game.players[player_index] instead of game.players[1].
Api doc wrote: on_gui_click

Called when LuaGuiElement is clicked.
Contains
element :: LuaGuiElement: The clicked element.
player_index :: uint: The player who did the clicking.
okay, I didn't see that and was always thinking "How the hell do you know which player did something !"
answer => read the fucking manual, and learn to read >.<

MrDoomah wrote: You also want to initialise the button with the on_player_created event. (This one also gives you a player_index).
now I've seen what I missed. I'll do it properly .
next update in some minutes


------------

edit : mod updated to support multiplayer (not tested yet) and updates

User avatar
sporefreak
Fast Inserter
Fast Inserter
Posts: 181
Joined: Sun Apr 17, 2016 12:55 am
Contact:

Re: [MOD 0.12.33+] Sort Inventory button

Post by sporefreak »

Kruparker wrote:
sporefreak wrote: would it be possible to make it sort when you close your inventory?
I don't think so.
I didn't find any event related to inventory (or key press), this is why the button is always visible.
You can click it whenever you want to sort your inventory.
Would it work as a timer? Sorting at set intervals?
I don't like the idea of pressing a button to sort (I know I'm lazy but it gets tedious and I would never remember to do it)
If that's not possible then I might just make a script to sort when I open/close my inventory, Based on this mod. Thanks for the replies :)

Kruparker
Burner Inserter
Burner Inserter
Posts: 16
Joined: Wed May 25, 2016 6:16 pm
Contact:

Re: [MOD 0.12.33+] Sort Inventory button

Post by Kruparker »

sporefreak wrote:
Kruparker wrote:
sporefreak wrote: would it be possible to make it sort when you close your inventory?
I don't think so.
I didn't find any event related to inventory (or key press), this is why the button is always visible.
You can click it whenever you want to sort your inventory.
Would it work as a timer? Sorting at set intervals?
I don't like the idea of pressing a button to sort (I know I'm lazy but it gets tedious and I would never remember to do it)
If that's not possible then I might just make a script to sort when I open/close my inventory, Based on this mod. Thanks for the replies :)
I'm not sure it's a good idea.

1) if I set a timer, the timer could trigger when you are playing with your inventory.
2) if I manage to detect inventory close/open and reorganize each time inventory is closed, what would happen if you make 10 little stacks of bullets to feed your turrets ?
After feeding the first turret, you'll have to recreate yours stacks, and so on..

MrDoomah
Fast Inserter
Fast Inserter
Posts: 196
Joined: Mon Jun 01, 2015 1:11 pm
Contact:

Re: [MOD 0.12.33+] Sort Inventory button

Post by MrDoomah »

Have you considered using opened_self?
image

Kruparker
Burner Inserter
Burner Inserter
Posts: 16
Joined: Wed May 25, 2016 6:16 pm
Contact:

Re: [MOD 0.12.33+] Sort Inventory button

Post by Kruparker »

hummm so opened_self was player inventory opened... not very clear >.<
Thanks !

I'll search if it's possible to add the button to the existing inventory gui.
At least, I could show the button when inventory is opened, hide it when inventory is closed.
and maybe add a configuration screen with a "sort on inventory exit " checkbox. But I'm still not sure if it's a good idea


PS : The method I use to sort inventory is not clean, really dirty. (create some fake chests, add items to chest, send them back inventory)
Because I find no way to work on COPIES(not references) of ItemStack.
I need real copies, I can't just create some vars, because I have to keep track of : bars, health, blueprintsetup/icons..., armor grid
LUA *~#{^# references everywhere makes it impossible because clear inventory means clear my vars >.>

If someone read this, and know how to do it, you'll have my eternal gratitude.

MrDoomah
Fast Inserter
Fast Inserter
Posts: 196
Joined: Mon Jun 01, 2015 1:11 pm
Contact:

Re: [MOD 0.12.33+] Sort Inventory button

Post by MrDoomah »

Kruparker wrote:hummm so opened_self was player inventory opened... not very clear >.<
Thanks !

I'll search if it's possible to add the button to the existing inventory gui.
At least, I could show the button when inventory is opened, hide it when inventory is closed.
and maybe add a configuration screen with a "sort on inventory exit " checkbox. But I'm still not sure if it's a good idea


PS : The method I use to sort inventory is not clean, really dirty. (create some fake chests, add items to chest, send them back inventory)
Because I find no way to work on COPIES(not references) of ItemStack.
I need real copies, I can't just create some vars, because I have to keep track of : bars, health, blueprintsetup/icons..., armor grid
LUA *~#{^# references everywhere makes it impossible because clear inventory means clear my vars >.>

If someone read this, and know how to do it, you'll have my eternal gratitude.

Code: Select all

require "util"
copy = util.table.deepcopy(table)
This creates a complete copy of a table, not just another reference. If you change a value in copy, it doesn't change it in table.

Kruparker
Burner Inserter
Burner Inserter
Posts: 16
Joined: Wed May 25, 2016 6:16 pm
Contact:

Re: [MOD 0.12.33+] Sort Inventory button

Post by Kruparker »

thanks, you seem to be my savior, I tried "standard" deepcopy method found on the web but they all crashed my game.

Code: Select all

-- don't copy factorio rich objects
could be what crashed my game.

I'll try this tomorrow, thanks

Kruparker
Burner Inserter
Burner Inserter
Posts: 16
Joined: Wed May 25, 2016 6:16 pm
Contact:

Re: [MOD 0.12.33+] Sort Inventory button

Post by Kruparker »

MrDoomah wrote:

Code: Select all

require "util"
copy = util.table.deepcopy(table)
This creates a complete copy of a table, not just another reference. If you change a value in copy, it doesn't change it in table.

Yeah : It Works !
..
...
....
MY ASS ! >.<

It's now official I hate LUA.

Code: Select all

for i=1, inventorySize do
	if inventory[i].valid_for_read then
		memInventory = util.table.deepcopy(inventory[i])
		memInventory.count = memInventory.count + 1
		game.players[p_index].print("m:" .. memInventory.name .. ":" .. memInventory.count .. " i:" .. inventory[i].name .. ":" .. inventory[i].count )
	end
end
prints => m:iron-plate:9 i:iron-plate:9
instead of m:iron-plate:9 i:iron-plate:8
on a fresh new map. so my bag stack is incremented because of ]@^]}@~#^ reference

User avatar
sporefreak
Fast Inserter
Fast Inserter
Posts: 181
Joined: Sun Apr 17, 2016 12:55 am
Contact:

Re: [MOD 0.12.33+] Sort Inventory button

Post by sporefreak »

Wondering if i could ping you for an update? Just curious about where the mod is going, im thinking about doing another factorio playthrough and would love to have a sort on close inventory, I might try and make it happen myself if thats okay with you.

Kruparker
Burner Inserter
Burner Inserter
Posts: 16
Joined: Wed May 25, 2016 6:16 pm
Contact:

Re: [MOD 0.12.33+] Sort Inventory button

Post by Kruparker »

Sorry, I didn't see your post before (I was kind of busy).

If I have enough time, I could do something for the end of the week (and if 0.13 not breaks everything)

If you think you can do it yourself (better / before me), just do it. I won't complain (just tell me so we are not 2people working on the code for nothing).
You can do whatever you want with my code (sell it, keep it, modify it, redistributed with your own credits) , except licence under f*** viral GPL.
If you make modifications and want them to published with my original mod, send me back the modified sources.

Post Reply

Return to “Mods”