Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
bab2a4e
Clone beta
AndreLouisIssa Mar 14, 2021
2c5e8b0
Create LICENSE
AndreLouisIssa Mar 15, 2021
38d4223
Delete ModUtilHades.lua
AndreLouisIssa Mar 15, 2021
2b11a4a
Add path intercept
AndreLouisIssa Mar 16, 2021
95cc58a
should fix table.insert
AndreLouisIssa Jul 1, 2021
8cbd8c2
Fix Contexts!
AndreLouisIssa Aug 16, 2021
f74e45c
fix syntax
AndreLouisIssa Aug 16, 2021
fa78b56
compat for wrapwithin
AndreLouisIssa Aug 16, 2021
8cecd6b
Fix global intercept
AndreLouisIssa Aug 16, 2021
71326d9
Update ModUtil.Compat.lua
AndreLouisIssa Aug 16, 2021
2efa6ce
UNTESTED: add Context.Wrap and extended traversal
AndreLouisIssa Aug 16, 2021
cb9f81f
UNTESTED: (actually loads) add Context.Wrap and extended traversal
AndreLouisIssa Aug 16, 2021
f156f56
Partially tested
AndreLouisIssa Aug 16, 2021
ba85253
fixed, tested, need to add some kind of priority
AndreLouisIssa Aug 16, 2021
29ba86e
UNTESTED: extend wraps to decorators
AndreLouisIssa Aug 17, 2021
fdc8ee8
UNTESTED: (prior commit) + compat upkeep
AndreLouisIssa Aug 17, 2021
f8c6171
decorators edit loads
AndreLouisIssa Aug 17, 2021
ede5b2b
small internal rename
AndreLouisIssa Aug 17, 2021
e96172b
add Context.StaticWrap
AndreLouisIssa Aug 17, 2021
dbcd4bf
make compat use env for wrapwithin
AndreLouisIssa Aug 17, 2021
6c36d62
rename calltable and make it public
AndreLouisIssa Aug 18, 2021
d702aeb
no reason setcall had to be specific to tables
AndreLouisIssa Aug 18, 2021
a98cac9
refined use of nodes, added union, prep for separating file
AndreLouisIssa Aug 18, 2021
5afacf3
update compat with renames
AndreLouisIssa Aug 18, 2021
ce704d1
decoration suite added to the callable target
AndreLouisIssa Aug 18, 2021
0face86
split off some uninteresting definitions
AndreLouisIssa Aug 18, 2021
f7081d4
attempt fixing Content.Env (incomplete)
AndreLouisIssa Aug 21, 2021
16afff2
remove Context.Env
AndreLouisIssa Aug 21, 2021
41df669
Change patch stack operations
AndreLouisIssa Aug 21, 2021
b4c5125
Rollback callable oriented extras
AndreLouisIssa Aug 21, 2021
831cdbc
Add persistent and safe mod data system
AndreLouisIssa Aug 31, 2021
ca938bd
fix subtable data
AndreLouisIssa Aug 31, 2021
1c68656
Merge branch 'main' into beta
AndreLouisIssa Aug 31, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions ModUtil.Compat.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@

ModUtil.Mod.Register( "Compat", ModUtil )

setmetatable( ModUtil, {
__index = ModUtil.Compat
} )

ModUtil.Compat.RegisterMod = ModUtil.Mod.Register

ModUtil.Compat.ForceClosed = ModUtil.Internal.ForceClosed

ModUtil.Compat.ValueString = ModUtil.ToString.Value

ModUtil.Compat.KeyString = ModUtil.ToString.Key

ModUtil.Compat.TableKeysString = ModUtil.ToString.TableKeys

ModUtil.Compat.ToShallowString = ModUtil.ToString.Shallow

ModUtil.Compat.ToDeepString = ModUtil.ToString.Deep

ModUtil.Compat.ToDeepNoNamespacesString = ModUtil.ToString.Deep.NoNamespaces

ModUtil.Compat.ToDeepNamespacesString = ModUtil.ToString.Deep.Namespaces

ModUtil.Compat.JoinStrings = ModUtil.String.Join

ModUtil.Compat.ChunkText = ModUtil.String.Chunk

ModUtil.Compat.ReplaceTable = ModUtil.Table.Replace

ModUtil.Compat.IsUnKeyed = ModUtil.Table.UnKeyed

ModUtil.Compat.PrintToFile = ModUtil.Print.ToFile

ModUtil.Compat.DebugPrint = ModUtil.Print.Debug

ModUtil.Compat.PrintTraceback = ModUtil.Print.Traceback

ModUtil.Compat.PrintNamespaces = ModUtil.Print.Namespaces

ModUtil.Compat.PrintVariables = ModUtil.Print.Variables

ModUtil.Compat.Slice = ModUtil.Array.Slice

ModUtil.Compat.NewTable = ModUtil.Node.New

ModUtil.Compat.SafeGet = ModUtil.IndexArray.Get

ModUtil.Compat.SafeSet = ModUtil.IndexArray.Set

ModUtil.Compat.MapNilTable = ModUtil.Table.NilMerge

ModUtil.Compat.MapSetTable = ModUtil.Table.Merge

ModUtil.Compat.JoinIndexArrays = ModUtil.Array.Join

ModUtil.Compat.PathToIndexArray = ModUtil.Path.IndexArray

ModUtil.Compat.PathGet = ModUtil.Path.Get

ModUtil.Compat.PathSet = ModUtil.Path.Set

ModUtil.Compat.WrapFunction = ModUtil.IndexArray.Wrap

ModUtil.Compat.RewrapFunction = ModUtil.IndexArray.Decorate.Refresh

ModUtil.Compat.UnwrapFunction = ModUtil.IndexArray.Decorate.Pop

ModUtil.Compat.WrapBaseFunction = ModUtil.Path.Wrap

ModUtil.Compat.RewrapBaseFunction = ModUtil.Path.Decorate.Refresh

ModUtil.Compat.UnwrapBaseFunction = ModUtil.Path.Decorate.Pop

ModUtil.Compat.Override = ModUtil.IndexArray.Override

ModUtil.Compat.BaseOverride = ModUtil.Path.Override

ModUtil.Compat.GetOriginalValue = ModUtil.IndexArray.Original

ModUtil.Compat.GetOriginalBaseValue = ModUtil.Path.Original

ModUtil.Compat.RawInterface = ModUtil.Raw

ModUtil.Compat.MapVars = ModUtil.Args.Map

ModUtil.Compat.StackedUpValues = ModUtil.UpValues.Stacked

ModUtil.Compat.StackedLocals = ModUtil.Locals.Stacked

ModUtil.Compat.LocalValues = ModUtil.Locals.Values

ModUtil.Compat.LocalNames = ModUtil.Locals.Names

function ModUtil.Compat.GetBaseBottomUpValues( funcPath )
return ModUtil.UpValues( ModUtil.Path.Original( funcPath ) )
end

function ModUtil.Compat.MapTable( mapFunc, tableArg )
return ModUtil.Table.Map( tableArg, mapFunc )
end

function ModUtil.Compat.WrapWithinFunction( baseTable, indexArray, envIndexArray, wrapFunc, mod )
ModUtil.IndexArray.Context.Wrap( baseTable, indexArray, function( )
ModUtil.IndexArray.Wrap( _G, envIndexArray, wrapFunc, mod )
end )
end

function ModUtil.Compat.WrapBaseWithinFunction( funcPath, baseFuncPath, wrapFunc, mod )
ModUtil.Path.Context.Wrap( baseFuncPath, function( )
ModUtil.Path.Wrap( funcPath, wrapFunc, mod )
end )
end

function ModUtil.BaseOverrideWithinFunction( funcPath, basePath, value, mod )
ModUtil.Path.Context.Wrap( funcPath, function( )
ModUtil.Path.Override( basePath, value, mod )
end )
end
111 changes: 111 additions & 0 deletions ModUtil.Extra.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---

ModUtil.IndexArray.Context = { }

function ModUtil.IndexArray.Wrap( baseTable, indexArray, wrap, mod )
return ModUtil.IndexArray.Map( baseTable, indexArray, ModUtil.Wrap, wrap, mod )
end

ModUtil.IndexArray.Context.Wrap = ModUtil.Callable.Set( { }, function( _, baseTable, indexArray, context, mod )
return ModUtil.IndexArray.Map( baseTable, indexArray, ModUtil.Context.Wrap, context, mod )
end )

function ModUtil.IndexArray.Context.Wrap.Static( baseTable, indexArray, context, mod )
return ModUtil.IndexArray.Map( baseTable, indexArray, ModUtil.Context.Wrap.Static, context, mod )
end

ModUtil.IndexArray.Decorate = ModUtil.Callable.Set( { }, function( _, baseTable, indexArray, func, mod )
return ModUtil.IndexArray.Map( baseTable, indexArray, ModUtil.Decorate, func, mod )
end )

function ModUtil.IndexArray.Decorate.Pop( baseTable, indexArray )
return ModUtil.IndexArray.Map( baseTable, indexArray, ModUtil.Decorate.Pop )
end

function ModUtil.IndexArray.Decorate.Refresh( baseTable, indexArray )
return ModUtil.IndexArray.Map( baseTable, indexArray, ModUtil.Decorate.Refresh )
end

function ModUtil.IndexArray.Override( baseTable, indexArray, value, mod )
return ModUtil.IndexArray.Map( baseTable, indexArray, ModUtil.Override, value, mod )
end

function ModUtil.IndexArray.Restore( baseTable, indexArray )
return ModUtil.IndexArray.Map( baseTable, indexArray, ModUtil.Restore )
end

function ModUtil.IndexArray.Overriden( baseTable, indexArray )
return ModUtil.Overriden( ModUtil.IndexArray.Get( baseTable, indexArray ) )
end

function ModUtil.IndexArray.Original( baseTable, indexArray )
return ModUtil.Original( ModUtil.IndexArray.Get( baseTable, indexArray ) )
end

function ModUtil.IndexArray.ReferFunction( baseTable, indexArray )
return ModUtil.ReferFunction( function( ... )
ModUtil.Get( ModUtil.IndexArray.Get( ... ) )
end, baseTable, indexArray )
end

function ModUtil.IndexArray.ReferTable( baseTable, indexArray )
return ModUtil.ReferTable( function( ... )
ModUtil.Get( ModUtil.IndexArray.Get( ... ) )
end, baseTable, indexArray )
end

---

ModUtil.Path.Context = { }

function ModUtil.Path.Wrap( path, wrap, mod )
return ModUtil.Path.Map( path, ModUtil.Wrap, wrap, mod )
end

ModUtil.Path.Context.Wrap = ModUtil.Callable.Set( { }, function( _, path, context, mod )
return ModUtil.Path.Map( path, ModUtil.Context.Wrap, context, mod )
end )

function ModUtil.Path.Context.Wrap.Static( path, context, mod )
return ModUtil.Path.Map( path, ModUtil.Context.Wrap.Static, context, mod )
end

ModUtil.Path.Decorate = ModUtil.Callable.Set( { }, function( _, path, func, mod )
return ModUtil.Path.Map( path, ModUtil.Decorate, func, mod )
end )

function ModUtil.Path.Decorate.Pop( path )
return ModUtil.Path.Map( path, ModUtil.Decorate.Pop )
end

function ModUtil.Path.Decorate.Refresh( path )
return ModUtil.Path.Map( path, ModUtil.Decorate.Refresh )
end

function ModUtil.Path.Override( path, value, mod )
return ModUtil.Path.Map( path, ModUtil.Override, value, mod )
end

function ModUtil.Path.Restore( path )
return ModUtil.Path.Map( path, ModUtil.Restore )
end

function ModUtil.Path.Overriden( path )
return ModUtil.Overriden( ModUtil.Path.Get( path ) )
end

function ModUtil.Path.Original( path )
return ModUtil.Original( ModUtil.Path.Get( path ) )
end

function ModUtil.Path.ReferFunction( path )
return ModUtil.ReferFunction( function( ... )
ModUtil.Path.Get( ... )
end, path )
end

function ModUtil.Path.ReferTable( path )
return ModUtil.ReferTable( function( ... )
ModUtil.Path.Get( ... )
end, path )
end
87 changes: 61 additions & 26 deletions ModUtilHades.lua → ModUtil.Hades.lua
Original file line number Diff line number Diff line change
@@ -1,31 +1,57 @@

ModUtil.RegisterMod( "Hades", ModUtil )
ModUtil.Mod.Register( "Hades", ModUtil )

ModUtil.MapSetTable( ModUtil.Hades, {
-- Global Interception

--[[
Intercept global keys which are objects to return themselves
This way we can use other namespaces for UI etc
--]]

local callableCandidateTypes = ModUtil.Internal.callableCandidateTypes

local function isPath( path )
return path:find("[.]")
and not path:find("[.][.]+")
and not path:find("^[.]")
and not path:find("[.]$")
end

local function routeKey( self, key )
local t = type( key )
if t == "string" and isPath( key ) then
return ModUtil.Path.Get( key )
end
if callableCandidateTypes[ t ] then
return key
end
end

do

local meta = getmetatable( _ENV ) or { }
if meta.__index then
meta.__index = ModUtil.Wrap( meta.__index, function( base, self, key )
local value = base( self, key )
if value ~= nil then return value end
return routeKey( self, key )
end, ModUtil.Hades )
else
meta.__index = routeKey
end

setmetatable( _ENV, meta )

end
---

ModUtil.Table.Merge( ModUtil.Hades, {
PrintStackHeight = 10,
PrintStackCapacity = 80
} )

ModUtil.Anchors.PrintOverhead = {}

-- Screen Handling

OnAnyLoad{ function()
if ModUtil.Hades.UnfreezeLoop then return end
ModUtil.Hades.UnfreezeLoop = true
thread( function()
while ModUtil.Hades.UnfreezeLoop do
wait(15)
if ModUtil.SafeGet(CurrentRun,{'Hero','FreezeInputKeys'}) then
if (not AreScreensActive()) and (not IsInputAllowed({})) then
UnfreezePlayerUnit()
DisableShopGamepadCursor()
end
end
end
end)
end}

-- Menu Handling

function ModUtil.Hades.CloseMenu( screen, button )
Expand Down Expand Up @@ -305,7 +331,7 @@ end

function ModUtil.Hades.PrintStackChunks( text, linespan, ... )
if not linespan then linespan = 90 end
for _,s in ipairs( ModUtil.ChunkText( text, linespan,ModUtil.Hades.PrintStackCapacity ) ) do
for _,s in ipairs( ModUtil.String.Chunk( text, linespan, ModUtil.Hades.PrintStackCapacity ) ) do
ModUtil.Hades.PrintStack( s, ... )
end
end
Expand Down Expand Up @@ -349,13 +375,13 @@ function ModUtil.Hades.NewMenuYesNo( group, closeFunc, openFunc, yesFunc, noFunc
Attach({ Id = components.Icon.Id, DestinationId = components.Background.Id, OffsetX = 0, OffsetY = -50})
SetAnimation({ Name = icon, DestinationId = components.Icon.Id, Scale = iconScale })

ModUtil.NewTable(ModUtil.Anchors.Menu[group], "Funcs")
ModUtil.Nodes.New(ModUtil.Anchors.Menu[group], "Funcs")
ModUtil.Anchors.Menu[group].Funcs={
Yes = function(screen, button)
if not yesFunc(screen,button) then
ModUtil.Hades.CloseMenuYesNo(screen,button)
end
end,
end,
No = function(screen, button)
if not noFunc(screen,button) then
ModUtil.Hades.CloseMenuYesNo(screen,button)
Expand All @@ -365,11 +391,11 @@ function ModUtil.Hades.NewMenuYesNo( group, closeFunc, openFunc, yesFunc, noFunc

components.CloseButton = CreateScreenComponent({ Name = "ButtonClose", Scale = 0.7, Group = group })
Attach({ Id = components.CloseButton.Id, DestinationId = components.Background.Id, OffsetX = 0, OffsetY = ScreenCenterY - 315 })
components.CloseButton.OnPressedFunctionName = "ModUtil.Hades.CloseMenuYesNo"
components.CloseButton.OnPressedFunctionName = ModUtil.Path.ReferFunction( "ModUtil.Hades.CloseMenuYesNo" )
components.CloseButton.ControlHotkey = "Cancel"

components.YesButton = CreateScreenComponent({ Name = "BoonSlot1", Group = group, Scale = 0.35, })
components.YesButton.OnPressedFunctionName = "ModUtil.Anchors.Menu."..group..".Funcs.Yes"
components.YesButton.OnPressedFunctionName = ModUtil.Path.ReferFunction( "ModUtil.Anchors.Menu."..group..".Funcs.Yes" )
SetScaleX({Id = components.YesButton.Id, Fraction = 0.75})
SetScaleY({Id = components.YesButton.Id, Fraction = 1.15})
Attach({ Id = components.YesButton.Id, DestinationId = components.Background.Id, OffsetX = -150, OffsetY = 75 })
Expand All @@ -379,7 +405,7 @@ function ModUtil.Hades.NewMenuYesNo( group, closeFunc, openFunc, yesFunc, noFunc
})

components.NoButton = CreateScreenComponent({ Name = "BoonSlot1", Group = group, Scale = 0.35, })
components.NoButton.OnPressedFunctionName = "ModUtil.Anchors.Menu."..group..".Funcs.No"
components.NoButton.OnPressedFunctionName = ModUtil.Path.ReferFunction( "ModUtil.Anchors.Menu."..group..".Funcs.No" )
SetScaleX({Id = components.NoButton.Id, Fraction = 0.75})
SetScaleY({Id = components.NoButton.Id, Fraction = 1.15})
Attach({ Id = components.NoButton.Id, DestinationId = components.Background.Id, OffsetX = 150, OffsetY = 75 })
Expand All @@ -401,4 +427,13 @@ end
function ModUtil.Hades.RandomElement( tableArg, rng )
local Collapsed = CollapseTable( tableArg )
return Collapsed[RandomInt( 1, #Collapsed, rng )]
end

-- Internal Access

do
local ups = ModUtil.UpValues( function( )
return callableCandidateTypes, isPath, routeKey
end )
ModUtil.Entangled.Union.Add( ModUtil.Internal, ups )
end
Loading