Skip to content

Commit

Permalink
removed restricting types from act! (#375)
Browse files Browse the repository at this point in the history
* removed restricting types from act!
* v0.5.3
  • Loading branch information
Wikunia committed Jul 26, 2021
1 parent a420b9d commit 13be465
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Javis.jl - Changelog

## Unreleased
## v0.5.3 (26th of July 2021)
- Allow all kinds of iterable ways in the `act!` function such that `act!(::Matrix, ::Action)` also works
- Updated `anim_translate`
- Docstring: `anim_translate` translates by a vector instead of to a point
- from->to assumes that we are at `from` already instead of adding it to it
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Javis"
uuid = "78b212ba-a7f9-42d4-b726-60726080707e"
authors = ["Ole Kröger <o.kroeger@opensourc.es>", "Jacob Zelko <jacobszelko@gmail.com>"]
version = "0.5.2"
version = "0.5.3"

[deps]
Animations = "27a7e980-b3e6-11e9-2bcd-0b925532e340"
Expand Down
16 changes: 8 additions & 8 deletions src/structs/Object.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,29 +116,29 @@ Here the scaling is applied to the rectangle for the first fifty frames.
- `object::AbstractObject` - the object the action is applied to
- `action::AbstractAction` - the action applied to the object
2. A single object and a list of actions:
2. A single object and several actions:
`act!(object::AbstractObject, action::Vector{<:AbstractAction})`
`act!(object::AbstractObject, action)`
- `object::AbstractObject` - the object actions are applied to
- `action::Vector{<:AbstractAction}` - the actions applied to an object
- `actions` - the actions applied to an object **Attention:** Will fail if `actions` is not iterable
3. A list of objects and a list of actions:
3. Several objects and several actions:
`act!(object::Vector{<:AbstractObject}, action::Vector{<:AbstractAction})`
- `object::Vector{<:AbstractObject}` - the objects actions are applied to
- `action::Vector{<:AbstractAction}` - the actions applied to the objects
- `objects` - the objects actions are applied to **Attention:** Will fail if `objects` is not iterable
- `actions` - the actions applied to the objects **Attention:** Will fail if `actions` is not iterable
"""
function act!(object::AbstractObject, action::AbstractAction)
push!(object.actions, copy(action))
end

function act!(object::AbstractObject, actions::Vector{<:AbstractAction})
function act!(object::AbstractObject, actions)
for action in actions
act!(object, action)
end
end

function act!(objects::Vector{<:AbstractObject}, action)
function act!(objects, action)
for object in objects
act!(object, action)
end
Expand Down
9 changes: 5 additions & 4 deletions test/unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
@testset "translation" begin
video = Video(500, 500)
Background(1:100, (args...) -> 1)
object = Object(1:100, (args...) -> Point(1, 1))
act!(object, Action(1:100, anim_translate(Point(1, 1), Point(100, 100))))
# test objects matrix
objects = [Object(1:100, (args...) -> Point(1, 1)) for i in 1:9, j in 1:9]
act!(objects, Action(1:100, anim_translate(Point(1, 1), Point(100, 100))))
Javis.preprocess_frames!(video.objects)

for f in [1, 50, 100]
Javis.get_javis_frame(video, [object], f)
@test get_position(object) == Point(f, f)
Javis.get_javis_frame(video, [objects...], f)
@test get_position(objects[1, 1]) == Point(f, f)
end

# with easing function
Expand Down

0 comments on commit 13be465

Please sign in to comment.