Skip to content

Commit

Permalink
feat: artifact/card carousel, rework of game flow
Browse files Browse the repository at this point in the history
  • Loading branch information
BigJk committed Jan 10, 2024
1 parent a77cf64 commit f59d0e1
Show file tree
Hide file tree
Showing 73 changed files with 1,142 additions and 1,117 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ node_modules/
cpu*
heap*
profile*
file_index.json
file_index.json
__old/
File renamed without changes.
42 changes: 42 additions & 0 deletions assets/scripts/_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,48 @@ function assert_chain(tests)
return nil
end

---assert_card_present asserts that the player's first card is of a certain type, returning an error message if not
---@param id type_id
---@return string|nil
function assert_card_present(id)
local cards = get_cards(PLAYER_ID)

if not cards[1] then
return "Card not in hand"
end

local card = get_card_instance(cards[1])
if card.type_id ~= id then
return "Card has wrong type: " .. card.type_id
end

return nil
end

---assert_cast_damage asserts that the player's first card deals a certain amount of damage, returning an error message if not
---@param id type_id
---@param dmg number
---@return string|nil
function assert_cast_damage(id, dmg)
local dummy = add_actor_by_enemy("DUMMY")
local cards = get_cards(PLAYER_ID)

if not cards[1] then
return "Card not in hand"
end

local card = get_card_instance(cards[1])
if card.type_id ~= id then
return "Card has wrong type: " .. card.type_id
end

cast_card(cards[1], dummy)

if get_actor(dummy).hp ~= 100 - dmg then
return "Expected " .. tostring(100 - dmg) .. " health, got " .. get_actor(dummy).hp
end
end

---assert_status_effect_count asserts that the player has a certain number of status effects, returning an error message if not
---@param count number
---@return string|nil
Expand Down
128 changes: 128 additions & 0 deletions assets/scripts/_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,131 @@
function highlight(val)
return text_underline(text_bold("[" .. tostring(val) .. "]"))
end

---highlight_warn some value with warning colors
---@param val any
function highlight_warn(val)
return text_underline(text_bold(text_red("[" .. tostring(val) .. "]")))
end

---choose_weighted chooses an item from a list of choices, with a weight for each item.
---@param choices table
---@param weights number[]
---@return string
function choose_weighted(choices, weights)
print(choices, weights)

local total_weight = 0
for _, weight in ipairs(weights) do
total_weight = total_weight + weight
end

local random = math.random() * total_weight
for i, weight in ipairs(weights) do
random = random - weight
if random <= 0 then
return choices[i]
end
end

return choices[#choices]
end

---table.contains check if a table contains an element.
function table.contains(table, element)
for _, value in pairs(table) do
if value == element then
return true
end
end
return false
end

---find_by_tags find all items with the given tags.
---@param items artifact|card
---@param tags string[]
function find_by_tags(items, tags)
local found = {}
for _, item in pairs(items) do
for _, tag in pairs(tags) do
if item.tags == nil then
goto continue
end
if not table.contains(item.tags, tag) then
goto continue
end
end

table.insert(found, item)

::continue::
end
return found
end

---find_artifacts_by_tags find all artifacts with the given tags.
---@param tags string[]
---@return artifact[]
function find_artifacts_by_tags(tags)
return find_by_tags(registered.artifact, tags)
end

---find_cards_by_tags find all cards with the given tags.
---@param tags string[]
---@return card[]
function find_cards_by_tags(tags)
return find_by_tags(registered.card, tags)
end

---find_events_by_tags find all events with the given tags.
---@param tags string[]
---@return event[]
function find_events_by_tags(tags)
return find_by_tags(registered.event, tags)
end

---choose_weighted_by_price choose a random item from the given list, weighted by price.
---@param items artifact|card
---@return string
function choose_weighted_by_price(items)
return choose_weighted(
fun.iter(items):map(function(item) return item.id or item.type_id end):totable(),
fun.iter(items):map(function(item) return item.price end):totable()
)
end

---clear_cards_by_tag remove all cards with tag.
---@param tag string tag to remove
---@param excluded? table optional table of guids to exclude.
function clear_cards_by_tag(tag, excluded)
for _, guid in pairs(get_cards(PLAYER_ID)) do
if excluded and table.contains(excluded, guid) then
goto continue
end

local tags = get_card(guid).tags
if table.contains(tags, tag) then
remove_card(guid)
end

::continue::
end
end

---clear_artifacts_by_tag remove all artifacts with tag.
---@param tag string tag to remove
---@param excluded table optional table of guids to exclude.
function clear_artifacts_by_tag(tag, excluded)
for _, guid in pairs(get_artifacts(PLAYER_ID)) do
if excluded and table.contains(excluded, guid) then
goto continue
end

local tags = get_artifact(guid).tags
if table.contains(tags, tag) then
remove_artifact(guid)
end

::continue::
end
end
14 changes: 0 additions & 14 deletions assets/scripts/artifacts/bag_of_holding.lua

This file was deleted.

21 changes: 0 additions & 21 deletions assets/scripts/artifacts/deflector_shield.lua

This file was deleted.

26 changes: 0 additions & 26 deletions assets/scripts/artifacts/gigantic_strength.lua

This file was deleted.

22 changes: 0 additions & 22 deletions assets/scripts/artifacts/gold_converter.lua

This file was deleted.

14 changes: 0 additions & 14 deletions assets/scripts/artifacts/holy_grail.lua

This file was deleted.

12 changes: 0 additions & 12 deletions assets/scripts/artifacts/juicy_fruit.lua

This file was deleted.

12 changes: 0 additions & 12 deletions assets/scripts/artifacts/radiant_seed.lua

This file was deleted.

14 changes: 0 additions & 14 deletions assets/scripts/artifacts/repulsion_stone.lua

This file was deleted.

16 changes: 0 additions & 16 deletions assets/scripts/artifacts/short_radiance.lua

This file was deleted.

14 changes: 0 additions & 14 deletions assets/scripts/artifacts/spiked_plant.lua

This file was deleted.

22 changes: 0 additions & 22 deletions assets/scripts/cards/berserker_rage.lua

This file was deleted.

Loading

0 comments on commit f59d0e1

Please sign in to comment.