Add a dev settings feature, keyed off codename right now

This commit is contained in:
Lucien Greathouse
2018-12-03 16:54:21 -08:00
parent 061ea0e7a3
commit 503d7400f3
7 changed files with 86 additions and 37 deletions

View File

@@ -1,7 +1,7 @@
return {
codename = "Epiphany",
version = {0, 5, 0},
expectedServerVersionString = "0.5.x",
expectedServerVersionString = "0.5.0 or newer",
protocolVersion = 2,
port = 34872,
dev = false,
}

View File

@@ -1,7 +0,0 @@
return function()
local Config = require(script.Parent.Config)
it("should have 'dev' disabled", function()
expect(Config.dev).to.equal(false)
end)
end

View File

@@ -0,0 +1,53 @@
local Config = require(script.Parent.Config)
local function getValueContainer()
return game:FindFirstChild("RojoDev-" .. Config.codename)
end
local valueContainer = getValueContainer()
local function create()
valueContainer = getValueContainer()
if valueContainer == nil then
valueContainer = Instance.new("Folder")
valueContainer.Name = "RojoDev-" .. Config.codename
valueContainer.Parent = game
end
local valueLogLevel = valueContainer:FindFirstChild("LogLevel")
if valueLogLevel == nil then
valueLogLevel = Instance.new("IntValue")
valueLogLevel.Name = "LogLevel"
valueLogLevel.Value = 2
valueLogLevel.Parent = valueContainer
end
end
_G[("ROJO_%s_DEV_CREATE"):format(Config.codename:upper())] = create
local function getValue(name)
if valueContainer == nil then
return nil
end
local valueObject = valueContainer:FindFirstChild(name)
if valueObject == nil then
return nil
end
return valueObject.Value
end
local DevSettings = {}
function DevSettings:isEnabled()
return valueContainer ~= nil
end
function DevSettings:getLogLevel()
return getValue("LogLevel")
end
return DevSettings

View File

@@ -12,14 +12,11 @@ HttpError.Error = {
"Check your game settings, located in the 'Home' tab of Studio.",
},
ConnectFailed = {
message = "Rojo plugin couldn't connect to the Rojo server.\n" ..
message = "Couldn't connect to the Rojo server.\n" ..
"Make sure the server is running -- use 'rojo serve' to run it!",
},
Timeout = {
message = "Rojo timed out during a request.",
},
Unknown = {
message = "Rojo encountered an unknown error: {{message}}",
message = "Unknown error: {{message}}",
},
}
@@ -44,22 +41,18 @@ end
--[[
This method shouldn't have to exist. Ugh.
]]
function HttpError.fromErrorString(err)
err = err:lower()
function HttpError.fromErrorString(message)
local lower = message:lower()
if err:find("^http requests are not enabled") then
if lower:find("^http requests are not enabled") then
return HttpError.new(HttpError.Error.HttpNotEnabled)
end
if err:find("^curl error") then
if err:find("couldn't connect to server") then
return HttpError.new(HttpError.Error.ConnectFailed)
elseif err:find("timeout was reached") then
return HttpError.new(HttpError.Error.Timeout)
end
if lower:find("^httperror: connectfail") then
return HttpError.new(HttpError.Error.ConnectFailed)
end
return HttpError.new(HttpError.Error.Unknown, err)
return HttpError.new(HttpError.Error.Unknown, message)
end
function HttpError:report()

View File

@@ -1,5 +1,6 @@
local DevSettings = require(script.Parent.DevSettings)
local testLogLevel = nil
local configValue = game:FindFirstChild("ROJO_LOG")
local Level = {
Error = 0,
@@ -17,32 +18,37 @@ local function getLogLevel()
return _G.ROJO_LOG
end
if configValue ~= nil then
return configValue.Value
local hyperValue = DevSettings:getLogLevel()
if hyperValue ~= nil then
return hyperValue
end
return Level.Info
end
local function addTags(tag, message)
return tag .. message:gsub("\n", "\n" .. tag)
end
local Log = {}
Log.Level = Level
function Log.trace(template, ...)
if getLogLevel() >= Level.Trace then
print("[Rojo-Trace] " .. string.format(template, ...))
print(addTags("[Rojo-Trace] ", string.format(template, ...)))
end
end
function Log.info(template, ...)
if getLogLevel() >= Level.Info then
print("[Rojo-Info] " .. string.format(template, ...))
print(addTags("[Rojo-Info] ", string.format(template, ...)))
end
end
function Log.warn(template, ...)
if getLogLevel() >= Level.Warning then
warn("[Rojo-Warn] " .. string.format(template, ...))
warn(addTags("[Rojo-Warn] ", string.format(template, ...)))
end
end

View File

@@ -28,6 +28,9 @@ function Session.new()
:andThen(function()
return api:retrieveMessages()
end)
:catch(function(message)
Logging.warn("Couldn't start a new Rojo session: %s", tostring(message))
end)
return setmetatable(self, Session)
end

View File

@@ -2,10 +2,11 @@ if not plugin then
return
end
local Session = require(script.Parent.Session)
local Config = require(script.Parent.Config)
local Version = require(script.Parent.Version)
local Logging = require(script.Parent.Logging)
local Session = require(script.Session)
local Config = require(script.Config)
local Version = require(script.Version)
local Logging = require(script.Logging)
local DevSettings = require(script.DevSettings)
--[[
Check if the user is using a newer version of Rojo than last time. If they
@@ -13,7 +14,7 @@ local Logging = require(script.Parent.Logging)
]]
local function checkUpgrade()
-- When developing Rojo, there's no use in doing version checks
if Config.dev then
if DevSettings:isEnabled() then
return
end
@@ -26,7 +27,7 @@ local function checkUpgrade()
local message = (
"\nRojo detected an upgrade from version %s to version %s." ..
"\nMake sure you have also upgraded your server!" ..
"\n\nRojo version %s is intended for use with server version %s.\n"
"\n\nRojo plugin version %s is intended for use with server version %s.\n"
):format(
Version.display(lastVersion), Version.display(Config.version),
Version.display(Config.version), Config.expectedServerVersionString
@@ -40,7 +41,7 @@ local function checkUpgrade()
end
local function main()
local displayedVersion = Config.dev and "DEV" or Version.display(Config.version)
local displayedVersion = DevSettings:isEnabled() and "DEV" or Version.display(Config.version)
Logging.trace("Rojo %s initialized", displayedVersion)