local L=require(script.Parent:WaitForChild("\115\116\097\116\115"))local p=require(script.Parent:WaitForChild("\112\111\114\116\097\108\115"))local A=require(script.Parent:WaitForChild("\105\110\118\101\110\116\111\114\121"))local C=require(script.Parent:WaitForChild("\101\113\117\105\112\112\101\100"))return function(K,f)K=K or{}if f.type=="\080\076\065\089\069\082\095\065\068\068"then K=f.saveData end if f.type=="\080\076\065\089\069\082\095\082\069\077\079\086\069"then return nil end if f.type=="\033\033\033\067\076\069\065\082\095\083\065\086\069\033\033\033"then K={}end return{inventory=A(K.inventory,f);equipped=C(K.equipped,f);stats=L(K.stats,f),portals=p(K.portals,f)}end
local stats = require(script.Parent:WaitForChild("stats"))
local portals = require(script.Parent:WaitForChild("portals"))
local inventory = require(script.Parent:WaitForChild("inventory"))
local equipped = require(script.Parent:WaitForChild("equipped"))

return (function(state,action)
    state = state or {}

    -- server TODO: break this into two reducers?
    if action.type == "PLAYER_ADD" then -- load save data
        state = action.saveData
    end

    if action.type == "PLAYER_REMOVE" then -- bye bye
        return nil
    end

    if action.type == "!!!CLEAR_SAVE!!!" then -- DANGER ZONE!
        state = {}
    end

    return {
        inventory = inventory(state.inventory, action),
        equipped = equipped(state.equipped, action),
        stats = stats(state.stats, action),
        portals = portals(state.portals, action),
    }
end)