feat(inferium): replace getplan by getconfig
This commit is contained in:
parent
38b9c24bd6
commit
90a3ac864e
@ -1,5 +0,0 @@
|
|||||||
return {
|
|
||||||
fertilizedBoost = false,
|
|
||||||
length = 8,
|
|
||||||
firstCropZ = 2
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
local function mystical(essenceName)
|
|
||||||
return 'mysticalagriculture:' .. essenceName .. '_seeds'
|
|
||||||
end
|
|
||||||
|
|
||||||
return {
|
|
||||||
['default'] = {
|
|
||||||
mystical('coal'),
|
|
||||||
mystical('coal'),
|
|
||||||
mystical('inferium'),
|
|
||||||
mystical('inferium'),
|
|
||||||
mystical('inferium'),
|
|
||||||
mystical('inferium'),
|
|
||||||
mystical('inferium'),
|
|
||||||
mystical('inferium')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
21
config/inferium.lua
Normal file
21
config/inferium.lua
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
local function mystical(essenceName)
|
||||||
|
return 'mysticalagriculture:' .. essenceName .. '_seeds'
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
defaultConfig = {
|
||||||
|
plan = {
|
||||||
|
mystical('coal'),
|
||||||
|
mystical('coal'),
|
||||||
|
mystical('inferium'),
|
||||||
|
mystical('inferium'),
|
||||||
|
mystical('inferium'),
|
||||||
|
mystical('inferium'),
|
||||||
|
mystical('inferium'),
|
||||||
|
mystical('inferium')
|
||||||
|
},
|
||||||
|
fertilizedBoost = false,
|
||||||
|
length = 8,
|
||||||
|
firstCropZ = 2
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,9 +1,8 @@
|
|||||||
local net = require('libs/net')
|
local net = require('libs/net')
|
||||||
local utils = require('libs/utils')
|
local utils = require('libs/utils')
|
||||||
local turtleUtils = require('libs/turtle-utils')
|
local turtleUtils = require('libs/turtle-utils')
|
||||||
local LOCAL_CONFIG = require('config/harvesting')
|
|
||||||
|
|
||||||
local VERSION = "2.6.1"
|
local VERSION = "3.0.0"
|
||||||
local INFERIUM_SERVER = 'inferium.com'
|
local INFERIUM_SERVER = 'inferium.com'
|
||||||
local IDLE_TIME = 2
|
local IDLE_TIME = 2
|
||||||
local WAIT_ITEM_IDLE_TIME = 5
|
local WAIT_ITEM_IDLE_TIME = 5
|
||||||
@ -18,7 +17,7 @@ local FERTILIZED_ESSENCE = 'mysticalagriculture:fertilized_essence'
|
|||||||
-- a table with the list of current crops
|
-- a table with the list of current crops
|
||||||
local localPlan = nil
|
local localPlan = nil
|
||||||
|
|
||||||
local previouslyFetchedRemotePlan = nil
|
local previouslyFetchedRemoteConfig = nil
|
||||||
|
|
||||||
-- UTILS
|
-- UTILS
|
||||||
|
|
||||||
@ -311,28 +310,32 @@ local function retrieveLocalPlan(config)
|
|||||||
goBackToHome(config)
|
goBackToHome(config)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function fetchRemotePlan()
|
local function fetchRemoteConfig()
|
||||||
print('> fetch remote plan')
|
print('> fetch remote config')
|
||||||
local message = { type = 'getplan' }
|
local message = { type = 'getconfig' }
|
||||||
|
|
||||||
local lastErrMessage = nil
|
local lastErrMessage = nil
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local replyMessage, errMessage = net.sendQuery(INFERIUM_SERVER, message, NETWORK_TIMEOUT)
|
local replyMessage, errMessage = net.sendQuery(INFERIUM_SERVER, message, NETWORK_TIMEOUT)
|
||||||
if replyMessage and replyMessage.payload then
|
if replyMessage and replyMessage.payload then
|
||||||
previouslyFetchedRemotePlan = replyMessage.payload
|
previouslyFetchedRemoteConfig = replyMessage.payload
|
||||||
print('> plan fetched')
|
print('> config fetched')
|
||||||
local payload = replyMessage.payload
|
local payload = replyMessage.payload
|
||||||
if not payload then
|
if not payload then
|
||||||
error('cannot fetch the remote plan')
|
error('cannot fetch the remote config')
|
||||||
|
end
|
||||||
|
|
||||||
|
if not payload.plan then
|
||||||
|
error('no "plan" property found in remote config')
|
||||||
end
|
end
|
||||||
|
|
||||||
return payload
|
return payload
|
||||||
elseif previouslyFetchedRemotePlan then
|
elseif previouslyFetchedRemoteConfig then
|
||||||
print('> failed to fetch: ' .. tostring(errMessage))
|
print('> failed to fetch: ' .. tostring(errMessage))
|
||||||
print('> use the previous recorded remote plan instead')
|
print('> use the previous recorded remote config instead')
|
||||||
|
|
||||||
return previouslyFetchedRemotePlan
|
return previouslyFetchedRemoteConfig
|
||||||
elseif not replyMessage and errMessage then
|
elseif not replyMessage and errMessage then
|
||||||
if lastErrMessage ~= errMessage then
|
if lastErrMessage ~= errMessage then
|
||||||
lastErrMessage = errMessage
|
lastErrMessage = errMessage
|
||||||
@ -484,7 +487,9 @@ local function replantSeeds(config)
|
|||||||
goBackToHome(config)
|
goBackToHome(config)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function replantProcedure(remotePlan, config)
|
local function replantProcedure(config)
|
||||||
|
local remotePlan = config.plan
|
||||||
|
|
||||||
if localPlan == nil then
|
if localPlan == nil then
|
||||||
retrieveLocalPlan(config)
|
retrieveLocalPlan(config)
|
||||||
end
|
end
|
||||||
@ -538,21 +543,19 @@ local function main()
|
|||||||
print('> Starting cycle ' .. tostring(cycleNumber))
|
print('> Starting cycle ' .. tostring(cycleNumber))
|
||||||
print()
|
print()
|
||||||
|
|
||||||
local remotePlan = fetchRemotePlan()
|
local remoteConfig = fetchRemoteConfig()
|
||||||
local config = LOCAL_CONFIG
|
|
||||||
|
|
||||||
dropAllProcedure(config)
|
dropAllProcedure(remoteConfig)
|
||||||
refuelProcedure()
|
refuelProcedure()
|
||||||
|
|
||||||
-- TODO: change parameters to be just config
|
replantProcedure(remoteConfig)
|
||||||
replantProcedure(remotePlan, config)
|
|
||||||
|
|
||||||
if config.fertilizedBoost then
|
if remoteConfig.fertilizedBoost then
|
||||||
print('> fertilized boost enabled')
|
print('> fertilized boost enabled')
|
||||||
retrieveFertilizedEssences(config)
|
retrieveFertilizedEssences(remoteConfig)
|
||||||
end
|
end
|
||||||
|
|
||||||
harvestProcedure(config)
|
harvestProcedure(remoteConfig)
|
||||||
|
|
||||||
cycleNumber = cycleNumber + 1
|
cycleNumber = cycleNumber + 1
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,53 +1,49 @@
|
|||||||
local net = require('libs/net')
|
local net = require('libs/net')
|
||||||
local inferiumPlans = require('config/inferium-plans') -- temporary default plan
|
local inferium = require('config/inferium')
|
||||||
|
|
||||||
local INFERIUM_SERVER = 'inferium.com'
|
local INFERIUM_SERVER = 'inferium.com'
|
||||||
local UPGRADE_SCRIPT = '/upgrade.lua'
|
local UPGRADE_SCRIPT = '/upgrade.lua'
|
||||||
local VERSION = "0.5.2"
|
local VERSION = "1.0.0"
|
||||||
|
|
||||||
local defaultPlan = inferiumPlans.default or error('no default plan provided in config', 0)
|
local defaultConfig= inferium.defaultConfig or error('no default config provided in config', 0)
|
||||||
|
|
||||||
local function getPlanForComputer(computerId)
|
-- TODO: persistance
|
||||||
return inferiumPlans[tostring(computerId)]
|
local LOCAL_CONFIGS = {}
|
||||||
|
|
||||||
|
local function getConfigForComputer(computerId)
|
||||||
|
return LOCAL_CONFIGS[tostring(computerId)]
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getPlan(computerId)
|
local function setConfigForComputer(computerId, config)
|
||||||
|
LOCAL_CONFIGS[tostring(computerId)] = config
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getConfig(computerId)
|
||||||
if not computerId == nil then
|
if not computerId == nil then
|
||||||
print('getplan error: no computerId found')
|
print('getconfig error: no computerId found')
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local plan = getPlanForComputer(computerId)
|
local config = getConfigForComputer(computerId)
|
||||||
|
|
||||||
if not plan then
|
if not config then
|
||||||
print('getplan warning: no plan found for computerID ' .. tostring(computerId))
|
print('getconfig warning: no plan found for computerID ' .. tostring(computerId))
|
||||||
plan = defaultPlan
|
setConfigForComputer(computerId, defaultConfig)
|
||||||
|
config = defaultConfig
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type = "getplan/response",
|
type = "getconfig/response",
|
||||||
payload = plan
|
payload = config
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local ROUTES = {
|
local ROUTES = {
|
||||||
['getplan'] = function(_, computerId) return getPlan(computerId) end,
|
['getconfig'] = function(_, computerId) return getConfig(computerId) end,
|
||||||
['exit-server'] = function(_, _, stopServer) stopServer() ; return true end,
|
['exit-server'] = function(_, _, stopServer) stopServer() ; return true end,
|
||||||
['upgrade-server'] = function() shell.execute(UPGRADE_SCRIPT) ; return true end,
|
['upgrade-server'] = function() shell.execute(UPGRADE_SCRIPT) ; return true end,
|
||||||
}
|
}
|
||||||
|
|
||||||
local function handleMessage(message, computerId)
|
|
||||||
if message.type == 'getplan' then
|
|
||||||
return getPlan(computerId)
|
|
||||||
elseif message.type == 'exit-server' then
|
|
||||||
stopServer()
|
|
||||||
return true
|
|
||||||
elseif message.type == 'upgrade-server' then
|
|
||||||
shell.execute('/upgrade.lua')
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
net.openRednet()
|
net.openRednet()
|
||||||
print('> inferium server v' .. VERSION .. ' started')
|
print('> inferium server v' .. VERSION .. ' started')
|
||||||
|
|
||||||
|
|||||||
46
install.lua
46
install.lua
@ -17,18 +17,40 @@ local LIST_CONFIG_FILES = {
|
|||||||
'startup.lua',
|
'startup.lua',
|
||||||
'upgrade.lua',
|
'upgrade.lua',
|
||||||
'config/mining.lua',
|
'config/mining.lua',
|
||||||
'config/harvesting.lua',
|
'config/inferium.lua'
|
||||||
'config/inferium-plans.lua'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-- old files that need to be cleaned up
|
-- old files that need to be cleaned up
|
||||||
local LIST_OLD_FILES = {}
|
local LIST_OLD_FILES = {
|
||||||
|
'config/inferium-plans.lua',
|
||||||
|
'config/harvesting.lua'
|
||||||
|
}
|
||||||
|
|
||||||
local REPO_PREFIX = 'https://git.trapcloud.fr/guillaumearm/minecraft-cc-tools/raw/branch/master/'
|
local REPO_PREFIX = 'https://git.trapcloud.fr/guillaumearm/minecraft-cc-tools/raw/branch/master/'
|
||||||
|
|
||||||
local removeFiles = function(list)
|
local removeFiles = function(list)
|
||||||
for _, filePath in pairs(list) do
|
for _, filePath in pairs(list) do
|
||||||
fs.delete(filePath)
|
if filePath then
|
||||||
|
fs.delete(filePath)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local installFiles = function(list)
|
||||||
|
for _, filePath in pairs(list) do
|
||||||
|
if filePath then
|
||||||
|
fs.delete(filePath)
|
||||||
|
shell.execute('wget', REPO_PREFIX .. filePath, filePath)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local installConfig = function()
|
||||||
|
-- do not override existing config files
|
||||||
|
for _, filePath in pairs(LIST_CONFIG_FILES) do
|
||||||
|
if filePath and not fs.exists(filePath) then
|
||||||
|
shell.execute('wget', REPO_PREFIX .. filePath, filePath)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -39,22 +61,6 @@ local prepareDirs = function()
|
|||||||
fs.makeDir('/data')
|
fs.makeDir('/data')
|
||||||
end
|
end
|
||||||
|
|
||||||
local installFiles = function(list)
|
|
||||||
for _, filePath in pairs(list) do
|
|
||||||
fs.delete(filePath)
|
|
||||||
shell.execute('wget', REPO_PREFIX .. filePath, filePath)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local installConfig = function()
|
|
||||||
-- do not override existing config files
|
|
||||||
for _, filePath in pairs(LIST_CONFIG_FILES) do
|
|
||||||
if not fs.exists(filePath) then
|
|
||||||
shell.execute('wget', REPO_PREFIX .. filePath, filePath)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local mainSetup = function()
|
local mainSetup = function()
|
||||||
local previousDir = shell.dir()
|
local previousDir = shell.dir()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user