mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-02-24 15:04:00 +00:00
Add "default" and "none" mod compat scripts
This commit is contained in:
parent
a2e7e4a670
commit
4732d10d78
7 changed files with 96 additions and 50 deletions
|
@ -358,7 +358,10 @@ ModType Mod::getTypeFromXML(XMLElement *xml) // should be <AquariaMod>...</Aquar
|
|||
|
||||
bool Mod::loadCompatScript()
|
||||
{
|
||||
if(!compatScript.length() || dsq->runScript("scripts/compat/" + compatScript + ".lua"))
|
||||
std::string cs = compatScript.c_str();
|
||||
if(cs.empty())
|
||||
cs = "default";
|
||||
if(dsq->runScript("scripts/compat/" + cs + ".lua"))
|
||||
return true;
|
||||
|
||||
dsq->scriptInterface.reset();
|
||||
|
|
5
files/scripts/compat/default.lua
Normal file
5
files/scripts/compat/default.lua
Normal file
|
@ -0,0 +1,5 @@
|
|||
-- Loaded when mod compat setting is empty or does not exist.
|
||||
-- Does a few basic adjustments but does not offer compatbility with legacy mods.
|
||||
-- (In this case and for 1.1.x/Steam compatibility, use "legacy" or "legacy-strict")
|
||||
|
||||
dofile("scripts/compat/internal/osestubs.lua")
|
|
@ -1,5 +1,7 @@
|
|||
-- Removes more functions than to no-deprecated
|
||||
-- Some original game scripts will not work with this!
|
||||
-- This is fine to use when developing a mod, but do NOT distribute a mod with this set!
|
||||
-- (Consider using "no-deprecated", "default", "none" or simply leave the compat tag away)
|
||||
|
||||
dofile("scripts/compat/no-deprecated.lua")
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
-- Most that had no function are dummied out, some existed but threw errors,
|
||||
-- and others were registered under different names.
|
||||
|
||||
local util = dofile("scripts/compat/internal/util.lua")
|
||||
|
||||
local NULLREF = 0
|
||||
|
||||
-- these did something but are now gone
|
||||
|
@ -88,7 +90,7 @@ end
|
|||
local REPLACED_FUNCTIONS =
|
||||
{
|
||||
-- alternate names, old name on the left, new name on the right
|
||||
-- (Might want tp use the name on the right, they existed in 1.1.1 already)
|
||||
-- (Might want to use the name on the right, they existed in 1.1.1 already)
|
||||
entity_getPositionX = entity_x,
|
||||
entity_getPositionY = entity_y,
|
||||
entity_applyRandomForce = entity_addRandomVel,
|
||||
|
@ -113,52 +115,8 @@ local REPLACED_FUNCTIONS =
|
|||
entity_watchSwimToEntitySide = entity_watchSwimToEntitySide,
|
||||
}
|
||||
|
||||
----------------------------------------------------
|
||||
---- Functors to generate replacement function -----
|
||||
----------------------------------------------------
|
||||
|
||||
local warnLog = (isDeveloperKeys() and errorLog) or debugLog
|
||||
|
||||
-- generate function that warns when called and returns nil
|
||||
local function warndummy(name)
|
||||
warnLog("Dummy function: " .. name .. "() - no longer present in the current API, fix the script!")
|
||||
end
|
||||
local function mkwarn(name)
|
||||
return function() warndummy(name) end
|
||||
end
|
||||
|
||||
-- generate function that warns when called and returns a non-nil fixed value
|
||||
local function mkwarnret(name, param)
|
||||
return function() warndummy(name) return param end
|
||||
end
|
||||
|
||||
-- generate silent dummy that does nothing when called and returns nil
|
||||
local function dummy() end
|
||||
local function mkdummy(name, param)
|
||||
return dummy
|
||||
end
|
||||
|
||||
|
||||
-- register existing function under a different name
|
||||
local function mkalias(name, param)
|
||||
return assert(param, name)
|
||||
end
|
||||
|
||||
local function makestubs(tab, gen)
|
||||
for name, param in pairs(tab) do
|
||||
if rawget(_G, name) then
|
||||
errorLog("WARNING: oldfunctions.lua: function " .. name .. " already exists")
|
||||
else
|
||||
local f = gen(name, param)
|
||||
rawset(_G, name, f)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
----------------
|
||||
---- Do it! ----
|
||||
----------------
|
||||
makestubs(WARN_FUNCTIONS, mkwarn)
|
||||
makestubs(WARN_FUNCTIONS_VAL, mkwarnret)
|
||||
makestubs(DUMMY_FUNCTIONS, mkdummy)
|
||||
makestubs(REPLACED_FUNCTIONS, mkalias)
|
||||
util.makestubs(WARN_FUNCTIONS, util.mkwarn)
|
||||
util.makestubs(WARN_FUNCTIONS_VAL, util.mkwarnret)
|
||||
util.makestubs(DUMMY_FUNCTIONS, util.mkdummy)
|
||||
util.makestubs(REPLACED_FUNCTIONS, util.mkalias)
|
||||
|
|
23
files/scripts/compat/internal/osestubs.lua
Normal file
23
files/scripts/compat/internal/osestubs.lua
Normal file
|
@ -0,0 +1,23 @@
|
|||
-- This takes care of providing some deprecated functions that were added and later removed again
|
||||
-- in the OSE version of Aquaria.
|
||||
|
||||
local util = dofile("scripts/compat/internal/util.lua")
|
||||
|
||||
local WARN_FUNCTIONS = {
|
||||
-- git commit f466e1e7c8d0a0a3ea40048a0a944419f9373dfb
|
||||
obj_setOverrideRenderPass = true,
|
||||
quad_setOverrideRenderPass = true,
|
||||
bone_setOverrideRenderPass = true,
|
||||
shot_setOverrideRenderPass = true,
|
||||
beam_setOverrideRenderPass = true,
|
||||
web_setOverrideRenderPass = true,
|
||||
text_setOverrideRenderPass = true,
|
||||
pe_setOverrideRenderPass = true,
|
||||
}
|
||||
|
||||
local REPLACED_FUNCTIONS = {
|
||||
entity_setOverrideRenderPass = entity_setRenderPass,
|
||||
}
|
||||
|
||||
util.makestubs(WARN_FUNCTIONS, util.mkwarn)
|
||||
util.makestubs(REPLACED_FUNCTIONS, util.mkalias)
|
53
files/scripts/compat/internal/util.lua
Normal file
53
files/scripts/compat/internal/util.lua
Normal file
|
@ -0,0 +1,53 @@
|
|||
----------------------------------------------------
|
||||
---- Functors to generate replacement functions -----
|
||||
----------------------------------------------------
|
||||
|
||||
local warnLog = (isDeveloperKeys() and errorLog) or debugLog
|
||||
|
||||
-- generate function that warns when called and returns nil
|
||||
local function warndummy(name)
|
||||
warnLog("Dummy function: " .. name .. "() - no longer present in the current API, fix the script!")
|
||||
end
|
||||
local function mkwarn(name)
|
||||
return function() warndummy(name) end
|
||||
end
|
||||
|
||||
-- generate function that warns when called and returns a non-nil fixed value
|
||||
local function mkwarnret(name, param)
|
||||
return function() warndummy(name) return param end
|
||||
end
|
||||
|
||||
-- generate silent dummy that does nothing when called and returns nil
|
||||
local function dummy() end
|
||||
local function mkdummy(name)
|
||||
return dummy
|
||||
end
|
||||
|
||||
|
||||
-- register existing function under a different name
|
||||
local function mkalias(name, param)
|
||||
if type(param) == "string" then
|
||||
param = _G[param]
|
||||
end
|
||||
return assert(param, name)
|
||||
end
|
||||
|
||||
local function makestubs(tab, gen)
|
||||
for name, param in pairs(tab) do
|
||||
if rawget(_G, name) then
|
||||
errorLog("WARNING: oldfunctions.lua: function " .. name .. " already exists")
|
||||
else
|
||||
local f = gen(name, param)
|
||||
rawset(_G, name, f)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
warnLog = warnLog,
|
||||
warndummy = warndummy,
|
||||
mkwarn = mkwarn,
|
||||
mkdummy = mkdummy,
|
||||
mkalias = mkalias,
|
||||
makestubs = makestubs,
|
||||
}
|
2
files/scripts/compat/none.lua
Normal file
2
files/scripts/compat/none.lua
Normal file
|
@ -0,0 +1,2 @@
|
|||
-- No compatibility layer at all.
|
||||
-- Don't do anything here.
|
Loading…
Add table
Reference in a new issue