feat(inferium-server): final implemention of listAvailableSeeds

This commit is contained in:
Guillaume ARM 2024-05-24 17:09:26 +02:00
parent 6b36dd3c92
commit 702dd4833a

View File

@ -3,7 +3,7 @@ local utils = require('libs/utils')
local inferium = require('config/inferium')
local DEFAULT_HARVESTER_NAME = 'harvester'
local VERSION = "2.0.3"
local VERSION = "2.1.0"
local INFERIUM_SERVER = 'inferium.com'
local PERSISTED_CONFIGS = '/data/inferium-configs'
@ -11,6 +11,19 @@ local UPGRADE_SCRIPT = '/upgrade.lua'
local defaultConfig = inferium.defaultConfig or error('no default config provided in config', 0)
local function formatSeedName(essenceName)
if not essenceName then
return false
end
return 'mysticalagriculture:' .. essenceName .. '_seeds'
end
local defaultAvailableSeeds = {
formatSeedName('inferium'),
formatSeedName('coal')
}
-- Persistance utils
local savePersistedConfigs = function(configs)
@ -52,13 +65,7 @@ local function saveConfigForComputer(computerId, config)
end
-- Utils
local function formatSeedName(essenceName)
if not essenceName then
return false
end
return 'mysticalagriculture:' .. essenceName .. '_seeds'
end
local function getConfigWithLength(config)
if not config then
@ -170,29 +177,57 @@ local function listHarvesters()
local result = {}
for k, v in pairs(LOCAL_CONFIGS) do
table.insert(result, { id = k, name = v.name or DEFAULT_HARVESTER_NAME })
local harvester = {
id = k,
name = v.name or DEFAULT_HARVESTER_NAME
}
table.insert(result, harvester)
end
return result
end
-- TODO: share this utils with inferium-gui (create libs/inferium)
local function parseSeedName(seedName)
if not seedName then
return nil
end
local result, nbReplaced = string.gsub(seedName, 'mysticalagriculture:', '')
if nbReplaced == 0 then
return nil
end
local finalResult, nbFinalReplaced = string.gsub(result, '_seeds', '')
if nbFinalReplaced == 0 then
return nil
end
return finalResult
end
local function isMysticalSeed(seedName)
return not not parseSeedName(seedName)
end
local function listAvailableSeeds()
return {
formatSeedName('inferium'),
formatSeedName('experience'),
formatSeedName('soulium'),
formatSeedName('diamond'),
formatSeedName('redstone'),
formatSeedName('coal'),
formatSeedName('iron'),
formatSeedName('dye'),
formatSeedName('nether_quartz'),
formatSeedName('yellorium'),
formatSeedName('glowstone'),
formatSeedName('fire'),
formatSeedName('water'),
formatSeedName('dirt')
}
local inv = peripheral.find('inventory')
if not inv then
print('warning: no inventory found for the inferium server')
return defaultAvailableSeeds
end
local seeds = {}
for _, item in pairs(inv.list()) do
if isMysticalSeed(item.name) then
table.insert(seeds, item.name)
end
end
return seeds
end
local function exitServer(_, _, stopServer)