Skip to content
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

javascript node.js scripts #687

Merged
merged 7 commits into from
Apr 2, 2022
Merged

javascript node.js scripts #687

merged 7 commits into from
Apr 2, 2022

Conversation

mojoaxel
Copy link
Collaborator

@mojoaxel mojoaxel commented Mar 28, 2022

These games are meant as simple CLI scripts (see #117 (comment)).
I therefor think javascript should target mainly node.js instead of the browser (in opposite of whats currents implemented).

  • So, I started porting the existing javascript implementations to be simple node-scripts.
  • I also introduced very basic common function like print, input and tab. (see Intellij complains about dependencies in ConsoleTest.kt. #548 (comment)).
  • I decided to use modern ES-modules instead of the legacy commonCJ node-syntax. That way the scripts can easily load the common function (also in the browser). For this to work the files have a *.mjs extension.
  • To not loose the ability to play the games in the browser I created a simple node-terminal-emulator that lets run our node-scripts directly in the browser. For this to work I overwrote the default process.stdout/stdin of node and hocked them up to some browser mockups. I know this is very hacky but it works just fine (at least for the simple scripts I've tested).

Here is an example of the emulator in action: https://mojoaxel.github.io/basic-computer-games/00_Common/javascript/WebTerminal/terminal.html#74_Rock_Scissors_Paper/javascript/rockscissors.mjs

This way we have the best of both worlds:

  • ✔️ The JavaScript implementations get very slim and easy to ready also for beginners. All the browser-specific stuff is gone!
  • ✔️ The scripts can simply be executed and played in every shell, just like e.g. the python or perl implementations.
  • ✔️ We still have the possibility to run the games in the browser.
  • ✔️ The terminal-emulator even feels more "real" because the input fields are gone.
  • ❌ It is no longer super easy for the user to run the games locally IN THE BROWSER, but I think that is ok ant it is still possible using the emulator.

The following games already have been refactored to be valid node-script:

  • 57_Literature_Quiz
  • 74_Rock_Scissors_Paper
  • 78_Sine_Wave
  • 96_Word
  • all other games still use the existing html-implementation

Please let me know what you think!!

@mojoaxel mojoaxel self-assigned this Mar 28, 2022
@mojoaxel mojoaxel changed the title javascript node.js scripts WORK IN PROGRESS: javascript node.js scripts Mar 28, 2022
@mojoaxel mojoaxel marked this pull request as draft March 28, 2022 21:28
@mojoaxel mojoaxel changed the title WORK IN PROGRESS: javascript node.js scripts javascript node.js scripts Mar 28, 2022
@coding-horror
Copy link
Owner

As long as we can run the games in the browser for the JS versions, it's all good to me!

@mojoaxel mojoaxel marked this pull request as ready for review April 2, 2022 12:41
@mojoaxel
Copy link
Collaborator Author

mojoaxel commented Apr 2, 2022

@nanochess @stevebosman What do you think about this (big) change! I would be happy to hear your input!

@coding-horror coding-horror merged commit 861ff22 into main Apr 2, 2022
@coding-horror coding-horror deleted the 74-html-terminal branch April 2, 2022 19:11
@coding-horror
Copy link
Owner

LGTM! Let's merge it and then discuss!

@mojoaxel
Copy link
Collaborator Author

mojoaxel commented Apr 2, 2022

Thanks for merging! Looks like the new node.js-terminal-emulator works:
https://coding-horror.github.io/basic-computer-games/00_Common/javascript/WebTerminal/terminal.html#74_Rock_Scissors_Paper/javascript/rockscissors.mjs

@coding-horror
Copy link
Owner

It is good! One thing I noticed, the terminal style seems to disppear if you make the browser narrow, e.g.:

image

compare to a little bit wider:

image

rjrw pushed a commit to rjrw/basic-computer-games that referenced this pull request Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants