forked from minetest-mods/player_monoids
Fix def missing and spacetabs
This commit is contained in:
parent
025f1d398a
commit
de25711530
17
init.lua
17
init.lua
@ -13,6 +13,7 @@ local mon_meta = {}
|
||||
mon_meta.__index = mon_meta
|
||||
|
||||
-- A monoid object is a table with the following fields:
|
||||
-- def: The monoid definition
|
||||
-- player_map: A map from player names to their effect tables. Effect tables
|
||||
-- are maps from effect IDs to values.
|
||||
-- value_cache: A map from player names to the cached value for the monoid.
|
||||
@ -45,6 +46,8 @@ player_monoids.make_monoid = monoid
|
||||
function mon_meta:add_change(player, value)
|
||||
local p_name = player:get_player_name()
|
||||
|
||||
local def = self.def
|
||||
|
||||
local p_effects = self.player_map[p_name]
|
||||
if p_effects == nil then
|
||||
p_effects = {}
|
||||
@ -62,11 +65,11 @@ function mon_meta:add_change(player, value)
|
||||
|
||||
local old_total = self.value_cache[p_name]
|
||||
p_effects[actual_id] = value
|
||||
local new_total = self.fold(p_effects)
|
||||
local new_total = def.fold(p_effects)
|
||||
self.value_cache[p_name] = new_total
|
||||
|
||||
self.apply(new_total, player)
|
||||
self.on_change(old_total, new_total, player)
|
||||
def.apply(new_total, player)
|
||||
def.on_change(old_total, new_total, player)
|
||||
end
|
||||
|
||||
function mon_meta:del_change(player, id)
|
||||
@ -77,14 +80,14 @@ function mon_meta:del_change(player, id)
|
||||
|
||||
local old_total = self.value_cache[p_name]
|
||||
p_effects[id] = nil
|
||||
local new_total = self.fold(p_effects)
|
||||
local new_total = def.fold(p_effects)
|
||||
self.value_cache[p_name] = new_total
|
||||
|
||||
self.apply(new_total, player)
|
||||
self.on_change(old_total, new_total, player)
|
||||
def.apply(new_total, player)
|
||||
def.on_change(old_total, new_total, player)
|
||||
end
|
||||
|
||||
function mon_meta:value(player)
|
||||
local p_name = player:get_player_name()
|
||||
return self.value_cache[p_name] or self.identity
|
||||
return self.value_cache[p_name] or self.def.identity
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user