Skip to content

Instantly share code, notes, and snippets.

@Nimblz
Created February 28, 2019 02:09
Show Gist options
  • Save Nimblz/741a5de0b438d132037f86eb8796fcf4 to your computer and use it in GitHub Desktop.
Save Nimblz/741a5de0b438d132037f86eb8796fcf4 to your computer and use it in GitHub Desktop.
-- services
local Players = game:GetService("Players")
local PlayerScripts = Players.LocalPlayer:WaitForChild("PlayerScripts")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- paths
local common = ReplicatedStorage:WaitForChild("common")
local common_util = common:WaitForChild("util")
local lib = ReplicatedStorage:WaitForChild("lib")
local moduleBin = PlayerScripts:WaitForChild("module")
-- libraries / functions
local Rodux = require(lib:WaitForChild("Rodux"))
local ClientApi = require(PlayerScripts:WaitForChild("ClientApi"))
local callOnAll = require(common_util:WaitForChild("callOnAll"))
-- client object
local Client = {}
Client.modules = {
EgLegAnimator = require(moduleBin:WaitForChild("EgLegAnimator")),
Portals = require(moduleBin:WaitForChild("Portals")),
Cannons = require(moduleBin:WaitForChild("Cannons")),
Coins = require(moduleBin:WaitForChild("Coins")),
Sound = require(moduleBin:WaitForChild("Sound")),
LegacyCustomizer = require(moduleBin:WaitForChild("LegacyCustomizer")),
Gui = require(moduleBin:WaitForChild("Gui")),
}
function Client:getModule(name)
assert(self.modules[name],"No such module: "..name)
return self.modules[name]
end
function Client:load()
-- init all modules
callOnAll(Client.modules,"init")
-- start all modules, pass self
callOnAll(Client.modules,"start",self)
end
Client.api = ClientApi.new({
initialPlayerState = function(state)
-- create new store based on loaded save
Client.store = Rodux.Store.new(require(PlayerScripts:WaitForChild("clientReducer")), state, {
Rodux.thunkMiddleware,
})
-- player store is initialized, load modules for service locator
Client:load()
end,
-- replicate actions that happen on the server store to player state
storeAction = function(action)
if Client.store ~= nil then
Client.store:dispatch(action)
end
end,
})
Client.api:connect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment