improvement: use the predicate system for events
This commit is contained in:
parent
d2db4e91a3
commit
f7221971c3
6 changed files with 19 additions and 54 deletions
|
@ -1,6 +1,7 @@
|
||||||
return {
|
return {
|
||||||
["actions"] = {
|
["actions"] = {
|
||||||
{"dialogBox", "haveMoney:lt:300", "You seem to be a bit short on money...", "Mighty", ""},
|
{"dialogBox", "haveMoney:eq:0", "You don't have any rings !", "Mighty", ""},
|
||||||
|
{"dialogBox", {"haveMoney:lt:300", "haveMoney:gt:0"}, "You seems to only have a few rings", "Mighty", ""},
|
||||||
{"dialogBox", "haveMoney:ge:300", "Wow you're rich !", "Mighty", ""}
|
{"dialogBox", "haveMoney:ge:300", "Wow you're rich !", "Mighty", ""}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,7 +2,8 @@ return {
|
||||||
["actions"] = {
|
["actions"] = {
|
||||||
{"dialogBox", "", "Hi Big Blue. Let's test a bit the choice dialog.", "Rouge", ""},
|
{"dialogBox", "", "Hi Big Blue. Let's test a bit the choice dialog.", "Rouge", ""},
|
||||||
{"optionBox", "", "What do you want ?", "Rouge", "", "Ring", "A health fruit", "Battling badnics", "optionFlag"},
|
{"optionBox", "", "What do you want ?", "Rouge", "", "Ring", "A health fruit", "Battling badnics", "optionFlag"},
|
||||||
{"dialogBox", "optionFlag:1", "Oooh, in need of cash ?", "Rouge", ""},
|
{"dialogBox", {"optionFlag:1", "haveMoney:lt:300"}, "Oooh, in need of cash ?", "Rouge", ""},
|
||||||
|
{"dialogBox", {"optionFlag:1", "haveMoney:gt:300"}, "You doesn't seem that poor to me.", "Rouge", ""},
|
||||||
{"dialogBox", "optionFlag:2", "Did you failed your battle ? Well, you'll have to train more", "Rouge", ""},
|
{"dialogBox", "optionFlag:2", "Did you failed your battle ? Well, you'll have to train more", "Rouge", ""},
|
||||||
{"dialogBox", "optionFlag:3", "Let's see if you can keep it up", "Rouge", ""},
|
{"dialogBox", "optionFlag:3", "Let's see if you can keep it up", "Rouge", ""},
|
||||||
}
|
}
|
||||||
|
|
12
sonic-radiance.love/game/events/conditions.lua
Normal file
12
sonic-radiance.love/game/events/conditions.lua
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
local Conditions = {}
|
||||||
|
|
||||||
|
function Conditions.haveMoney(cond, predicate, asker)
|
||||||
|
return predicate.utils.testVariables(game.loot.rings , cond[2], cond[3])
|
||||||
|
end
|
||||||
|
|
||||||
|
function Conditions.default(cond, predicate, asker)
|
||||||
|
local flag = predicate.utils.merge(cond)
|
||||||
|
return asker:haveFlag(flag)
|
||||||
|
end
|
||||||
|
|
||||||
|
return Conditions
|
|
@ -1,8 +0,0 @@
|
||||||
local Conditions = {}
|
|
||||||
local ConditionsUtils = require "game.events.conditions.utils"
|
|
||||||
|
|
||||||
function Conditions.haveMoney(cond)
|
|
||||||
return ConditionsUtils.testVariables(game.loot.rings , cond[2], cond[3])
|
|
||||||
end
|
|
||||||
|
|
||||||
return Conditions
|
|
|
@ -1,31 +0,0 @@
|
||||||
local ConditionsUtils = {}
|
|
||||||
|
|
||||||
function ConditionsUtils.testVariables(var1, testType, var2)
|
|
||||||
local var2 = tonumber(var2)
|
|
||||||
if (testType == "eq" and var1 == var2) then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
if (testType == "ne" and var1 ~= var2) then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
if (testType == "gt" and var1 > var2) then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
if (testType == "ge" and var1 >= var2) then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
if (testType == "lt" and var1 < var2) then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
if (testType == "le" and var1 <= var2) then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
function ConditionsUtils.testBool(bool, boolType)
|
|
||||||
return (bool == (boolType == "V"))
|
|
||||||
end
|
|
||||||
|
|
||||||
return ConditionsUtils;
|
|
|
@ -3,6 +3,7 @@ local EventManager = Object:extend()
|
||||||
local stepObjectList = require "game.events.event"
|
local stepObjectList = require "game.events.event"
|
||||||
local Conditions = require "game.events.conditions"
|
local Conditions = require "game.events.conditions"
|
||||||
|
|
||||||
|
local Predicates = require "birb.classes.predicate"
|
||||||
|
|
||||||
function EventManager:new(scene)
|
function EventManager:new(scene)
|
||||||
self.scene = scene
|
self.scene = scene
|
||||||
|
@ -37,19 +38,8 @@ function EventManager:addFlag(flagname, flagcontent)
|
||||||
end
|
end
|
||||||
|
|
||||||
function EventManager:testCondition(condition)
|
function EventManager:testCondition(condition)
|
||||||
if (utils.string.isEmpty(condition)) then
|
local predicate = Predicates.createPredicate(condition, Conditions, self)
|
||||||
return true
|
return predicate:solve()
|
||||||
end
|
|
||||||
local conditionArgs = utils.string.split(condition, ":")
|
|
||||||
if (Conditions[conditionArgs[1]] == nil) then
|
|
||||||
return self:haveFlag(condition)
|
|
||||||
else
|
|
||||||
local conditionFulfilled = Conditions[conditionArgs[1]](conditionArgs)
|
|
||||||
if (conditionArgs[#conditionArgs] == "not") then
|
|
||||||
conditionFulfilled = (not conditionFulfilled)
|
|
||||||
end
|
|
||||||
return conditionFulfilled
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function EventManager:haveFlag(flagToTest)
|
function EventManager:haveFlag(flagToTest)
|
||||||
|
|
Loading…
Reference in a new issue