-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
262 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-- Copyright (c) 2018 Redfern, Trevor <trevorredfern@gmail.com> | ||
-- | ||
-- This software is released under the MIT License. | ||
-- https://opensource.org/licenses/MIT | ||
|
||
local systems = require "systems" | ||
local wood_pile = require "entities.wood_pile" | ||
local choptree = { | ||
name = "chop_tree" | ||
} | ||
|
||
function choptree:new(owner, tree) | ||
local ct = { | ||
owner = owner, | ||
target = tree | ||
} | ||
setmetatable(ct, self) | ||
self.__index = self | ||
return ct | ||
end | ||
|
||
function choptree:execute() | ||
systems.entity_factory:create(wood_pile:new(self.target.position.x, self.target.position.y)) | ||
systems.entity_factory:remove(self.target) | ||
self.done = true | ||
end | ||
|
||
return choptree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-- Copyright (c) 2018 Redfern, Trevor <trevorredfern@gmail.com> | ||
-- | ||
-- This software is released under the MIT License. | ||
-- https://opensource.org/licenses/MIT | ||
|
||
describe("actions - chop_tree", function() | ||
require "test_helpers.mock_love" | ||
local systems = require "systems" | ||
local actions = require "actions" | ||
local tree = require "entities.tree" | ||
local character = require "entities.character" | ||
local tiny = require "ext.tiny-ecs" | ||
tiny.world(systems.entity_factory) | ||
|
||
it("chopping a tree turns it into a pile of wood", function() | ||
systems.entity_factory.create = spy.new(function() end) | ||
systems.entity_factory.remove = spy.new(function() end) | ||
local t = tree:new(5, 5) | ||
local c = character:new(5, 5) | ||
local chop_tree = actions.chop_tree:new(c, t) | ||
|
||
chop_tree:execute(0.2) | ||
--somehow remove the old entity and replace with a new one representing wood | ||
assert.spy(systems.entity_factory.create).was.called() | ||
assert.spy(systems.entity_factory.remove).was.called_with(systems.entity_factory, t) | ||
assert.is_true(chop_tree.done) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- Copyright (c) 2018 Redfern, Trevor <trevorredfern@gmail.com> | ||
-- | ||
-- This software is released under the MIT License. | ||
-- https://opensource.org/licenses/MIT | ||
|
||
local colors = require "colors" | ||
local components = require "components" | ||
local wood_pile = { | ||
symbol = "ʭ", | ||
color = colors.golden_brown | ||
} | ||
|
||
function wood_pile:new(x, y) | ||
local wp = { | ||
position = components.position:new(x, y), | ||
wood = 100 | ||
} | ||
setmetatable(wp, self) | ||
self.__index = self | ||
return wp | ||
end | ||
|
||
return wood_pile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-- Copyright (c) 2018 Redfern, Trevor <trevorredfern@gmail.com> | ||
-- | ||
-- This software is released under the MIT License. | ||
-- https://opensource.org/licenses/MIT | ||
|
||
describe("Entity - wood_pile", function() | ||
require "test_helpers.mock_love" | ||
local wood_pile = require "entities.wood_pile" | ||
|
||
it("should be drawable", function() | ||
local wp = wood_pile:new(4, 8) | ||
assert.not_equal(nil, wp.position) | ||
assert.not_equal(nil, wp.color) | ||
assert.not_equal(nil, wp.symbol) | ||
end) | ||
|
||
it("contains a count of the wood resources in the pile", function() | ||
local wp = wood_pile:new(4, 5) | ||
assert.equals(100, wp.wood) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.