Friday, 14 December 2018

Changing script files used on the front end of a node backed website

[edit] sorry about the effed-up code blocks. new.reddit is fucky with it.​I'm making a solitaire game using node/express backend and phaser.io frontend. It will offer different layouts of cards for play.I have the game working "just fine" alpha state, but with a single layout of cards setup in HTML with​​where `data.js` is the file that describes the card layout, and `tableau.js` is the game logic. I have several different files in `/gameboards` and for testing/building I change the filename when I want to change the layout.`data.js` is not a json file, it's a js object​let gameboard = {info: {title: "Standard",description: "6 columns of 5 cards"}, \[...\] deal: function() { for (let i = 0; i < this.vars.allstacks; i++) { etc... ​that contains simple object data as well as object methods that define patterns and repetition (like multiple stacks, pyramids, etc) so it can't really be made into a json or other straight data file.What I want to do is present a list of anchors/links to the player of the layout options. They click the link to get sent to `/game` with the layout they chose.The method I thought of was to have `/index` send POST-data containing the `layoutname`. Then, in `/game`router.post('/', function(req,res,next) {with the html template and `res.render` containing​​to call the right file.Is there a better way of doing this that what I listed above? It seems kludgey to me, as if there would be a a more 'nodey' and elegant way to do it.

Submitted December 14, 2018 at 09:33PM by monsto

No comments:

Post a Comment