-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Feature/wombat animation #361
base: develop
Are you sure you want to change the base?
Conversation
This will aid in adding a separate draw function and eventually merging the two together`
;; Iterate through all of the arena rows | ||
(doseq [[y row] (map-indexed vector arena)] | ||
(doseq [[x cell] (map-indexed vector row)] | ||
(let |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put x-coord
on this line.
"Given the start and the end dimension object, calculate which direction | ||
has movement" | ||
[start end] | ||
(if (pos? (Math/abs (- (:x start) (:x end)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is a bit confusing and would probably be easier to follow like:
(defn- get-direction-key
[{x0 :x} {x1 :x}] ;; you could also use [start end] here
(if (= x0 x1) ;; and then pull out the values here.
:y
:x))
width (/ (canvas/width canvas-element) (count (get arena 0)))] | ||
|
||
;; Iterate through all of the arena rows | ||
(doseq [[y row] (map-indexed vector arena)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I think this could still be done cleaner by combining draw-arena-canvas
into draw-arena-canvas-animated
.
I think the best way would be to sort all of the elements by the order that they should be drawn (such that the animated elements are always drawn after the non-animated). You would need to merge in their x/y coordinates. Then you can simply draw the element at the correct location. Does that make sense?
What's the reasoning for still having the two for loops? |
@dehli the draw arena method is still being used - I haven't depreciated it yet so the dual loops are still used for rendering the game-play, not the simulator. |
(* height y))} | ||
{:x (if (= direction-key :x) | ||
(* width | ||
(+ -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dec
should work here.
@dehli What's the status with this PR? If you get a chance to review this in the next few weeks, I'd be more than happy to update the code and make sure everything is good to go! |
Hey @elibosley! It's on my backlog. I will get around to this either this weekend, or sometime next week! Hope you had a good week! 😄 |
Awesome! Thanks, I had a great week! 😆 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @elibosley! Here's some suggestions. I think it's a good start! Feel free to address these whenever you have time and I'll do another review afterwards. Good luck with classes!
;; Draw background first | ||
(draw-background canvas-element x y width height) | ||
(when (= background true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just use (when background
|
||
(let [{contents :contents | ||
meta :meta} cell | ||
cell-type (:type contents)] | ||
|
||
(when (nil? cell-type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove these prn
calls.
;; step size is neg if moving up or left, so wrap to the largest dimension, | ||
;; this logic is reversed because step-size is calculated as the opposite | ||
;; sign when wrapping occurs | ||
(if (pos? step-size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a lot easier to follow if you had the (pos? step-size
when you actually calculate the values for :x
and :y
. Additionally, it would allow you to remove code that you have replicated.
"Add local :x and :y coordinates to arena matrix" | ||
[arena] | ||
(map-indexed | ||
(fn [y row] (map-indexed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation is off in this function.
(get-in item [:contents :uuid])) | ||
|
||
(defn- dimensions | ||
[item] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function isn't needed since item
already has the proper attributes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does - but I need the previous dimensions to be stored somewhere - I think I figured it was easier to just pull both at once. Would you suggest putting all of that information on the :cell attribute for the vector?
Answered down below
;; Get the coordinates of the animated items on the grid | ||
prev-coords (filter-arena prev-frame-locs [:zakano :wombat]) | ||
next-coords (filter-arena next-frame-locs [:zakano :wombat]) | ||
canvas-element (.getElementById js/document canvas-id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to use ref
instead of (.getElementById
;; Need to get two sets of coordinates - | ||
;; one to run wombat off the screen, one to wrap the new wombat on | ||
|
||
(defn- draw-arena-canvas-animated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this method draws all cells (not just animated). If so, it would make sense to rename this method.
:step-size step-size})] | ||
;; Draw a blank tile before the animated item to fix | ||
;; weird drawing issues | ||
(draw-background |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need to draw a blank tile if the elements are ordered according to when they should be drawn.
;; this when subtracts one from the end because the animation runs once | ||
;; before it gets a callback | ||
(when (<= (:progress animation-progress) (dec (:end animation-progress))) | ||
(.requestAnimationFrame js/window |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be cleaner to just do a forceUpdate
every animation frame so that the arena completely rerenders.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how to do this - would you replace the .requestAnimationFrame ? and what would I call force-update on to make sure I could increment the animation progress?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I'm thinking (might not actually work) is doing the following:
(.requestAnimationFrame js/window
(.forceUpdate this))
Then you're triggering a rerender every animation frame so you don't need to have any logic inside of the callback. Does that make sense?
total-step-size (get-step-size start end direction-key) | ||
step-size (/ total-step-size frame-time)] | ||
(if (> (Math/abs total-step-size) 1) ;; wrap-around | ||
(let [cell-coords (get-wrapped-coord |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have all these coords? I'd imagine just two would be enough for wrapping (current coord, and wrapped coord), otherwise we'd just need one coordinate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So one set of coords draws the wombat out of the frame and the other one draws it in - that was the best way that I could see to have the transition be smooth - lmk what you think!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I guess my question is what is cell-coords
, vs. wrapped-coords
, vs. same-side-wrap
. Makes sense though!
Ugh so I'm finally getting around to this and having crazy setup issues with Ubuntu - hopefully I can figure out what's wrong with my configuration but I just figured I'd update you about it! |
Sounds good! @elibosley Let me know if you need anything! |
@dehli Should I fork this repo to push my commit back up? I've updated the code a bit but I'm not sure how I should get it back into a PR |
Hey @elibosley! You can just push directly to this branch and it will update the PR appropriately 😄 |
PR for #274 .
PR Status
IN DEVELOPMENT
Ready for PR?
lein run-lint
to check for linting errors.Changes Proposed:
Breaking changes?
Screenshot of feature:
@emilyseibert @oconn @dehli