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 utils = require('libs/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 IDLE_TIME = 2
|
||||
local WAIT_ITEM_IDLE_TIME = 5
|
||||
@ -18,7 +17,7 @@ local FERTILIZED_ESSENCE = 'mysticalagriculture:fertilized_essence'
|
||||
-- a table with the list of current crops
|
||||
local localPlan = nil
|
||||
|
||||
local previouslyFetchedRemotePlan = nil
|
||||
local previouslyFetchedRemoteConfig = nil
|
||||
|
||||
-- UTILS
|
||||
|
||||
@ -311,28 +310,32 @@ local function retrieveLocalPlan(config)
|
||||
goBackToHome(config)
|
||||
end
|
||||
|
||||
local function fetchRemotePlan()
|
||||
print('> fetch remote plan')
|
||||
local message = { type = 'getplan' }
|
||||
local function fetchRemoteConfig()
|
||||
print('> fetch remote config')
|
||||
local message = { type = 'getconfig' }
|
||||
|
||||
local lastErrMessage = nil
|
||||
|
||||
while true do
|
||||
local replyMessage, errMessage = net.sendQuery(INFERIUM_SERVER, message, NETWORK_TIMEOUT)
|
||||
if replyMessage and replyMessage.payload then
|
||||
previouslyFetchedRemotePlan = replyMessage.payload
|
||||
print('> plan fetched')
|
||||
previouslyFetchedRemoteConfig = replyMessage.payload
|
||||
print('> config fetched')
|
||||
local payload = replyMessage.payload
|
||||
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
|
||||
|
||||
return payload
|
||||
elseif previouslyFetchedRemotePlan then
|
||||
elseif previouslyFetchedRemoteConfig then
|
||||
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
|
||||
if lastErrMessage ~= errMessage then
|
||||
lastErrMessage = errMessage
|
||||
@ -484,7 +487,9 @@ local function replantSeeds(config)
|
||||
goBackToHome(config)
|
||||
end
|
||||
|
||||
local function replantProcedure(remotePlan, config)
|
||||
local function replantProcedure(config)
|
||||
local remotePlan = config.plan
|
||||
|
||||
if localPlan == nil then
|
||||
retrieveLocalPlan(config)
|
||||
end
|
||||
@ -538,21 +543,19 @@ local function main()
|
||||
print('> Starting cycle ' .. tostring(cycleNumber))
|
||||
print()
|
||||
|
||||
local remotePlan = fetchRemotePlan()
|
||||
local config = LOCAL_CONFIG
|
||||
local remoteConfig = fetchRemoteConfig()
|
||||
|
||||
dropAllProcedure(config)
|
||||
dropAllProcedure(remoteConfig)
|
||||
refuelProcedure()
|
||||
|
||||
-- TODO: change parameters to be just config
|
||||
replantProcedure(remotePlan, config)
|
||||
replantProcedure(remoteConfig)
|
||||
|
||||
if config.fertilizedBoost then
|
||||
if remoteConfig.fertilizedBoost then
|
||||
print('> fertilized boost enabled')
|
||||
retrieveFertilizedEssences(config)
|
||||
retrieveFertilizedEssences(remoteConfig)
|
||||
end
|
||||
|
||||
harvestProcedure(config)
|
||||
harvestProcedure(remoteConfig)
|
||||
|
||||
cycleNumber = cycleNumber + 1
|
||||
end
|
||||
|
||||
@ -1,53 +1,49 @@
|
||||
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 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)
|
||||
return inferiumPlans[tostring(computerId)]
|
||||
-- TODO: persistance
|
||||
local LOCAL_CONFIGS = {}
|
||||
|
||||
local function getConfigForComputer(computerId)
|
||||
return LOCAL_CONFIGS[tostring(computerId)]
|
||||
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
|
||||
print('getplan error: no computerId found')
|
||||
print('getconfig error: no computerId found')
|
||||
return nil
|
||||
end
|
||||
|
||||
local plan = getPlanForComputer(computerId)
|
||||
local config = getConfigForComputer(computerId)
|
||||
|
||||
if not plan then
|
||||
print('getplan warning: no plan found for computerID ' .. tostring(computerId))
|
||||
plan = defaultPlan
|
||||
if not config then
|
||||
print('getconfig warning: no plan found for computerID ' .. tostring(computerId))
|
||||
setConfigForComputer(computerId, defaultConfig)
|
||||
config = defaultConfig
|
||||
end
|
||||
|
||||
return {
|
||||
type = "getplan/response",
|
||||
payload = plan
|
||||
type = "getconfig/response",
|
||||
payload = config
|
||||
}
|
||||
end
|
||||
|
||||
local ROUTES = {
|
||||
['getplan'] = function(_, computerId) return getPlan(computerId) end,
|
||||
['getconfig'] = function(_, computerId) return getConfig(computerId) end,
|
||||
['exit-server'] = function(_, _, stopServer) stopServer() ; 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()
|
||||
print('> inferium server v' .. VERSION .. ' started')
|
||||
|
||||
|
||||
46
install.lua
46
install.lua
@ -17,18 +17,40 @@ local LIST_CONFIG_FILES = {
|
||||
'startup.lua',
|
||||
'upgrade.lua',
|
||||
'config/mining.lua',
|
||||
'config/harvesting.lua',
|
||||
'config/inferium-plans.lua'
|
||||
'config/inferium.lua'
|
||||
}
|
||||
|
||||
-- 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 removeFiles = function(list)
|
||||
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
|
||||
|
||||
@ -39,22 +61,6 @@ local prepareDirs = function()
|
||||
fs.makeDir('/data')
|
||||
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 previousDir = shell.dir()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user