Skip to content

Commit

Permalink
happiness -> mood
Browse files Browse the repository at this point in the history
  • Loading branch information
raquentin committed Jan 18, 2025
1 parent 13ffcc9 commit 381327a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 42 deletions.
12 changes: 5 additions & 7 deletions lua/tamagotchi/pet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions lua/tamagotchi/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/pet_persistence_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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)

Expand Down
16 changes: 8 additions & 8 deletions test/pet_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down
37 changes: 17 additions & 20 deletions test/pet_sprite_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,29 @@ 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,
})
local sprite = pet:get_sprite()
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,
})
Expand Down Expand Up @@ -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,
})
Expand All @@ -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,
})
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/window_toggle_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 381327a

Please sign in to comment.