devilutionX icon indicating copy to clipboard operation
devilutionX copied to clipboard

Add Lua API for mana shield persistence across level changes

Open skypher opened this issue 1 month ago • 0 comments

Summary

  • Add Lua manaShield property (read/write) to Player usertype with proper network sync
  • Add new level module with type() function and dungeon type constants
  • Add LeavingLevel and EnterLevel events for level transition hooks
  • Include sample persist_mana_shield mod demonstrating the API

API

Player module

local player = require("devilutionx.player")
local p = player.self()
p.manaShield = true  -- Enable mana shield
local active = p.manaShield  -- Check if mana shield is active

Level module

local level = require("devilutionx.level")
local currentType = level.type()  -- Get current dungeon type

-- Available constants:
level.TOWN
level.CATHEDRAL
level.CATACOMBS
level.CAVES
level.HELL
level.NEST
level.CRYPT

Events

local events = require("devilutionx.events")

events.LeavingLevel.add(function()
  -- Called before leaving current level (before mana shield is cleared)
end)

events.EnterLevel.add(function()
  -- Called after entering a new level
end)

Test plan

  • [x] Unit tests for manaShield property (LuaPlayerModuleTest)
  • [x] Unit tests for Lua script access to manaShield (LuaPlayerModuleTest)
  • [x] Unit tests for level.type() function (LuaLevelModuleTest)
  • [x] Unit tests for level type constants (LuaLevelModuleTest)
  • [x] Regression test for mana shield persistence logic (ManaShieldPersistenceTest)
  • [x] Regression test for level module Lua access pattern (ManaShieldPersistenceTest)
  • [x] Integration test with real player and Lua events (ManaShieldIntegration)
  • [x] Integration test for town level type check (ManaShieldIntegration)
  • [x] Manual test - mod on, mana shield stays / mod off, default behavior of clearing mana shield on level exit.

skypher avatar Nov 26 '25 05:11 skypher