Shirkit / AdditionalPasteSettings

Factorio mod for paste settings that should be added to the game.
https://mods.factorio.com/mods/SHiRKiT/additional-paste-settings/
MIT License
0 stars 2 forks source link

Factorio 1.1 support #5

Closed billbo99 closed 3 years ago

billbo99 commented 3 years ago

Can you please release a version that supports Factorio 1.1 ?

Shirkit commented 3 years ago

Did it break? I'll take a look at it by the weekend.

Shirkit commented 3 years ago

Hey @billbo99 yeah things broke on the API I was using, it'll take some time before I can fix it: https://forums.factorio.com/viewtopic.php?f=25&t=92247&p=524290#p524290

If no devs sees this, I'll ponder in submitting it as a bug report.

billbo99 commented 3 years ago

This is the new behaviour with 1.x .. the chests no longer have a fixed number of slots, you can put in as many requests as you want. The GUI auto expands as you use up the slots.

https://i.imgur.com/nvt5sx1.png

Shirkit commented 3 years ago

Yeah, it looks great on the UI. The only issue is now the API doesn't have a max value for the number of slots, so I can't iterate over the slots, since I don't know the upper limit. Doing until it throws an error is an option if I can't find any other viable solution.

billbo99 commented 3 years ago

chest.request_slot_count .. give the max number of request slots in the current chest. image

chest.get_request_slot(x) .. get the content of given slot .. nil if empty

PS .. not sure what tool you are using for writing your code. But "Visual Studio Code" has an extension for debugging Factorio code, allowing you to add break points in both data and control lua code.

Shirkit commented 3 years ago

Ok, that's weird. I'm just doing print on the chat, and it's returning me 0. What version are you running?

I'm going to install Visual Studio Code to see the debbuging feature.

Are you looking at on_vanilla_pre_paste(event) as well? Weird that it's returning me 0 and 40 to you.

billbo99 commented 3 years ago

I was trying to debug what was broken with your mod.

local function on_vanilla_pre_paste(event)
    -- cache the items in the chest before the paste event is applied
    if event.source.type == "assembling-machine" and event.destination.type == "logistic-container" and (event.destination.prototype.logistic_mode == "requester" or event.destination.prototype.logistic_mode == "buffer") then
        local evt = global.event_backup[event.source.position.x .. "-" .. event.source.position.y .. "-" .. event.destination.position.x .. "-" .. event.destination.position.y]
        if evt ~= nil then
            for i = 1, event.destination.request_slot_count do
                local j = event.destination.get_request_slot(i)
                if j ~= nil then
                    evt.stacks[j.name] = j.count
                end
            end
        end
    end
end

Since the slot numbers are now variable, and the contents on the slots has to be unique, I was looking to store things in your "evt" variable as key/value pairs.

image

Shirkit commented 3 years ago

Well, I need to even reach that part, because on my end it doesn't even run the code there, since it reads 0.

It's a 3 step process: assembler_to_logiscts_chest -> pre_paste -> vanilla_paste

I first detect who's firing the event, then store the contents of the current slots (for later merging), and then do the actual merge (or overwrite).

If it reads 40 on your end, I don't see what would be the issue, since this code is mostly unchanged for a while, and I didn't read anything that could have broken on the changelog and modding changelog.

billbo99 commented 3 years ago

Does your requester chest have any requests in place? I added 4x dummy requests just to get something to display.

billbo99 commented 3 years ago

additional-paste-settings-revisited.zip Attached is a version of your mod that I got working.

Shirkit commented 3 years ago

Yeah, I got it working as well, but not without all those breaking changes. It's a quick fix mine, which I think it's highly unlikely to cause issues.