feat: initial work on inventory system
This commit is contained in:
parent
c5a6eb0a2b
commit
abc415c7f3
7 changed files with 255 additions and 29 deletions
51
sonic-radiance.love/datas/gamedata/items/init.lua
Normal file
51
sonic-radiance.love/datas/gamedata/items/init.lua
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
return {
|
||||||
|
[1] = {
|
||||||
|
name = "medicines",
|
||||||
|
fullname = "Medicines",
|
||||||
|
description = "Healing items",
|
||||||
|
inBattle = true
|
||||||
|
},
|
||||||
|
[2] = {
|
||||||
|
name = "powerups",
|
||||||
|
fullname = "Powerups",
|
||||||
|
description = "Helping items usable in battle",
|
||||||
|
inBattle = true
|
||||||
|
},
|
||||||
|
[3] = {
|
||||||
|
name = "wisps",
|
||||||
|
fullname = "Wisps",
|
||||||
|
description = "Little alien creatures that can attack ennemies",
|
||||||
|
inBattle = true
|
||||||
|
},
|
||||||
|
[4] = {
|
||||||
|
name = "gloves",
|
||||||
|
fullname = "Gloves",
|
||||||
|
description = "All equipables gloves",
|
||||||
|
inBattle = false
|
||||||
|
},
|
||||||
|
[5] = {
|
||||||
|
name = "shoes",
|
||||||
|
fullname = "Shoes",
|
||||||
|
description = "All equipables shoes",
|
||||||
|
inBattle = false
|
||||||
|
},
|
||||||
|
[6] = {
|
||||||
|
name = "accessories",
|
||||||
|
fullname = "Accessories",
|
||||||
|
description = "All equipables accessories",
|
||||||
|
inBattle = false
|
||||||
|
},
|
||||||
|
[7] = {
|
||||||
|
name = "chao",
|
||||||
|
fullname = "Chao's Items",
|
||||||
|
description = "All chao-related items",
|
||||||
|
inBattle = false
|
||||||
|
},
|
||||||
|
[8] = {
|
||||||
|
name = "quest",
|
||||||
|
fullname = "Quest Items",
|
||||||
|
description = "All quest items",
|
||||||
|
inBattle = false
|
||||||
|
},
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
return {
|
||||||
|
name = "chilidog",
|
||||||
|
fullname = "Chili Dog",
|
||||||
|
description = "Sonic's favorite food.",
|
||||||
|
conditions = {
|
||||||
|
{"status", "ko", false}
|
||||||
|
},
|
||||||
|
effects= {
|
||||||
|
{"heal", "hp", "fixed", 10}
|
||||||
|
},
|
||||||
|
usableInBattle=true,
|
||||||
|
usableOnMap=true,
|
||||||
|
affectEverybody=false,
|
||||||
|
}
|
|
@ -1,21 +1,21 @@
|
||||||
local LootManager = Object:extend()
|
local LootManager = Object:extend()
|
||||||
|
local Pocket = Object:extend()
|
||||||
|
|
||||||
|
local itemutils = require "game.utils.items"
|
||||||
|
|
||||||
function LootManager:new(controller)
|
function LootManager:new(controller)
|
||||||
self.controller = controller
|
self.controller = controller
|
||||||
self.rings = 0
|
self.rings = 0
|
||||||
self.inventory = {}
|
self.inventory = {}
|
||||||
self.materials = {}
|
self.pocketIndex = {}
|
||||||
self.chaosDrives = {}
|
|
||||||
self.animals = {}
|
self:generatePockets()
|
||||||
end
|
end
|
||||||
|
|
||||||
function LootManager:getData()
|
function LootManager:getData()
|
||||||
local data = {}
|
local data = {}
|
||||||
data.rings = self.rings
|
data.rings = self.rings
|
||||||
data.inventory = self.inventory
|
data.inventory = self.inventory
|
||||||
data.materials = self.materials
|
|
||||||
data.chaosDrives = self.chaosDrives
|
|
||||||
data.animals = self.animals
|
|
||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -23,9 +23,85 @@ function LootManager:setData(data)
|
||||||
local data = data
|
local data = data
|
||||||
self.rings = data.rings
|
self.rings = data.rings
|
||||||
self.inventory = data.inventory
|
self.inventory = data.inventory
|
||||||
self.materials = data.materials
|
end
|
||||||
self.chaosDrives = data.chaosDrives
|
|
||||||
self.animals = data.animals
|
function LootManager:generatePockets()
|
||||||
|
local structure = require "datas.gamedata.items"
|
||||||
|
for i,pocketdata in ipairs(structure) do
|
||||||
|
local pocket = Pocket(pocketdata)
|
||||||
|
self.pocketIndex[pocketdata.name] = i
|
||||||
|
table.insert(self.inventory, pocket)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function LootManager:getPocketById(id)
|
||||||
|
return self.inventory[id]
|
||||||
|
end
|
||||||
|
|
||||||
|
function LootManager:getPocketByName(name)
|
||||||
|
return self.inventory[self.pocketIndex[name]]
|
||||||
|
end
|
||||||
|
|
||||||
|
function LootManager:addItem(type, item, number)
|
||||||
|
local pocket = self:getPocketByName(type)
|
||||||
|
if (itemutils.itemExists(type, item)) then
|
||||||
|
pocket:addItem(item, number)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function LootManager:getItemData(type, item)
|
||||||
|
return itemutils.getItemData(type, item)
|
||||||
|
end
|
||||||
|
|
||||||
|
function LootManager:getItemNumber(type, item)
|
||||||
|
local pocket = self:getPocketByName(type)
|
||||||
|
return pocket:getItemNumber(item)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- POCKET OBJECT
|
||||||
|
|
||||||
|
function Pocket:new(pocketdata)
|
||||||
|
self.name = pocketdata.name
|
||||||
|
self.fullname = pocketdata.fullname
|
||||||
|
self.inBattle = pocketdata.inBattle
|
||||||
|
self.description = pocketdata.description
|
||||||
|
self.list = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function Pocket:addItem(item, number)
|
||||||
|
local success = false
|
||||||
|
|
||||||
|
for i,itemData in ipairs(self.list) do
|
||||||
|
if (itemData.name == item) then
|
||||||
|
itemData.number = itemData.number + number
|
||||||
|
success = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if (not success) then
|
||||||
|
itemData = {}
|
||||||
|
itemData.name = item
|
||||||
|
itemData.number = number
|
||||||
|
table.insert(self.list, itemData)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Pocket:getItem(name)
|
||||||
|
for i, itemData in ipairs(self.list) do
|
||||||
|
if (itemData.name == name) then
|
||||||
|
return itemData
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function Pocket:getItemNumber(name)
|
||||||
|
local item = self:getItem(name)
|
||||||
|
if (item == nil) then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return item.number
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return LootManager
|
return LootManager
|
||||||
|
|
45
sonic-radiance.love/game/utils/items.lua
Normal file
45
sonic-radiance.love/game/utils/items.lua
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
local ItemUtils = {}
|
||||||
|
|
||||||
|
local datasutils = require "game.utils.datas"
|
||||||
|
|
||||||
|
local DIR = "items"
|
||||||
|
|
||||||
|
function ItemUtils.getBaseDirectory(lua)
|
||||||
|
return datasutils.concatDataFolder(DIR, lua)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ItemUtils.listCategories()
|
||||||
|
return require(ItemUtils.getBaseDirectory(true))
|
||||||
|
end
|
||||||
|
|
||||||
|
function ItemUtils.getCategoryDirectory(directory, lua)
|
||||||
|
return datasutils.concatFolder(ItemUtils.getBaseDirectory(lua), directory, lua)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ItemUtils.getItemsFromCategory(directory)
|
||||||
|
local folder = ItemUtils.getCategoryDirectory(directory, false)
|
||||||
|
local baseTable = love.filesystem.getDirectoryItems(folder)
|
||||||
|
return datasutils.luaFileListToModuleList(baseTable)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ItemUtils.getItemFile(category, item, lua)
|
||||||
|
local dir = ItemUtils.getCategoryDirectory(category, lua)
|
||||||
|
local path = datasutils.concatFolder(dir, item, lua)
|
||||||
|
if (not lua) then
|
||||||
|
path = path .. ".lua"
|
||||||
|
end
|
||||||
|
return path
|
||||||
|
end
|
||||||
|
|
||||||
|
function ItemUtils.itemExists(category, item)
|
||||||
|
local path = ItemUtils.getItemFile(category, item, false)
|
||||||
|
local fileinfo = love.filesystem.getInfo(path)
|
||||||
|
return (fileinfo ~= nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ItemUtils.getItemData(category, item)
|
||||||
|
local path = ItemUtils.getItemFile(category, item, true)
|
||||||
|
return datasutils.copy(path)
|
||||||
|
end
|
||||||
|
|
||||||
|
return ItemUtils
|
|
@ -9,6 +9,7 @@ local ActionWidget = BattleWidget:extend()
|
||||||
local SubMenuWidget = BattleWidget:extend()
|
local SubMenuWidget = BattleWidget:extend()
|
||||||
local BackMenuWidget = BattleWidget:extend()
|
local BackMenuWidget = BattleWidget:extend()
|
||||||
local SkillWidget = BattleWidget:extend()
|
local SkillWidget = BattleWidget:extend()
|
||||||
|
local ItemWidget = BattleWidget:extend()
|
||||||
|
|
||||||
local MENUPOS_X1, MENUPOS_X2, MENUPOS_Y = 88, 32, 72
|
local MENUPOS_X1, MENUPOS_X2, MENUPOS_Y = 88, 32, 72
|
||||||
local MENU_WIDTH, MENU_ITEM_HEIGHT = 180, 17
|
local MENU_WIDTH, MENU_ITEM_HEIGHT = 180, 17
|
||||||
|
@ -63,30 +64,21 @@ end
|
||||||
function MenuConstructor:buildObjectMenu(character)
|
function MenuConstructor:buildObjectMenu(character)
|
||||||
CharacterMenu(self.scene, "ObjectMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
CharacterMenu(self.scene, "ObjectMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
||||||
|
|
||||||
CharacterMenu(self.scene, "MedMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
for i,pocket in ipairs(game.loot.inventory) do
|
||||||
CharacterMenu(self.scene, "RingMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
if (pocket.inBattle) then
|
||||||
CharacterMenu(self.scene, "WispMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
CharacterMenu(self.scene, pocket.name, MENUPOS_X1 - 16, MENUPOS_Y)
|
||||||
CharacterMenu(self.scene, "OtherMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
SubMenuWidget(character, "ObjectMenu", pocket.fullname, pocket.name)
|
||||||
|
for j,itemData in ipairs(pocket.list) do
|
||||||
|
ItemWidget(character, pocket.name, itemData.name)
|
||||||
SubMenuWidget(character, "ObjectMenu", "heal", "MedMenu")
|
end
|
||||||
SubMenuWidget(character, "ObjectMenu", "rings", "RingMenu")
|
SubMenuWidget(character, pocket.name, "back", "ObjectMenu")
|
||||||
SubMenuWidget(character, "ObjectMenu", "wisps", "WispMenu")
|
self.scene.menusystem.menus[pocket.name]:setCancelWidget()
|
||||||
SubMenuWidget(character, "ObjectMenu", "other", "OtherMenu")
|
end
|
||||||
|
end
|
||||||
|
|
||||||
SubMenuWidget(character, "ObjectMenu", "back", "BaseMenu")
|
SubMenuWidget(character, "ObjectMenu", "back", "BaseMenu")
|
||||||
SubMenuWidget(character, "MedMenu", "back", "ObjectMenu")
|
|
||||||
SubMenuWidget(character, "RingMenu", "back", "ObjectMenu")
|
|
||||||
SubMenuWidget(character, "WispMenu", "back", "ObjectMenu")
|
|
||||||
SubMenuWidget(character, "OtherMenu", "back", "ObjectMenu")
|
|
||||||
|
|
||||||
|
|
||||||
self.scene.menusystem.menus["ObjectMenu"]:setCancelWidget()
|
self.scene.menusystem.menus["ObjectMenu"]:setCancelWidget()
|
||||||
|
|
||||||
self.scene.menusystem.menus["MedMenu"]:setCancelWidget()
|
|
||||||
self.scene.menusystem.menus["RingMenu"]:setCancelWidget()
|
|
||||||
self.scene.menusystem.menus["WispMenu"]:setCancelWidget()
|
|
||||||
self.scene.menusystem.menus["OtherMenu"]:setCancelWidget()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -307,4 +299,24 @@ function SkillWidget:sendCharacterData()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- ItemWidget
|
||||||
|
-- A widget to handle items
|
||||||
|
|
||||||
|
function ItemWidget:new(character, menu_name, item)
|
||||||
|
self.itemname = item
|
||||||
|
local label2 = "00"
|
||||||
|
|
||||||
|
self.number = game.loot:getItemNumber(menu_name, item)
|
||||||
|
self.itemdata = game.loot:getItemData(menu_name, item)
|
||||||
|
|
||||||
|
label2 = self.number
|
||||||
|
|
||||||
|
ItemWidget.super.new(self, character, menu_name, self.itemdata.fullname, "x" .. label2, "skills")
|
||||||
|
end
|
||||||
|
|
||||||
|
function ItemWidget:sendCharacterData()
|
||||||
|
self.character:doNothing()
|
||||||
|
self.assets.sfx["mError"]:play()
|
||||||
|
end
|
||||||
|
|
||||||
return MenuConstructor
|
return MenuConstructor
|
||||||
|
|
|
@ -4,6 +4,7 @@ local menu = require "scenes.debug.menu.menu"
|
||||||
local DebugMenu = Scene:extend()
|
local DebugMenu = Scene:extend()
|
||||||
local panels = require "scenes.debug.menu.infopanel"
|
local panels = require "scenes.debug.menu.infopanel"
|
||||||
local battleutils = require "game.utils.battle"
|
local battleutils = require "game.utils.battle"
|
||||||
|
local itemutils = require "game.utils.items"
|
||||||
|
|
||||||
function DebugMenu:new()
|
function DebugMenu:new()
|
||||||
DebugMenu.super.new(self)
|
DebugMenu.super.new(self)
|
||||||
|
@ -67,6 +68,8 @@ function DebugMenu:buildSaveMenu()
|
||||||
menu.AddRemoveWidget(self, "team", data)
|
menu.AddRemoveWidget(self, "team", data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self:addInventory()
|
||||||
|
|
||||||
self:addSubMenu("load", "save", "Load Saves")
|
self:addSubMenu("load", "save", "Load Saves")
|
||||||
for i=1, game.slotNumber do
|
for i=1, game.slotNumber do
|
||||||
menu.LoadWidget(self, "load", i)
|
menu.LoadWidget(self, "load", i)
|
||||||
|
@ -86,6 +89,18 @@ function DebugMenu:addCharacterMenu(name, data)
|
||||||
menu.SubMenuWidget(self, name, "characters", "Back", panels.Gamedata, nil)
|
menu.SubMenuWidget(self, name, "characters", "Back", panels.Gamedata, nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function DebugMenu:addInventory()
|
||||||
|
self:addSubMenu("inventory", "save", "Inventory")
|
||||||
|
for i,pocket in ipairs(game.loot.inventory) do
|
||||||
|
self:addSubMenu(pocket.name, "inventory", pocket.fullname)
|
||||||
|
for j, item in ipairs(itemutils.getItemsFromCategory(pocket.name)) do
|
||||||
|
menu.ItemWidget(self, pocket.name, itemutils.getItemData(pocket.name, item))
|
||||||
|
end
|
||||||
|
menu.commons.SubMenuWidget(self, pocket.name, "inventory", "Back")
|
||||||
|
end
|
||||||
|
menu.commons.SubMenuWidget(self, "inventory", "save", "Back")
|
||||||
|
end
|
||||||
|
|
||||||
function DebugMenu:buildOtherMenu()
|
function DebugMenu:buildOtherMenu()
|
||||||
self:addSubMenu("other", "BaseMenu", "Other gameplay")
|
self:addSubMenu("other", "BaseMenu", "Other gameplay")
|
||||||
self:addSubMenu("battle", "other", "Sonic Battle Maps")
|
self:addSubMenu("battle", "other", "Sonic Battle Maps")
|
||||||
|
|
|
@ -9,6 +9,7 @@ menu.LevelUpWidget = commons.DebugWidget:extend()
|
||||||
menu.AddRemoveWidget = commons.DebugWidget:extend()
|
menu.AddRemoveWidget = commons.DebugWidget:extend()
|
||||||
menu.ChangeLeaderWidget = commons.DebugWidget:extend()
|
menu.ChangeLeaderWidget = commons.DebugWidget:extend()
|
||||||
menu.SubMenuWidget = commons.SubMenuWidget:extend()
|
menu.SubMenuWidget = commons.SubMenuWidget:extend()
|
||||||
|
menu.ItemWidget = commons.DebugWidget:extend()
|
||||||
|
|
||||||
-- ExitWidget
|
-- ExitWidget
|
||||||
function menu.ExitWidget:new(scene, menuName)
|
function menu.ExitWidget:new(scene, menuName)
|
||||||
|
@ -88,5 +89,17 @@ function menu.ChangeLeaderWidget:action()
|
||||||
game.characters:setActiveCharacter(1)
|
game.characters:setActiveCharacter(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- ItemWidget
|
||||||
|
function menu.ItemWidget:new(scene, menuName, itemdata)
|
||||||
|
menu.ItemWidget.super.new(self, scene, menuName, itemdata.fullname)
|
||||||
|
self.category = menuName
|
||||||
|
self.itemName = itemdata.name
|
||||||
|
end
|
||||||
|
|
||||||
|
function menu.ItemWidget:action()
|
||||||
|
game.loot:addItem(self.category, self.itemName, 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return menu
|
return menu
|
||||||
|
|
Loading…
Reference in a new issue