diff --git a/plugin/src/DevSettings.lua b/plugin/src/DevSettings.lua index 8edf7efb..060742c2 100644 --- a/plugin/src/DevSettings.lua +++ b/plugin/src/DevSettings.lua @@ -1,10 +1,27 @@ local Config = require(script.Parent.Config) +local Environment = { + User = "User", + Dev = "Dev", + Test = "Test", +} + local VALUES = { LogLevel = { type = "IntValue", - defaultUserValue = 2, - defaultDevValue = 3, + values = { + [Environment.User] = 2, + [Environment.Dev] = 3, + [Environment.Test] = 3, + }, + }, + TypecheckingEnabled = { + type = "BoolValue", + values = { + [Environment.User] = false, + [Environment.Dev] = true, + [Environment.Test] = true, + }, }, } @@ -42,7 +59,9 @@ local function setStoredValue(name, kind, value) object.Value = value end -local function createAllValues() +local function createAllValues(environment) + assert(Environment[environment] ~= nil, "Invalid environment") + valueContainer = getValueContainer() if valueContainer == nil then @@ -52,20 +71,57 @@ local function createAllValues() end for name, value in pairs(VALUES) do - setStoredValue(name, value.type, value.defaultDevValue) + setStoredValue(name, value.type, value.values[environment]) end end -_G[("ROJO_%s_DEV_CREATE"):format(Config.codename:upper())] = createAllValues +local function getValue(name) + assert(VALUES[name] ~= nil, "Invalid DevSettings name") + + local stored = getStoredValue(name) + + if stored ~= nil then + return stored + end + + return VALUES[name].values[Environment.User] +end local DevSettings = {} +function DevSettings:createDevSettings() + createAllValues(Environment.Dev) +end + +function DevSettings:createTestSettings() + createAllValues(Environment.Test) +end + +function DevSettings:hasChangedValues() + return valueContainer ~= nil +end + +function DevSettings:resetValues() + if valueContainer then + valueContainer:Destroy() + valueContainer = nil + end +end + function DevSettings:isEnabled() return valueContainer ~= nil end function DevSettings:getLogLevel() - return getStoredValue("LogLevel") or VALUES.LogLevel.defaultUserValue + return getValue("LogLevel") +end + +function DevSettings:shouldTypecheck() + return getValue("TypecheckingEnabled") +end + +function _G.ROJO_DEV_CREATE() + DevSettings:createDevSettings() end return DevSettings \ No newline at end of file diff --git a/plugin/src/Reconciler.lua b/plugin/src/Reconciler.lua index d63bfddd..58eb4182 100644 --- a/plugin/src/Reconciler.lua +++ b/plugin/src/Reconciler.lua @@ -1,7 +1,10 @@ +local t = require(script.Parent.Parent.t) + local InstanceMap = require(script.Parent.InstanceMap) local Logging = require(script.Parent.Logging) local setCanonicalProperty = require(script.Parent.setCanonicalProperty) local rojoValueToRobloxValue = require(script.Parent.rojoValueToRobloxValue) +local Types = require(script.Parent.Types) local Reconciler = {} Reconciler.__index = Reconciler @@ -24,11 +27,18 @@ function Reconciler:applyUpdate(requestedIds, virtualInstancesById) end end +local reconcileSchema = Types.ifEnabled(t.tuple( + t.map(t.string, Types.VirtualInstance), + t.string, + t.Instance +)) --[[ Update an existing instance, including its properties and children, to match the given information. ]] function Reconciler:reconcile(virtualInstancesById, id, instance) + assert(reconcileSchema(virtualInstancesById, id, instance)) + local virtualInstance = virtualInstancesById[id] -- If an instance changes ClassName, we assume it's very different. That's @@ -121,7 +131,15 @@ function Reconciler:__shouldClearUnknownChildren(virtualInstance) end end +local reifySchema = Types.ifEnabled(t.tuple( + t.map(t.string, Types.VirtualInstance), + t.string, + t.Instance +)) + function Reconciler:__reify(virtualInstancesById, id, parent) + assert(reifySchema(virtualInstancesById, id, parent)) + local virtualInstance = virtualInstancesById[id] local instance = Instance.new(virtualInstance.ClassName) @@ -142,7 +160,15 @@ function Reconciler:__reify(virtualInstancesById, id, parent) return instance end +local applyUpdatePieceSchema = Types.ifEnabled(t.tuple( + t.string, + t.map(t.string, t.boolean), + t.map(t.string, Types.VirtualInstance) +)) + function Reconciler:__applyUpdatePiece(id, visitedIds, virtualInstancesById) + assert(applyUpdatePieceSchema(id, visitedIds, virtualInstancesById)) + if visitedIds[id] then return end diff --git a/plugin/src/Types.lua b/plugin/src/Types.lua new file mode 100644 index 00000000..f182d60a --- /dev/null +++ b/plugin/src/Types.lua @@ -0,0 +1,36 @@ +local t = require(script.Parent.Parent.t) + +local DevSettings = require(script.Parent.DevSettings) + +local VirtualValue = t.interface({ + Type = t.string, + Value = t.optional(t.any), +}) + +local VirtualMetadata = t.interface({ + ignoreUnknownInstances = t.optional(t.boolean), +}) + +local VirtualInstance = t.interface({ + Name = t.string, + ClassName = t.string, + Properties = t.map(t.string, VirtualValue), + Metadata = t.optional(VirtualMetadata) +}) + +local function ifEnabled(innerCheck) + return function(...) + if DevSettings:shouldTypecheck() then + return innerCheck(...) + else + return true + end + end +end + +return { + ifEnabled = ifEnabled, + VirtualInstance = VirtualInstance, + VirtualMetadata = VirtualMetadata, + VirtualValue = VirtualValue, +} \ No newline at end of file diff --git a/plugin/testBootstrap.server.lua b/plugin/testBootstrap.server.lua index 4d10558a..81ed88b2 100644 --- a/plugin/testBootstrap.server.lua +++ b/plugin/testBootstrap.server.lua @@ -1,2 +1,19 @@ -local TestEZ = require(game.ReplicatedStorage.TestEZ) -TestEZ.TestBootstrap:run({game.ReplicatedStorage.Rojo.Plugin}) \ No newline at end of file +local ReplicatedStorage = game:GetService("ReplicatedStorage") + +local TestEZ = require(ReplicatedStorage.TestEZ) + +local Rojo = ReplicatedStorage.Rojo + +local DevSettings = require(Rojo.Plugin.DevSettings) + +local setDevSettings = not DevSettings:hasChangedValues() + +if setDevSettings then + DevSettings:createTestSettings() +end + +TestEZ.TestBootstrap:run({Rojo.Plugin}) + +if setDevSettings then + DevSettings:resetValues() +end \ No newline at end of file