Please give some information on your develpment process
While not an issue with the game, it would be cool to have some insight on how you actually develop the game, like
- what tools do you use
- how you do debug
- how you do test
- what components of the game do what
etc.
Also, some docstrings in the source would also help.
This would make it easier for people who want to join development of this game.
Maybe create a wiki page or something like that, where other people could also share their experience (I could write an essay of the PITA it was to get this game running on windows 8 with VS2013).
You're right about this. It's not a solution, but here are a few of my notes to get you started. @mtgred can probably throw some more details notes here, as I still feel rather unsure with my development process.
-
On Windows 8.1, I use IntelliJ IDEA with a plugin called Cursive for development. I recommend it.
-
Debugging is difficult for me, really only through console or chat log printouts.
(system-msg)is one function for printing to the game's chat log; you pass itstateand a side (:runner,:corp, orsideif that binding is available depending on where you area), then a string message, and it will print to the chatlog. The downside here is that the action must complete and send the new game state to the client for you to see your printouts, so you can't use it (for example) to find out where you are throwing in the middle of a large function.Clojure's
printhas weird behaviors from what I've experienced; it often won't show to the console UNTIL an exception is thrown. UsingSystem.out.printlnfrom Java is probably the most flexible; use it as(.println System/out (str "append strings and variable values here")). -
Testing is difficult. I don't have a good answer here. For individual cards I test as many interactions as I can think of, using two browsers on my test machine. For large system changes I do more thorough testing, sometimes putting my dev server behind a reverse proxy to let other trusted users test the system on my codebase.
-
Obviously this needs a much more thorough answer, but generally... anything in /src/clj/game is game server code for implementing the game's logic. There is also some logic for communication with the web server. Anything in /src/cljs/netrunner is ClojureScript which cross-compiles to JavaScript and involves the web server. Most of the code there is for displaying the game (or deckbuilder, chat, and other parts of the UI). There is also some code for managing the communication with the game server.
Thanks. I also ask because I have only limited experience with clojure.
I wrote a markdown parser some years ago (using Netbeans), but development was easy since I wrote unit tests and did the development mostly in the REPL.
Now I just set breakpoints and use the Evaluate Expression feature of Cursive, but it's a bit cumbersome. When you're a VS user, you're totally spoilet; like attach to running processes, break on execptions, change code while running, debug backward etc. Don't know if such features exists in Intellij/Cursive.
I also startet to code a Netrunner implementation in C# some time ago, but didn't work on it lately.
- The preferred way to develop is to use a Clojure REPL and launch the game server with (future-call dev) in the REPL. When you modify a function or a card, simply reload the function or the cards.clj file to the REPL and it should be reflected in the game engine without having to recreate a new game. For cards already installed you have to drag it back to hand and install it again to reflect the new code. No need to refresh the browser, you can keep the game state.
- My dev setup is Emacs on Mac OS but Cursive is a good option too. If you want to use Emacs you have to install
clojure-modeandcider. Cider allows you to connect Emacs to a REPL with C-c M-j. To reload a function, it's C-c C-c with the cursor inside the function definition. To reload a file (eg. card.clj) it's C-c C-k. - To inspect the content of clojure data structure,
prnis handy. You can addprnin your functions or inside(req )macro in card definitions you want to inspect. - When there is an exception, the game server might hang. It sucks and you have to kill the REPL, relaunch a game server and recreate and setup a game. If there is another solution, I'm interested to learn!
- To modify the client side, Figwheel is super awesome. Run
lein figwheelandstylus -w src/css -o resources/public/css/. When you save a cljs or styl file, the Clojurescript or Stylus are automatically compiled and sent to the connected browsers. No need to refresh anything, you keep the game state. When you have an error in a cljs file, the UI might disappear. Don't panic! As soon as the error is corrected the UI will reappear. No need to reload anything.
OK, I wish I'd asked this when I got started. Launching the server in REPL is amazing. :+1:
Awesome! Thank you! :+1:
Maybe consider creating a wiki page, as this are really helpful tips and should not be getting burried here.
Excellent information that will help me a ton. I got IntelliJ and Cursive installed on my MacBook Air last night, so hopefully in the coming days I can play around with this and get the hang of it. I installed Emacs too but for some reason got stuck trying to install the cider package.
I took the liberty to create a WikiPage myself.
I will try to populate it with the data in this issue.
OK, last night I got as far as opening my netrunner/ directory in IntelliJ and actually getting the REPL running after a couple attempts. At first the middle option "Run nREPL with Leiningen" was greyed out and I couldn't choose it--the missing piece was the need to right-click project.clj and choose "Add as Leiningen project".
I still need to configure Apache so that my netrunner/ directory is visible when hitting localhost in my browser...I think that should be pretty straightforward with some Googling. After that, if I'm reading between the lines correctly, I can just make edits directly to cards.clj and reload it in the REPL without recompiling anything? And I just test cards and behaviors in my browser and keep an eye on the REPL window in IntelliJ for errors?
I was able to run the Server in a REPL, but reloadi g files didnt work. Well, I could reload them but it wasnt reflected in the game (e.g. I changed Sure Gamble to give 100c, but that didnt work until restarting the Server)
Maybe I'm missing something?
@JoelCFC25 why do you need to run Apache?
Don't I? I assumed I would need a web server running in order to hit the game server with my browser to fire up games and test card implementations. It's very possible that I'm misunderstanding something about what the REPL can do--I'm very inexperienced in this arena.
If I try implementing a card or changing an existing one, how do I then test it?
You have to start the game server, then start the Node server with coffee server.coffee. It will open a port in your machine which you then can connect to (See its console output to see which port it opened)
OK, thanks. That was the part I had missed. I got things going briefly before I had to stop and get some sleep last night, but I did actually make some code changes and saw them represented in test games, so that's major progress.
coffee server.coffee
In IntelliJ: start the REPL, then (future-call dev)
I had (wrongly?) used the java -jar target/netrunner-0.1.0-SNAPSHOT-standalone.jar from a terminal.
java -jar... is basically the equivalent of starting a REPL with future-call dev: it starts the game logic server. coffee server.coffee is the web server. Together, they are unstoppable!
simply reload the function or the cards.clj file to the REPL and it should be reflected in the game engine without having to recreate a new game
@mtgred Any idea why it does not seem to work inside Intellij? I can reload the files in the REPL, and I see my changes, but they are not reflected in the game :-( Maybe I'm doing something wrong?
@JoelCFC25 Did you have any luck with reloading files/functions inside the REPL?
Let's take a simple example:
- Change Hedge Funds to give 10 credits instead of 9.
- Reload cards.clj into the REPL. (Tools→REPL. “Load file in REPL”)
- Play the card, you should gain 10 credits.
For installed cards you have to drag them back to hand and install them again to see the change.
Does not work for me. I tried running the REPL from the command line (lein repl).
I changed Hedge Fund:
"Hedge Fund"
{:effect (effect (gain :credit 99)) :test 123}
reloaded the file (use 'game.core :reload), and checked it:
game.main=> (get-in cards '("Hedge Fund" :test))
123
So the file was reloaded, but when I play Hedge Fund in the game, it will still only give 9 credits, not 99.
Anyone any idea how to troubleshoot this issue?
I reload with (load-file "src/clj/game/cards.clj"), not sure if that is different.
I did
lein clean
lein uberjar
lein repl
now reloading works for me with
(load-file "src/clj/game/cards.clj")
Thanks!
Hi all!
I'm just starting with this project, but I do have some experience with Clojure. I think I can clarify a few things in this discussion:
- Clojure's
clojure.lang/printfunction is equivalent toSystem.out.printin Java. Both are buffered, i.e. the printed text does not actually appear on the console until there's either "enough" of it to fill the buffer (which is big) or there is a newline. There is aclojure.lang/printlnfunction which is an equivalent toSystem.out.printlnin Java. However, for debugging,prnis usually better (printlntries to print a user-friendly representation, whereasprnstrives for a machine-readable one). (use 'game.core :reload)seems to be a typo: it reloads thegame.corenamespace, whereas you wanted to reload thegame/cards.cljfile (which is not directly associated with a namespace).java -jar ...standalone.jardoes basically start the server, but does not start a REPL, and does not provide any opportunity for code reloading (in particular, it never looks at the source files). For more details on that point, you can look atgame/main.clj:java -jaressentially runs thegame.main/mainfunction directly (i.e. not from a REPL), which is very similar but not equivalent to thegame.main/devfunction you call with(future-call dev)from the REPL.
Thanks for the clarifications! Very happy to see more people becoming interested in contributing :).