Skip to content

Commit

Permalink
fix monoid
Browse files Browse the repository at this point in the history
  • Loading branch information
fluxionary committed Aug 13, 2019
1 parent 054eabd commit 605a68b
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,37 @@ local function bound(min, v, max)
end

more_monoids.sunlight_monoid = player_monoids.make_monoid({
-- additive monoid, values between -1 and 1, cuts off if sum goes beyond those
combine = function(sunlight1, sunlight2)
return math.max(sunlight1, sunlight2)
if not sunlight1 then
return sunlight2
elseif not sunlight2 then
return sunlight1
else
return sunlight1 + sunlight2
end
end,
fold = function(t)
return #t == 0 and 0 or math.max(unpack(t))
local size = 0
local sum = 0
for _, v in pairs(t) do
if v then
sum = sum + v
size = size + 1
end
end
if size == 0 then
return nil
else
return sum
end
end,
identity = 0,
identity = nil,
apply = function(sunlight, player)
player:override_day_night_ratio(bound(0, sunlight, 1))
if sunlight then
sunlight = bound(0, (sunlight + 1) / 2, 1)
end
player:override_day_night_ratio(sunlight)
end,
on_change = function() return end,
})

0 comments on commit 605a68b

Please sign in to comment.