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 inferium = require('config/inferium')
local DEFAULT_HARVESTER_NAME = 'harvester' local DEFAULT_HARVESTER_NAME = 'harvester'
local VERSION = "2.0.3" local VERSION = "2.1.0"
local INFERIUM_SERVER = 'inferium.com' local INFERIUM_SERVER = 'inferium.com'
local PERSISTED_CONFIGS = '/data/inferium-configs' 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 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 -- Persistance utils
local savePersistedConfigs = function(configs) local savePersistedConfigs = function(configs)
@ -52,13 +65,7 @@ local function saveConfigForComputer(computerId, config)
end end
-- Utils -- Utils
local function formatSeedName(essenceName)
if not essenceName then
return false
end
return 'mysticalagriculture:' .. essenceName .. '_seeds'
end
local function getConfigWithLength(config) local function getConfigWithLength(config)
if not config then if not config then
@ -170,29 +177,57 @@ local function listHarvesters()
local result = {} local result = {}
for k, v in pairs(LOCAL_CONFIGS) do 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 end
return result return result
end 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() local function listAvailableSeeds()
return { local inv = peripheral.find('inventory')
formatSeedName('inferium'),
formatSeedName('experience'), if not inv then
formatSeedName('soulium'), print('warning: no inventory found for the inferium server')
formatSeedName('diamond'), return defaultAvailableSeeds
formatSeedName('redstone'), end
formatSeedName('coal'),
formatSeedName('iron'), local seeds = {}
formatSeedName('dye'), for _, item in pairs(inv.list()) do
formatSeedName('nether_quartz'), if isMysticalSeed(item.name) then
formatSeedName('yellorium'), table.insert(seeds, item.name)
formatSeedName('glowstone'), end
formatSeedName('fire'), end
formatSeedName('water'),
formatSeedName('dirt') return seeds
}
end end
local function exitServer(_, _, stopServer) local function exitServer(_, _, stopServer)