change location of dependencies

0 favourites
  • 2 posts
  • when a game is exported its dependencies are in its root directory i.e. "c2runtime.js", "data.js", "images/" etc.

    I want to tell my game to point to different locations when loading these dependencies. This is easily done with files in index.html but there are some files (i.e. "data.js") that are loaded later on in the process.

    My website will have a lot of games and I wanted to keep it DRY (don't repeat yourself) by reusing some of the files that are the same.

    How do I change where construct 2 looks for its dependencies? Am I taking this whole DRY thing too far?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ended up writing a php script that updated c2runtime.js and data.js for me:

    function changeFilePointers($directory) {

    //in c2runtime, point to data.js

    $path_to_file = $directory . 'c2runtime.js';

    $file_contents = file_get_contents($path_to_file);

    $file_contents = str_replace("\"data.js\"", "\"/" . $directory . "data.js\"", $file_contents);

    //Also point loading-logo.png in the right direction

    $file_contents = str_replace("\"loading-logo.png\"", "\"/" . $directory . "loading-logo.png\"", $file_contents);

    //save the file

    file_put_contents($path_to_file, $file_contents);

    //in data.js, point images to the right place

    $path_to_file = $directory . 'data.js';

    $file_contents = file_get_contents($path_to_file);

    $file_contents = str_replace("\"images/", "\"/" . $directory . "images/", $file_contents);

    file_put_contents($path_to_file, $file_contents);

    //delete sw.js, I don't need it for now

    $swLocation = $directory . "sw.js";

    if (file_exists($swLocation))

    {

    unlink($directory . "sw.js");

    }

    }

    This allows me a lot of flexibility when working with a framework (I'm using Laravel 5.1). I can now upload zipped games and load them through a route and don't have to rely on a traditional file structure.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)