Provide hasMark methods (#180)

It provides two methods `Player:hasMark` and `Card:hasMark` for
determining if the player/card has the mark, which is more expressive
than `xxx:getMark` when only checking for the existence.

By the way, xxx:hasMark may directly determine a `Mark` in xxx.mark, for
which I added `table:hasKey` method in `util.lua`, but currently the
code still checks if the result of `xxx:getMark` is not 0.

---


提供了`Player:hasMark`和`Card:hasMark`两个方法,用于在只需要判断是否有标记时可以直接使用`xxx:hasMark`,相比使用`xxx:getMark`而言更加表达代码的作用。


顺带一提,`xxx:hasMark`应该可以直接判断`Mark`是否在`xxx.mark`里,我在`util.lua`里添加了`table:hasKey`的方法用于判断,但目前的代码还是判断`xxx:getMark`的结果是否不为0。
This commit is contained in:
Rintim 2023-06-09 17:23:24 +08:00 committed by GitHub
parent 1556da2f13
commit 04f1009075
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -322,11 +322,18 @@ end
--- 获取卡牌对应Mark的数量。 --- 获取卡牌对应Mark的数量。
---@param mark string @ 标记 ---@param mark string @ 标记
---@param count integer @ 为标记删除的数量 ---@return integer
function Card:getMark(mark) function Card:getMark(mark)
return (self.mark[mark] or 0) return (self.mark[mark] or 0)
end end
--- 判定卡牌是否拥有对应的Mark。
---@param mark string @ 标记
---@return boolean
function Card:hasMark(mark)
return self:getMark(mark) ~= 0
end
--- 获取卡牌有哪些Mark。 --- 获取卡牌有哪些Mark。
function Card:getMarkNames() function Card:getMarkNames()
local ret = {} local ret = {}

View File

@ -192,11 +192,18 @@ end
--- 获取角色对应Mark的数量。 --- 获取角色对应Mark的数量。
---@param mark string @ 标记 ---@param mark string @ 标记
---@param count integer @ 为标记删除的数量 ---@return integer
function Player:getMark(mark) function Player:getMark(mark)
return (self.mark[mark] or 0) return (self.mark[mark] or 0)
end end
--- 判定角色是否拥有对应的Mark。
---@param mark string @ 标记
---@return boolean
function Player:hasMark(mark)
return self:getMark(mark) ~= 0
end
--- 获取角色有哪些Mark。 --- 获取角色有哪些Mark。
function Player:getMarkNames() function Player:getMarkNames()
local ret = {} local ret = {}