mirror of
https://github.com/cave-story-randomizer/cave-story-randomizer
synced 2024-11-28 09:43:15 +00:00
Add item deck.
This commit is contained in:
parent
ea1d0720fc
commit
768895badc
21
src/database/items.lua
Normal file
21
src/database/items.lua
Normal file
|
@ -0,0 +1,21 @@
|
|||
return {
|
||||
-- Weapons
|
||||
wPolar = {
|
||||
name = "Polar Star",
|
||||
map = "Pole",
|
||||
getText = "Got the =Polar Star=!",
|
||||
command = "<AM+0002:0000",
|
||||
displayCmd = "<GIT0002",
|
||||
kind = "weapon",
|
||||
},
|
||||
-- Items
|
||||
iPanties = {
|
||||
name = "Curly's Panties",
|
||||
map = "CurlyS",
|
||||
-- getText = "Found =Curly's Underwear=.",
|
||||
getText = "Found =Curly's Panties=.",
|
||||
command = "<IT+0035",
|
||||
displayCmd = "<GIT1035",
|
||||
kind = "item",
|
||||
},
|
||||
}
|
45
src/item_deck.lua
Normal file
45
src/item_deck.lua
Normal file
|
@ -0,0 +1,45 @@
|
|||
local C = Class:extend()
|
||||
|
||||
local ITEM_DATA = require 'database.items'
|
||||
|
||||
function C:new()
|
||||
self._left = {}
|
||||
self._indexMap = {}
|
||||
for k, v in pairs(ITEM_DATA) do
|
||||
local item = _.clone(v)
|
||||
table.insert(self._left, item)
|
||||
self._indexMap[item] = #self._left
|
||||
end
|
||||
end
|
||||
|
||||
local function _filterAny(item) return true end
|
||||
local function _filterWeapon(item) return item.kind == "weapon" end
|
||||
|
||||
function C:getAny()
|
||||
return self:_getItem(_filterAny)
|
||||
end
|
||||
|
||||
function C:getWeapon()
|
||||
return self:_getItem(_filterWeapon)
|
||||
end
|
||||
|
||||
function C:_getItem(filterFn)
|
||||
-- Filter down to only applicable items.
|
||||
local applicable = {}
|
||||
for _, item in ipairs(self._left) do
|
||||
if filterFn(item) then
|
||||
table.insert(applicable, item)
|
||||
end
|
||||
end
|
||||
assert(#applicable >= 1, 'No applicable items!')
|
||||
|
||||
-- Select an item.
|
||||
local selected = _.sample(applicable)
|
||||
local index = self._indexMap[selected]
|
||||
table.remove(self._left, index)
|
||||
self._indexMap[selected] = nil
|
||||
|
||||
return selected
|
||||
end
|
||||
|
||||
return C
|
25
src/main.lua
25
src/main.lua
|
@ -20,26 +20,6 @@ function logNotice(...) _log(3, 'NOTICE: ', ...) end
|
|||
function logInfo(...) _log(4, 'INFO: ', ...) end
|
||||
function logDebug(...) _log(5, 'DEBUG: ', ...) end
|
||||
|
||||
local ITEM_DATA = {
|
||||
-- Weapons
|
||||
wPolar = {
|
||||
name = "Polar Star",
|
||||
map = "Pole",
|
||||
getText = "Got the =Polar Star=!",
|
||||
command = "<AM+0002:0000",
|
||||
displayCmd = "<GIT0002",
|
||||
},
|
||||
-- Items
|
||||
iPanties = {
|
||||
name = "Curly's Panties",
|
||||
map = "CurlyS",
|
||||
-- getText = "Found =Curly's Underwear=.",
|
||||
getText = "Found =Curly's Panties=.",
|
||||
command = "<IT+0035",
|
||||
displayCmd = "<GIT1035",
|
||||
},
|
||||
}
|
||||
|
||||
local TSC_FILES = {
|
||||
'Pole.tsc',
|
||||
}
|
||||
|
@ -70,6 +50,11 @@ function love.directorydropped(path)
|
|||
-- decoded = stringReplace(decoded, ITEM_DATA.wPolar.displayCmd, ITEM_DATA.iPanties.displayCmd)
|
||||
end
|
||||
|
||||
local ItemDeck = require 'item_deck'
|
||||
local itemDeck = ItemDeck()
|
||||
print(Serpent.line(itemDeck:getWeapon()))
|
||||
print(Serpent.line(itemDeck:getAny()))
|
||||
|
||||
tscFiles['Pole.tsc']:writeTo('Testing.tsc')
|
||||
|
||||
-- Unmount
|
||||
|
|
Loading…
Reference in a new issue