Where to put files?

207 views
Skip to first unread message

Don Morrison

unread,
Mar 20, 2023, 3:40:49 PM3/20/23
to nodeGame, Drew Cranford

If your game has static data it needs access to (server-side only), what’s the preferred place to put that? And what is the best incantation for accessing in logic.js?

Thanks!



Don Morrison df...@cmu.edu
“History is a contest between art and war, and art plays the part
of Sisyphus.” – Will and Ariel Durant, The Age of Voltaire

Stefano B

unread,
Mar 20, 2023, 7:26:15 PM3/20/23
to node...@googlegroups.com
Hi Don,

You can add it to private (or create another local dir within the game dir). Then you load it from game.setup.js, which is shared across all logic instances of the game. 

I generally load all .csv or .json files with a new instance of NDDB:

// SETUP

const path = require('path');
const NDDB = require('NDDB').NDDB;

module.exports = function (settings, stages, dir, level) {

    // Load from private/subdir/.
    const DATADIR = path.join(dir, 'private', 'subdir');
    const file = path.join(DATADIR, "static_file.json");

    let db = NDDB.db();
    db.loadSync(file)
    console.log(db.size());

    // Share to logics via setup.
    setup.mydb = db.loadSync(file);

   // ...

};
    
// LOGIC

module.exports = function(treatmentName, settings, stager, setup, gameRoom) {

   // setup.mydb is what you need.

   // ...

};


Cheers,
Stefano

--
You received this message because you are subscribed to the Google Groups "nodeGame" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodegame+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodegame/CAO9hiFXTzfuhq_gCyzbs9VarydobZ2VJoEnfFS%3DxV-94Gcn6Qw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages