Major refactoring (big thanks to OldCoder) enabling CLI and local storage and cleaner modpol/MT split
This commit is contained in:
77
modpol.lua
Normal file
77
modpol.lua
Normal file
@ -0,0 +1,77 @@
|
||||
-- ===================================================================
|
||||
-- /modpol.lua
|
||||
-- Modular Politics (modpol) core
|
||||
|
||||
-- ===================================================================
|
||||
-- Basic tables
|
||||
|
||||
-- Main API table
|
||||
modpol = {
|
||||
}
|
||||
|
||||
-- Table for all active governance data
|
||||
modpol.orgs = {
|
||||
}
|
||||
|
||||
-- Record of every state change should appear here
|
||||
modpol.ledger = {
|
||||
}
|
||||
|
||||
-- ===================================================================
|
||||
-- Locate framework top-level directory.
|
||||
|
||||
-- This function is intended for use under Linux and/or UNIX only. It
|
||||
-- returns a relative or absolute path for the framework top-level
|
||||
-- directory without a trailing slash.
|
||||
|
||||
local get_script_dir = function()
|
||||
local str = debug.getinfo (2, "S").source:sub (2)
|
||||
str = str:match ("(.*/)") or "."
|
||||
str = str:gsub ("/$", "", 1)
|
||||
return str
|
||||
end
|
||||
|
||||
-- Absolute or relative path to script directory.
|
||||
local topdir = get_script_dir()
|
||||
modpol.topdir = topdir
|
||||
print (topdir)
|
||||
|
||||
-- ===================================================================
|
||||
-- Load dependencies
|
||||
|
||||
-- OldCoder utilities
|
||||
dofile (topdir .. "/ocutil.lua")
|
||||
|
||||
-- ===================================================================
|
||||
-- Persistent storage
|
||||
-- must implement modpol.load_storage() and modpol.store_data()
|
||||
|
||||
-- Select a storage method
|
||||
-- Works with CLI:
|
||||
dofile (topdir .. "/storage-local.lua")
|
||||
-- Works with Minetest 5:
|
||||
-- dofile (topdir .. "/storage-mod_storage.lua")
|
||||
|
||||
-- If available, load persistent storage into active tables
|
||||
modpol.load_storage()
|
||||
|
||||
-- ===================================================================
|
||||
-- ModPol core features
|
||||
|
||||
dofile (topdir .. "/users.lua")
|
||||
dofile (topdir .. "/orgs.lua")
|
||||
dofile (topdir .. "/interactions.lua")
|
||||
-- messaging functions
|
||||
|
||||
-- ===================================================================
|
||||
-- Final checks
|
||||
|
||||
-- create instance if not present
|
||||
if (modpol.orgs["instance"] == nil) then
|
||||
modpol.add_org("instance", modpol.list_users())
|
||||
end
|
||||
|
||||
ocutil.log ("modpol loaded")
|
||||
|
||||
-- ===================================================================
|
||||
-- End of file.
|
Reference in New Issue
Block a user