Skip to content

Commit

Permalink
Added support for the action to open an URL in GDJS (with support for…
Browse files Browse the repository at this point in the history
… CocoonJS & Intel XDK)
  • Loading branch information
4ian committed Oct 14, 2014
1 parent 9f15f25 commit c648380
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
8 changes: 4 additions & 4 deletions Core/GDCore/BuiltinExtensions/FileExtension.cpp
Expand Up @@ -127,13 +127,13 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsFileExtension(gd::Platf
.MarkAsAdvanced();

extension.AddAction("LaunchFile",
_("Launch a file"),
_("This action launch the specified file."),
_("Launch the file _PARAM0_"),
_("Open an URL or a file"),
_("This action launch the specified file or URL, in a browser (or in a new tab if the game is using the Web platform and is launched inside a browser)."),
_("Open URL (or file) _PARAM0_"),
_("Files"),
"res/actions/launchFile24.png",
"res/actions/launchFile.png")
.AddParameter("file", _("Filename"), "",false)
.AddParameter("string", _("URL (or filename)"), "",false)
.MarkAsAdvanced();

extension.AddAction("ExecuteCmd",
Expand Down
12 changes: 2 additions & 10 deletions GDJS/GDJS/BuiltinExtensions/FileExtension.cpp
Expand Up @@ -41,6 +41,8 @@ FileExtension::FileExtension()
.codeExtraInformation.SetFunctionName("gdjs.evtTools.storage.deleteElementFromJSONFile");
GetAllActions()["DeleteFichier"].SetGroup(_("Storage"))
.codeExtraInformation.SetFunctionName("gdjs.evtTools.storage.clearJSONFile");
GetAllActions()["LaunchFile"]
.codeExtraInformation.SetFunctionName("gdjs.evtTools.window.openURL");

StripUnimplementedInstructionsAndExpressions(); //Unimplemented things are listed here:
/*
Expand All @@ -54,16 +56,6 @@ FileExtension::FileExtension()
.AddParameter("file", _("Filename"), "",false)
.codeExtraInformation.SetFunctionName("FileExists").SetIncludeFile("GDCpp/BuiltinExtensions/FileTools.h");
AddAction("LaunchFile",
_("Launch a file"),
_("This action launch the specified file."),
_("Launch the file _PARAM0_"),
_("Files"),
"res/actions/launchFile24.png",
"res/actions/launchFile.png")
.AddParameter("file", _("Filename"), "",false)
.codeExtraInformation.SetFunctionName("LaunchFile").SetIncludeFile("GDCpp/BuiltinExtensions/FileTools.h");
AddAction("ExecuteCmd",
_("Execute a command"),
_("This action execute the specified command."),
Expand Down
6 changes: 6 additions & 0 deletions GDJS/GDJS/Exporter.cpp
Expand Up @@ -540,6 +540,12 @@ bool Exporter::ExportWholeProject(gd::Project & project, std::string exportDir,
fs.MkDir(exportDir+"/Extensions");
std::vector<std::string> includesFiles;

if (exportForCocoonJS)
{
fs.MkDir(exportDir+"/libs/CocoonJS");
includesFiles.push_back("libs/CocoonJS/cocoon.min.js");
}

gd::Project exportedProject = project;

//Export the resources ( before generating events as some resources filenames may be updated )
Expand Down
4 changes: 4 additions & 0 deletions GDJS/Runtime/libs/CocoonJS/cocoon.min.js

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion GDJS/Runtime/windowtools.js
Expand Up @@ -5,7 +5,7 @@
*/

/**
* Tools related to runtime scene, for events generated code.
* Tools related to window, for events generated code.
* @namespace gdjs.evtTools
* @class window
* @static
Expand Down Expand Up @@ -44,3 +44,15 @@ gdjs.evtTools.window.getWindowWidth = function() {
gdjs.evtTools.window.getWindowHeight = function() {
return window.innerHeight;
};

gdjs.evtTools.window.openURL = function(url) {
//Try to detect the environment to use the most adapted
//way of opening an URL.
if (typeof intel !== "undefined" && intel.xdk && intel.xdk.device && intel.xdk.device.launchExternal) {
intel.xdk.device.launchExternal(url);
} else if (typeof Cocoon !== "undefined" && Cocoon.App && Cocoon.App.openURL ) {
Cocoon.App.openURL(url);
} else {
window.open(url);
}
}

0 comments on commit c648380

Please sign in to comment.