forked from rojo-rbx/rojo
Add a dev settings feature, keyed off codename right now
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
return {
|
return {
|
||||||
|
codename = "Epiphany",
|
||||||
version = {0, 5, 0},
|
version = {0, 5, 0},
|
||||||
expectedServerVersionString = "0.5.x",
|
expectedServerVersionString = "0.5.0 or newer",
|
||||||
protocolVersion = 2,
|
protocolVersion = 2,
|
||||||
port = 34872,
|
port = 34872,
|
||||||
dev = false,
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
|
||||||
53
plugin/src/DevSettings.lua
Normal file
53
plugin/src/DevSettings.lua
Normal 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
|
||||||
@@ -12,14 +12,11 @@ HttpError.Error = {
|
|||||||
"Check your game settings, located in the 'Home' tab of Studio.",
|
"Check your game settings, located in the 'Home' tab of Studio.",
|
||||||
},
|
},
|
||||||
ConnectFailed = {
|
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!",
|
"Make sure the server is running -- use 'rojo serve' to run it!",
|
||||||
},
|
},
|
||||||
Timeout = {
|
|
||||||
message = "Rojo timed out during a request.",
|
|
||||||
},
|
|
||||||
Unknown = {
|
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.
|
This method shouldn't have to exist. Ugh.
|
||||||
]]
|
]]
|
||||||
function HttpError.fromErrorString(err)
|
function HttpError.fromErrorString(message)
|
||||||
err = err:lower()
|
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)
|
return HttpError.new(HttpError.Error.HttpNotEnabled)
|
||||||
end
|
end
|
||||||
|
|
||||||
if err:find("^curl error") then
|
if lower:find("^httperror: connectfail") then
|
||||||
if err:find("couldn't connect to server") then
|
return HttpError.new(HttpError.Error.ConnectFailed)
|
||||||
return HttpError.new(HttpError.Error.ConnectFailed)
|
|
||||||
elseif err:find("timeout was reached") then
|
|
||||||
return HttpError.new(HttpError.Error.Timeout)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return HttpError.new(HttpError.Error.Unknown, err)
|
return HttpError.new(HttpError.Error.Unknown, message)
|
||||||
end
|
end
|
||||||
|
|
||||||
function HttpError:report()
|
function HttpError:report()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
local DevSettings = require(script.Parent.DevSettings)
|
||||||
|
|
||||||
local testLogLevel = nil
|
local testLogLevel = nil
|
||||||
local configValue = game:FindFirstChild("ROJO_LOG")
|
|
||||||
|
|
||||||
local Level = {
|
local Level = {
|
||||||
Error = 0,
|
Error = 0,
|
||||||
@@ -17,32 +18,37 @@ local function getLogLevel()
|
|||||||
return _G.ROJO_LOG
|
return _G.ROJO_LOG
|
||||||
end
|
end
|
||||||
|
|
||||||
if configValue ~= nil then
|
local hyperValue = DevSettings:getLogLevel()
|
||||||
return configValue.Value
|
if hyperValue ~= nil then
|
||||||
|
return hyperValue
|
||||||
end
|
end
|
||||||
|
|
||||||
return Level.Info
|
return Level.Info
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function addTags(tag, message)
|
||||||
|
return tag .. message:gsub("\n", "\n" .. tag)
|
||||||
|
end
|
||||||
|
|
||||||
local Log = {}
|
local Log = {}
|
||||||
|
|
||||||
Log.Level = Level
|
Log.Level = Level
|
||||||
|
|
||||||
function Log.trace(template, ...)
|
function Log.trace(template, ...)
|
||||||
if getLogLevel() >= Level.Trace then
|
if getLogLevel() >= Level.Trace then
|
||||||
print("[Rojo-Trace] " .. string.format(template, ...))
|
print(addTags("[Rojo-Trace] ", string.format(template, ...)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Log.info(template, ...)
|
function Log.info(template, ...)
|
||||||
if getLogLevel() >= Level.Info then
|
if getLogLevel() >= Level.Info then
|
||||||
print("[Rojo-Info] " .. string.format(template, ...))
|
print(addTags("[Rojo-Info] ", string.format(template, ...)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Log.warn(template, ...)
|
function Log.warn(template, ...)
|
||||||
if getLogLevel() >= Level.Warning then
|
if getLogLevel() >= Level.Warning then
|
||||||
warn("[Rojo-Warn] " .. string.format(template, ...))
|
warn(addTags("[Rojo-Warn] ", string.format(template, ...)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ function Session.new()
|
|||||||
:andThen(function()
|
:andThen(function()
|
||||||
return api:retrieveMessages()
|
return api:retrieveMessages()
|
||||||
end)
|
end)
|
||||||
|
:catch(function(message)
|
||||||
|
Logging.warn("Couldn't start a new Rojo session: %s", tostring(message))
|
||||||
|
end)
|
||||||
|
|
||||||
return setmetatable(self, Session)
|
return setmetatable(self, Session)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ if not plugin then
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local Session = require(script.Parent.Session)
|
local Session = require(script.Session)
|
||||||
local Config = require(script.Parent.Config)
|
local Config = require(script.Config)
|
||||||
local Version = require(script.Parent.Version)
|
local Version = require(script.Version)
|
||||||
local Logging = require(script.Parent.Logging)
|
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
|
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()
|
local function checkUpgrade()
|
||||||
-- When developing Rojo, there's no use in doing version checks
|
-- When developing Rojo, there's no use in doing version checks
|
||||||
if Config.dev then
|
if DevSettings:isEnabled() then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@ local function checkUpgrade()
|
|||||||
local message = (
|
local message = (
|
||||||
"\nRojo detected an upgrade from version %s to version %s." ..
|
"\nRojo detected an upgrade from version %s to version %s." ..
|
||||||
"\nMake sure you have also upgraded your server!" ..
|
"\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(
|
):format(
|
||||||
Version.display(lastVersion), Version.display(Config.version),
|
Version.display(lastVersion), Version.display(Config.version),
|
||||||
Version.display(Config.version), Config.expectedServerVersionString
|
Version.display(Config.version), Config.expectedServerVersionString
|
||||||
@@ -40,7 +41,7 @@ local function checkUpgrade()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function main()
|
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)
|
Logging.trace("Rojo %s initialized", displayedVersion)
|
||||||
|
|
||||||
Reference in New Issue
Block a user