forked from mozilla/BrowserQuest
-
Notifications
You must be signed in to change notification settings - Fork 217
[WIP] Conversion to Coffeescript #124
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
Open
Aaron1011
wants to merge
15
commits into
master
Choose a base branch
from
coffeescript
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
618b869
Coverted a few files to CoffeeScript
Aaron1011 ea4952e
Fixed typo in area.coffee
Aaron1011 d63e050
Fixed up item.coffee
Aaron1011 fe21ffa
Added animation.coffee
Aaron1011 f1b3598
Changed use of this to @
Aaron1011 74ffd54
Added tile.coffee
Aaron1011 d941804
Added Cakefile
Aaron1011 c489369
Merge branch 'master' into coffeescript
Aaron1011 cf63c43
Added bubble.coffee
Aaron1011 0cac48b
Fixed indentation in item.coffee
Aaron1011 e378249
Fixed function definition in item.coffee
Aaron1011 d1ac3a4
Add coffee-script to the npm package dependencies
b1b6333
Converted using js2coffee
14add0d
Removed the .js files converted using js2coffee
d9b658e
Temporarily disable testing on CoffeeScript branch
Aaron1011 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,15 @@ | ||
| {exec} = require 'child_process' | ||
| COFFEE = 'coffee --compile' | ||
| COFFE_MAP = '#{COFFEE} --map' | ||
|
|
||
| task 'build', 'Build client and server code', -> | ||
| invoke 'build:client' | ||
| invoke 'build:server' | ||
|
|
||
| task 'build:client', 'Build client code only', -> | ||
| exec "#{COFFEE} client/js/", (err, stdout, stderr) -> | ||
| throw err if err | ||
|
|
||
| task 'build:server', 'Build server code only', -> | ||
| exec "#{COFFEE} server/js/", (err, stdout, stderr) -> | ||
| throw err if err |
This file contains hidden or 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,44 @@ | ||
| define -> | ||
| class Animation | ||
| constructor: (@name, @length, @row, @width, @height) -> | ||
| @reset() | ||
|
|
||
| tick: -> | ||
| i = @currentFrame.index | ||
|
|
||
| if i < @length - 1 then i += 1 else i = 0 | ||
|
|
||
| if @count > 0 and i is 0 | ||
| @count -= 1 | ||
| if @count is 0 | ||
| @currentFrame.index = 0 | ||
| @endcount_callback() | ||
| return | ||
|
|
||
| @currentFrame.x = @width * i | ||
| @currentFrame.y = @height * @row | ||
| @currentFrame.index = i | ||
|
|
||
| setSpeed: (@speed) -> | ||
|
|
||
| setCount: (@count, @endcount_callback) -> | ||
|
|
||
| isTimeToAnimate: (time) -> | ||
| (time - @lastTime) > @speed | ||
|
|
||
| update: (time) -> | ||
| if @lastTime is 0 and @name[..3] is "atk" | ||
| @lastTime = time | ||
|
|
||
| if @isTimeToAnimate time | ||
| @lastTime = time | ||
| @tick() | ||
| true | ||
| else | ||
| false | ||
|
|
||
| reset: -> | ||
| @lastTime = 0 | ||
| @currentFrame = { index: 0, x: 0, y: @row * @height } | ||
|
|
||
| Animation |
This file contains hidden or 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,14 @@ | ||
| define -> | ||
| class Area | ||
| constructor: (@x, @y, @width, @height) -> | ||
|
|
||
| contains: (entity) -> | ||
| if entity? | ||
| entity.gridX >= @x and | ||
| entity.gridY >= @x and | ||
| entity.gridX < @x + @width and | ||
| entity.gridY < @y + @height | ||
| else | ||
| false | ||
|
|
||
| Area |
This file contains hidden or 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,55 @@ | ||
| define ['jquery', 'timer'] ($, timer) -> | ||
|
|
||
| class Bubble | ||
| constructor: (@id, @element, time) -> | ||
| @timer = new Timer(5000, time) | ||
|
|
||
| isOver: (time) -> | ||
| if @timer.isOver time | ||
| true | ||
| false | ||
|
|
||
| destroy: -> | ||
| $(@element).remove() | ||
|
|
||
| reset: (time) -> | ||
| @timer.lastTime = time | ||
|
|
||
| class BubbleManager | ||
| constructor: (@container) -> | ||
| @bubbles = {} | ||
|
|
||
| getBubbleById: (id) -> | ||
| if id in @bubbles | ||
| @bubbles[id] | ||
| null | ||
|
|
||
| create: (id, message, time) -> | ||
| if @bubbles[id] | ||
| @bubbles[id].reset(time) | ||
| $("#"+id+" p").html(message) | ||
| else | ||
| el = $("<div id=\""+id+"\" class=\"bubble\"><p>"+message+"</p><div class=\"thingy\"></div></div>") #attr('id', id) | ||
| $(el).appendTo @container | ||
| @bubbles[id] = new Bubble(id, el, time) | ||
|
|
||
| update: (time) -> | ||
| for bubble in @bubbles[0..@bubbles.length] # Don't mutate the list being iterated over | ||
| if bubble.isOver(time) | ||
| bubble.destroy() | ||
| delete @bubbles[bubble.id] | ||
|
|
||
| clean: -> | ||
| bubble.destroy(); delete @bubbles[bubble.id] for bubble in @bubbles | ||
| @bubbles = {} | ||
|
|
||
| destroyBubble: (id) -> | ||
| bubble = @getBubbleById(id) | ||
| if bubble | ||
| bubble.destroy() | ||
| delete @bubbles[id] | ||
|
|
||
| forEachBubble: (callback) -> | ||
| calback(bubble) for bubble in @bubbles | ||
|
|
||
| BubbleManager |
This file contains hidden or 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 @@ | ||
| define ['entity'], -> (Entity) | ||
| class Item extends Entity | ||
| constructor: (id, kind, @type) -> | ||
| super id, kind | ||
|
|
||
| @itemKind = Types.getKindAsString kind | ||
| @wasDropped = false | ||
|
|
||
| hasShadow: -> true | ||
|
|
||
| onLoot: (player) -> | ||
| if @type == "weapon" | ||
| player.switchWeapon @itemKind | ||
| else if @type == "armor" | ||
| player.armorloot_callback @itemKind | ||
|
|
||
| getSpriteName: -> | ||
| "item-" + @itemKind | ||
|
|
||
| getLootMessage: -> | ||
| @lootMessage | ||
|
|
||
| Item | ||
This file contains hidden or 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 @@ | ||
| define -> | ||
| class Tile | ||
|
|
||
| class AnimatedTile extends Tile | ||
| constructor: (@id, @length, @speed, @index) -> | ||
| @startId = id | ||
| @lastTime = 0 | ||
|
|
||
| tick: -> | ||
| if (@id - @startId) < @length - 1 | ||
| @id += 1 | ||
| else | ||
| @id = @startId | ||
|
|
||
| animate: (time) -> | ||
| if (time - @lastTime) > @speed | ||
| @tick() | ||
| @lastTime = time | ||
| true | ||
| else | ||
| false | ||
|
|
||
| AnimatedTile |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Looking through this now (relearning CoffeeScript 😄), why no "type" variable?
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.
In CoffeeScript, you can prefix a parameter with @ (in this case type), to have it set as an instance variable. This way, you can avoid an extra line of code (
this.type = 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.
Thanks. 😄 I think my brain is in "slow absorbing mode".
This might take a while. 😦