diff --git a/lua/tamagotchi/pet.lua b/lua/tamagotchi/pet.lua index de0bc31..1a68768 100644 --- a/lua/tamagotchi/pet.lua +++ b/lua/tamagotchi/pet.lua @@ -6,7 +6,7 @@ function Pet:new(o) setmetatable(o, Pet) o.name = o.name or "Anonymous Pet" o.satiety = o.satiety or 80 - o.happiness = o.happiness or 80 + o.mood = o.mood or 80 o.birth_time = vim.loop.now() local config = require("tamagotchi.config").values @@ -33,11 +33,9 @@ function Pet:get_satiety() return self.satiety end function Pet:set_satiety(value) self.satiety = math.max(1, math.min(100, value)) end -function Pet:get_happiness() return self.happiness end +function Pet:get_mood() return self.mood end -function Pet:set_happiness(value) - self.happiness = math.max(1, math.min(100, value)) -end +function Pet:set_mood(value) self.mood = math.max(1, math.min(100, value)) end -- get current pet age in ms function Pet:get_age() return vim.loop.now() - self.birth_time end @@ -46,7 +44,7 @@ function Pet:get_age() return vim.loop.now() - self.birth_time end function Pet:to_table() return { satiety = self.satiety, - happiness = self.happiness, + mood = self.mood, birth_time = self.birth_time, } end @@ -82,7 +80,7 @@ end local function determine_state(pet) if pet.satiety < 70 then return "hungry" - elseif pet.happiness > 70 then + elseif pet.mood > 70 then return "happy" else return "neutral" diff --git a/lua/tamagotchi/window.lua b/lua/tamagotchi/window.lua index 9529307..cd81762 100644 --- a/lua/tamagotchi/window.lua +++ b/lua/tamagotchi/window.lua @@ -17,7 +17,7 @@ local function build_ui_lines(pet) local satiety_bar = ascii_bar(pet:get_satiety(), 100, 10) - local happiness_bar = ascii_bar(pet:get_happiness(), 100, 10) + local mood_bar = ascii_bar(pet:get_mood(), 100, 10) -- You can add more or fewer lines as you like: -- We'll pad lines so sprite stays on left, text on right. @@ -33,8 +33,8 @@ local function build_ui_lines(pet) -- Second line: label + satiety bar on the right lines[2] = string.format("%-20s Satiety: %s", "", satiety_bar) - -- Third line: label + happiness bar on the right - lines[3] = string.format("%-20s Happiness: %s", "", happiness_bar) + -- Third line: label + mood bar on the right + lines[3] = string.format("%-20s Mood: %s", "", mood_bar) return lines end diff --git a/test/pet_persistence_spec.lua b/test/pet_persistence_spec.lua index fc29ed8..00494e2 100644 --- a/test/pet_persistence_spec.lua +++ b/test/pet_persistence_spec.lua @@ -7,7 +7,7 @@ describe("pet persistence", function() local pet before_each(function() - pet = Pet:new({ satiety = 80, happiness = 80 }) + pet = Pet:new({ satiety = 80, mood = 80 }) -- ensure clean test file each time if vim.fn.filereadable(test_filepath) == 1 then vim.fn.delete(test_filepath) @@ -29,7 +29,7 @@ describe("pet persistence", function() local content = table.concat(lines, "") local data = vim.fn.json_decode(content) assert.are.equal(80, data.satiety) - assert.are.equal(80, data.happiness) + assert.are.equal(80, data.mood) assert.is_true(type(data.birth_time) == "number") end) @@ -38,7 +38,7 @@ describe("pet persistence", function() local loaded_pet = Pet.load(test_filepath) assert.is_not_nil(loaded_pet) assert.are.equal(80, loaded_pet:get_satiety()) - assert.are.equal(80, loaded_pet:get_happiness()) + assert.are.equal(80, loaded_pet:get_mood()) assert.are.equal(pet.birth_time, loaded_pet.birth_time) end) diff --git a/test/pet_spec.lua b/test/pet_spec.lua index 27bca35..5d445dd 100644 --- a/test/pet_spec.lua +++ b/test/pet_spec.lua @@ -8,7 +8,7 @@ describe("pet object", function() it("should initialize with default values", function() assert.are.equal(80, pet:get_satiety()) - assert.are.equal(80, pet:get_happiness()) + assert.are.equal(80, pet:get_mood()) local age = pet:get_age() assert.is_true(age >= 0 and age < 100) -- should take less than 100ms end) @@ -24,15 +24,15 @@ describe("pet object", function() assert.are.equal(1, pet:get_satiety()) end) - it("should allow updating happiness within bounds", function() - pet:set_happiness(90) - assert.are.equal(90, pet:get_happiness()) + it("should allow updating mood within bounds", function() + pet:set_mood(90) + assert.are.equal(90, pet:get_mood()) - pet:set_happiness(200) -- above max - assert.are.equal(100, pet:get_happiness()) + pet:set_mood(200) -- above max + assert.are.equal(100, pet:get_mood()) - pet:set_happiness(0) -- below min - assert.are.equal(1, pet:get_happiness()) + pet:set_mood(0) -- below min + assert.are.equal(1, pet:get_mood()) end) it("should calculate increasing age over time", function() diff --git a/test/pet_sprite_spec.lua b/test/pet_sprite_spec.lua index 89c5ab2..a4fab62 100644 --- a/test/pet_sprite_spec.lua +++ b/test/pet_sprite_spec.lua @@ -29,9 +29,9 @@ describe("pet sprite selection", function() assert.is_not_nil(test_pet_def) end) - it("should return happy sprite if happiness > 70", function() + it("should return happy sprite if mood > 70", function() local pet = Pet:new({ - happiness = 80, + mood = 80, satiety = 80, sprites = test_pet_def.sprites, }) @@ -39,22 +39,19 @@ describe("pet sprite selection", function() assert.is_true(sprite == ":)" or sprite == ":-D") end) - it( - "should return neutral sprite if satiety > 70 and happiness <= 70", - function() - local pet = Pet:new({ - happiness = 50, - satiety = 80, - sprites = test_pet_def.sprites, - }) - local sprite = pet:get_sprite() - assert.is_true(sprite == ":|" or sprite == "-_-") - end - ) + it("should return neutral sprite if satiety > 70 and mood <= 70", function() + local pet = Pet:new({ + mood = 50, + satiety = 80, + sprites = test_pet_def.sprites, + }) + local sprite = pet:get_sprite() + assert.is_true(sprite == ":|" or sprite == "-_-") + end) it("should return hungry sprite if satiety is low", function() local pet = Pet:new({ - happiness = 80, + mood = 80, satiety = 50, sprites = test_pet_def.sprites, }) @@ -90,9 +87,9 @@ describe("pet sprite cycling and state reset", function() assert.is_not_nil(test_pet_def) end) - it("should cycle through happy sprites when happiness > 70", function() + it("should cycle through happy sprites when mood > 70", function() local pet = Pet:new({ - happiness = 80, + mood = 80, satiety = 80, sprites = test_pet_def.sprites, }) @@ -110,7 +107,7 @@ describe("pet sprite cycling and state reset", function() it("should reset sprite index on state change", function() local pet = Pet:new({ - happiness = 80, + mood = 80, satiety = 80, sprites = test_pet_def.sprites, }) @@ -119,8 +116,8 @@ describe("pet sprite cycling and state reset", function() -- cycle once to be in happy state pet:get_sprite() - -- change state: lower happiness to switch sprite set - pet.happiness = 50 + -- change state: lower mood to switch sprite set + pet.mood = 50 local neutral_sprite = pet:get_sprite() -- after state change, sprite index for 'neutral' should reset to first sprite diff --git a/test/window_toggle_spec.lua b/test/window_toggle_spec.lua index 33c6dae..902ec1e 100644 --- a/test/window_toggle_spec.lua +++ b/test/window_toggle_spec.lua @@ -7,7 +7,7 @@ local mock_pet = { get_sprite = function() return "mock_sprite" end, get_age = function() return 0 end, get_satiety = function() return 50 end, - get_happiness = function() return 50 end, + get_mood = function() return 50 end, } describe("window toggle functionality", function()