change location of dependencies

Discussion and feedback on Construct 2

Post » Thu Jun 25, 2015 2:22 pm

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?

:)
B
12
S
2
Posts: 39
Reputation: 1,082

Post » Sat Jun 27, 2015 3:11 pm

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.
B
12
S
2
Posts: 39
Reputation: 1,082


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 5 guests