mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-20 20:55:50 +00:00
WIP: Epiphany Refactor (#85)
This commit is contained in:
committed by
GitHub
parent
80b9b7594b
commit
72bc77f1d5
5
plugin/README.md
Normal file
5
plugin/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Rojo Plugin
|
||||
|
||||
This is the source to the Rojo Roblox Studio plugin.
|
||||
|
||||
Documentation is WIP.
|
||||
37
plugin/loadEnvironment.lua
Normal file
37
plugin/loadEnvironment.lua
Normal file
@@ -0,0 +1,37 @@
|
||||
--[[
|
||||
Loads the Rojo plugin and all of its dependencies.
|
||||
]]
|
||||
|
||||
local function loadEnvironment()
|
||||
-- If you add any dependencies, add them to this table so they'll be loaded!
|
||||
local LOAD_MODULES = {
|
||||
{"src", "Rojo"},
|
||||
{"modules/promise/lib", "Promise"},
|
||||
{"modules/testez/lib", "TestEZ"},
|
||||
}
|
||||
|
||||
-- This makes sure we can load Lemur and other libraries that depend on init.lua
|
||||
package.path = package.path .. ";?/init.lua"
|
||||
|
||||
-- If this fails, make sure you've run `lua bin/install-dependencies.lua` first!
|
||||
local lemur = require("modules.lemur")
|
||||
|
||||
-- Create a virtual Roblox tree
|
||||
local habitat = lemur.Habitat.new()
|
||||
|
||||
-- We'll put all of our library code and dependencies here
|
||||
local modules = lemur.Instance.new("Folder")
|
||||
modules.Name = "Modules"
|
||||
modules.Parent = habitat.game:GetService("ReplicatedStorage")
|
||||
|
||||
-- Load all of the modules specified above
|
||||
for _, module in ipairs(LOAD_MODULES) do
|
||||
local container = habitat:loadFromFs(module[1])
|
||||
container.Name = module[2]
|
||||
container.Parent = modules
|
||||
end
|
||||
|
||||
return habitat, modules
|
||||
end
|
||||
|
||||
return loadEnvironment
|
||||
Submodule plugin/modules/lemur updated: 86b33cdfb4...96d4166a2d
@@ -4,31 +4,31 @@
|
||||
"partitions": {
|
||||
"plugin": {
|
||||
"path": "src",
|
||||
"target": "ReplicatedStorage.Rojo.modules.Plugin"
|
||||
"target": "ReplicatedStorage.Rojo.Modules.Plugin"
|
||||
},
|
||||
"modules/roact": {
|
||||
"path": "modules/roact/lib",
|
||||
"target": "ReplicatedStorage.Rojo.modules.Roact"
|
||||
"target": "ReplicatedStorage.Rojo.Modules.Roact"
|
||||
},
|
||||
"modules/rodux": {
|
||||
"path": "modules/rodux/lib",
|
||||
"target": "ReplicatedStorage.Rojo.modules.Rodux"
|
||||
"target": "ReplicatedStorage.Rojo.Modules.Rodux"
|
||||
},
|
||||
"modules/roact-rodux": {
|
||||
"path": "modules/roact-rodux/lib",
|
||||
"target": "ReplicatedStorage.Rojo.modules.RoactRodux"
|
||||
"target": "ReplicatedStorage.Rojo.Modules.RoactRodux"
|
||||
},
|
||||
"modules/promise": {
|
||||
"path": "modules/promise/lib",
|
||||
"target": "ReplicatedStorage.Rojo.Modules.Promise"
|
||||
},
|
||||
"modules/testez": {
|
||||
"path": "modules/testez/lib",
|
||||
"target": "ReplicatedStorage.TestEZ"
|
||||
},
|
||||
"modules/promise": {
|
||||
"path": "modules/promise/lib",
|
||||
"target": "ReplicatedStorage.Rojo.modules.Promise"
|
||||
},
|
||||
"tests": {
|
||||
"path": "tests",
|
||||
"target": "TestService"
|
||||
"path": "testBootstrap.server.lua",
|
||||
"target": "TestService.testBootstrap"
|
||||
}
|
||||
}
|
||||
}
|
||||
15
plugin/runTest.lua
Normal file
15
plugin/runTest.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
local loadEnvironment = require("loadEnvironment")
|
||||
|
||||
local testPath = assert((...), "Please specify a path to a test file.")
|
||||
|
||||
local habitat = loadEnvironment()
|
||||
|
||||
local testModule = habitat:loadFromFs(testPath)
|
||||
|
||||
if testModule == nil then
|
||||
error("Couldn't find test file at " .. testPath)
|
||||
end
|
||||
|
||||
print("Starting test module.")
|
||||
|
||||
habitat:require(testModule)
|
||||
@@ -2,37 +2,14 @@
|
||||
Loads our library and all of its dependencies, then runs tests using TestEZ.
|
||||
]]
|
||||
|
||||
-- If you add any dependencies, add them to this table so they'll be loaded!
|
||||
local LOAD_MODULES = {
|
||||
{"src", "plugin"},
|
||||
{"modules/promise/lib", "Promise"},
|
||||
{"modules/testez/lib", "TestEZ"},
|
||||
}
|
||||
local loadEnvironment = require("loadEnvironment")
|
||||
|
||||
-- This makes sure we can load Lemur and other libraries that depend on init.lua
|
||||
package.path = package.path .. ";?/init.lua"
|
||||
|
||||
-- If this fails, make sure you've run `lua bin/install-dependencies.lua` first!
|
||||
local lemur = require("modules.lemur")
|
||||
|
||||
-- Create a virtual Roblox tree
|
||||
local habitat = lemur.Habitat.new()
|
||||
|
||||
-- We'll put all of our library code and dependencies here
|
||||
local Root = lemur.Instance.new("Folder")
|
||||
Root.Name = "Root"
|
||||
|
||||
-- Load all of the modules specified above
|
||||
for _, module in ipairs(LOAD_MODULES) do
|
||||
local container = habitat:loadFromFs(module[1])
|
||||
container.Name = module[2]
|
||||
container.Parent = Root
|
||||
end
|
||||
local habitat, modules = loadEnvironment()
|
||||
|
||||
-- Load TestEZ and run our tests
|
||||
local TestEZ = habitat:require(Root.TestEZ)
|
||||
local TestEZ = habitat:require(modules.TestEZ)
|
||||
|
||||
local results = TestEZ.TestBootstrap:run(Root.plugin, TestEZ.Reporters.TextReporter)
|
||||
local results = TestEZ.TestBootstrap:run(modules.Rojo, TestEZ.Reporters.TextReporter)
|
||||
|
||||
-- Did something go wrong?
|
||||
if results.failureCount > 0 then
|
||||
|
||||
@@ -19,14 +19,15 @@ setmetatable(ApiContext.Error, {
|
||||
end
|
||||
})
|
||||
|
||||
function ApiContext.new(url, onMessage)
|
||||
assert(type(url) == "string")
|
||||
function ApiContext.new(baseUrl, onMessage)
|
||||
assert(type(baseUrl) == "string")
|
||||
assert(type(onMessage) == "function")
|
||||
|
||||
local context = {
|
||||
url = url,
|
||||
baseUrl = baseUrl,
|
||||
onMessage = onMessage,
|
||||
serverId = nil,
|
||||
rootInstanceId = nil,
|
||||
connected = false,
|
||||
messageCursor = -1,
|
||||
partitionRoutes = nil,
|
||||
@@ -38,7 +39,9 @@ function ApiContext.new(url, onMessage)
|
||||
end
|
||||
|
||||
function ApiContext:connect()
|
||||
return Http.get(self.url .. "/api/rojo")
|
||||
local url = ("%s/api/rojo"):format(self.baseUrl)
|
||||
|
||||
return Http.get(url)
|
||||
:andThen(function(response)
|
||||
local body = response:json()
|
||||
|
||||
@@ -61,15 +64,18 @@ function ApiContext:connect()
|
||||
self.serverId = body.serverId
|
||||
self.connected = true
|
||||
self.partitionRoutes = body.partitions
|
||||
self.rootInstanceId = body.rootInstanceId
|
||||
end)
|
||||
end
|
||||
|
||||
function ApiContext:readAll()
|
||||
function ApiContext:read(ids)
|
||||
if not self.connected then
|
||||
return Promise.reject()
|
||||
end
|
||||
|
||||
return Http.get(self.url .. "/api/read_all")
|
||||
local url = ("%s/api/read/%s"):format(self.baseUrl, table.concat(ids, ","))
|
||||
|
||||
return Http.get(url)
|
||||
:andThen(function(response)
|
||||
local body = response:json()
|
||||
|
||||
@@ -92,7 +98,9 @@ function ApiContext:retrieveMessages()
|
||||
return Promise.reject()
|
||||
end
|
||||
|
||||
return Http.get(self.url .. "/api/subscribe/" .. self.messageCursor)
|
||||
local url = ("%s/api/subscribe/%s"):format(self.baseUrl, self.messageCursor)
|
||||
|
||||
return Http.get(url)
|
||||
:andThen(function(response)
|
||||
local body = response:json()
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
local HttpService = game:GetService("HttpService")
|
||||
|
||||
local HTTP_DEBUG = false
|
||||
local HTTP_DEBUG = true
|
||||
|
||||
local Promise = require(script.Parent.Parent.Promise)
|
||||
|
||||
|
||||
@@ -11,57 +11,7 @@ function Session.new()
|
||||
|
||||
setmetatable(self, Session)
|
||||
|
||||
local function createFoldersUntil(location, route)
|
||||
for i = 1, #route - 1 do
|
||||
local piece = route[i]
|
||||
|
||||
local child = location:FindFirstChild(piece)
|
||||
|
||||
if child == nil then
|
||||
child = Instance.new("Folder")
|
||||
child.Name = piece
|
||||
child.Parent = location
|
||||
end
|
||||
|
||||
location = child
|
||||
end
|
||||
|
||||
return location
|
||||
end
|
||||
|
||||
local function reify(instancesById, id)
|
||||
local object = instancesById[tostring(id)]
|
||||
local instance = Instance.new(object.className)
|
||||
instance.Name = object.name
|
||||
|
||||
for key, property in pairs(object.properties) do
|
||||
instance[key] = property.value
|
||||
end
|
||||
|
||||
for _, childId in ipairs(object.children) do
|
||||
reify(instancesById, childId).Parent = instance
|
||||
end
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
local api
|
||||
local function readAll()
|
||||
print("Reading all...")
|
||||
|
||||
return api:readAll()
|
||||
:andThen(function(response)
|
||||
for partitionName, partitionRoute in pairs(api.partitionRoutes) do
|
||||
local parent = createFoldersUntil(game, partitionRoute)
|
||||
|
||||
local rootInstanceId = response.partitionInstances[partitionName]
|
||||
|
||||
print("Root for", partitionName, "is", rootInstanceId)
|
||||
|
||||
reify(response.instances, rootInstanceId).Parent = parent
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
api = ApiContext.new(REMOTE_URL, function(message)
|
||||
if message.type == "InstanceChanged" then
|
||||
@@ -73,7 +23,9 @@ function Session.new()
|
||||
end)
|
||||
|
||||
api:connect()
|
||||
:andThen(readAll)
|
||||
:andThen(function()
|
||||
return api:read({api.rootInstanceId})
|
||||
end)
|
||||
:andThen(function()
|
||||
return api:retrieveMessages()
|
||||
end)
|
||||
|
||||
2
plugin/testBootstrap.server.lua
Normal file
2
plugin/testBootstrap.server.lua
Normal file
@@ -0,0 +1,2 @@
|
||||
local TestEZ = require(game.ReplicatedStorage.TestEZ)
|
||||
TestEZ.TestBootstrap:run(game.ReplicatedStorage.Rojo.plugin)
|
||||
5
plugin/tests/empty.lua
Normal file
5
plugin/tests/empty.lua
Normal file
@@ -0,0 +1,5 @@
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
|
||||
local Session = require(ReplicatedStorage.Modules.Rojo.Session)
|
||||
|
||||
Session.new()
|
||||
@@ -1,2 +0,0 @@
|
||||
local TestEZ = require(game.ReplicatedStorage.TestEZ)
|
||||
TestEZ.TestBootstrap:run(game.ReplicatedStorage.Rojo.plugin)
|
||||
Reference in New Issue
Block a user