-
-
Notifications
You must be signed in to change notification settings - Fork 255
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
First pass at merging Node.js support #54
Conversation
(CC @statico) for comments / suggestions. |
Very nice, thanks! I particularly like how the "if exports" node-ism (or, more correctly, commonjs-ism) is now moved into a dedicated One question for if ((typeof process !== "undefined" && process !== null ? process.env : void 0) != null) {
|
Removed unnecessary conditionals from node-shim.js and node-export.js Fixed jsdoc comments in node-shim.js and node-export.js Added "rng" keyword to package.node Removed "doc" directory from npm-published files in package.node Replaced package.json with make generated package.json
You are right! 😃 The I came up with the code for that conditional by going to Try CoffeeScript and putting in the following CoffeeScript code:
It generates this JavaScript:
I wanted to check that I also regenerated Thanks! 😃 |
Cool, will merge + delete package.json afterwards. |
First pass at merging Node.js support
|
Yep, that should do it! Would you like me to publish to npm? Or would you like to do it? |
Done, published :) Please let me know if anything goes wrong or this particular feature needs more attention in the future. Thanks for your assistance! |
Awesome! Thanks for doing this :) |
@blinkdog, I'm eager to try this, but I can't seem to get it to work. Could you provide a working example of a game running under Node.js? If you don't already have something, you could try porting the rot.js tutorial game (full source). |
FWIW, I was specifically using the FOV and Map classes, not the whole framework. If it's useful, here are the snippets that use ROT within Node 0.10: ROT = require 'rot.js'
{vec2} = require 'gl-matrix'
...
@terrain = new DenseMap(@width, @height)
pos = [0, 0]
map = new ROT.Map.Digger(@width, @height)
map.create (x, y, v) =>
vec2.set pos, x, y
@terrain.set pos, switch v
when 0 then TILES.FLOOR
when 1 then TILES.VOID
for corridor in map.getCorridors()
for x in [corridor._startX..corridor._endX]
for y in [corridor._startY..corridor._endY]
vec2.set pos, x, y
@terrain.set pos, TILES.CORRIDOR if @terrain.get(pos) is TILES.FLOOR
...
# computer what areas the player can see
pos = [0, 0]
diff = new SparseMap(@level.width, @level.height)
isWalkable = (x, y) =>
vec2.set pos, x, y
@level.terrain.get(pos) of WALKABLE_TILES
fov = new ROT.FOV.PreciseShadowcasting(isWalkable)
for _, player of @playerActors
[x, y] = player.pos
fov.compute x, y, 10, (x, y, _, visible) =>
# for now, just send terrain data to client
vec2.set pos, x, y
diff.set pos, terrain: @level.terrain.get pos
...
steps = []
path = new ROT.Path.AStar(target[0], target[1], isWalkable)
path.compute @pos[0], @pos[1], (x, y) ->
steps.push [x, y] |
Thank you. What I'm puzzled about, mostly, is proper use of |
Right. There is basically no input handling in rot.js whatsoever, as regular DOM events are somewhat sufficient in this area. |
"term" is another layout engine, similar to "rect" for rot.js in the browser.
And this code would do the same thing, in the browser:
When working with Node.js, there is no DOM or browser, just your good old console with terminal emulation. So, when targeting Node.js you need to explicitly specify the "term" layout:
Now, the tricky thing about terminal emulation is that there are a LOT of terminals to emulate. Each terminal had it's own sub/super set of ANSI Escape Codes. In order to make pretty colors on the display, the code needs to know how to tell the terminal "change to red background" and such. That's where Xterm comes in. You see, like the "rect" default that rot.js provided for the browser, the Node.js port also pulls this trick with
The Node.js port assumes that you are running an xterm-compatible terminal emulation. If you are running Node.js on a Linux or MacOS machine, you're probably OK. If you are running Node.js on a Windows machine, the default console probably isn't going to cut it. You'll need something like MobaXterm or the like. If there was enough demand, and I could find a Windows machine to test it on, I would consider making a
Sure. I'll see what I can come up with in a few hours. |
Okay @Kodiologist check out my repository here: https://github.com/blinkdog/ananas-aus-caracas-node It is the rot.js tutorial game with a shim for keyboard handling ( There are a few very tiny modifications to the game code itself, basically I will do a better port (replace the browser-isms with Node-isms) when I get some free time this weekend. But for now, this should get you going with a working Node.js example. |
Awesome, thanks! I linked to your repository from the tutorial. I notice that the terminal cursor is visible when there's a floor square to the right of Pedro. That's probably easy to fix by hiding or moving the cursor, perhaps with an extra method of |
I made another small round of updates to the shim version:
This is a good idea. I should code this as a permanent fix and offer another pull request to @ondras |
Now the repository contains a real Node version ( Some changes in this version:
Does it seem OK, @Kodiologist ? |
@blinkdog Looks quite good to me. Well-commented, too. You don't need the |
Building
So this is rot.js with support for Node.js. It offers a new build target
node
:This will recreate
package.json
and createlib/rot.js
.Publishing
Once the Node version of rot.js is built, package.json specifies everything that npm needs in order to publish. Publishing to npm is just:
I have added
ondras
as an owner on therot-js
npm module, so you should be able to publish and add/remove owners now. If you want me to publish, just let me know and I'll do so.Usage
After publication, the most simple way to try out rot.js for Node would be:
Notes
package.json
file in order to keep the diff short and clear. I do think it should be deleted, or at least regenerated, as part of your merge back to master.