Skip to content

Instantly share code, notes, and snippets.

@kardoso
Created August 6, 2018 21:57
Show Gist options
  • Save kardoso/1e8f190d87054c66b83d242523a6916f to your computer and use it in GitHub Desktop.
Save kardoso/1e8f190d87054c66b83d242523a6916f to your computer and use it in GitHub Desktop.
init script for KodeStudio
///CUSTOM INIT SCRIPT FOR USE WITH KODE STUDIO
"use strict";
const fs = require('fs');
const path = require('path');
function run(name, from, projectfile) {
if (!fs.existsSync(path.join(from, projectfile))) {
fs.writeFileSync(path.join(from, projectfile), "let project = new Project('New Project');\n"
+ "project.addAssets('Assets/**');\n"
+ "project.addSources('Sources');\n"
+ "resolve(project);\n", { encoding: 'utf8' });
}
if (!fs.existsSync(path.join(from, 'Assets')))
fs.mkdirSync(path.join(from, 'Assets'));
if (!fs.existsSync(path.join(from, 'Sources')))
fs.mkdirSync(path.join(from, 'Sources'));
var friendlyName = name;
friendlyName = friendlyName.replace(/ /g, '_');
friendlyName = friendlyName.replace(/-/g, '_');
///PERSONAL SETUP FOR EVERYTHING TO BE IN MAIN.HX FOR UPDATING AND RENDER
if (!fs.existsSync(path.join(from, 'Sources', 'Main.hx'))) {
var mainsource = 'package;\n\nimport kha.System;\nimport kha.Scheduler;\nimport kha.Assets;\n\n'
+ 'class Main {\n'
+ '\tpublic static var WIDTH = 800;\n'
+ '\tpublic static var HEIGHT = 600;\n'
+ '\n'
+ '\tpublic static function main(){\n'
+ '\t\tSystem.init({\n\t\t\ttitle:"' + name + '",\n\t\t\twidth:WIDTH,\n\t\t\theight:HEIGHT\n\t\t},\n\t\tfunction(){\n'
+ '\t\t\tAssets.loadEverything(function(){\n'
+ '\t\t\t\tvar ' + name + ' = new ' + friendlyName + '();\n'
+ '\t\t\t\tScheduler.addTimeTask(' + name + '.update, 0, 1 / 60);\n'
+ '\t\t\t\tSystem.notifyOnRender(' + name + '.render);\n'
+ '\t\t\t});\n'
+ '\t\t});\n'
+ '\t}\n'
+ '}\n';
fs.writeFileSync(path.join(from, 'Sources', 'Main.hx'), mainsource, { encoding: 'utf8' });
}
if (!fs.existsSync(path.join(from, 'Sources', friendlyName + '.hx'))) {
var projectsource = 'package;\n\nimport kha.Framebuffer;\n\n'
+ 'class ' + friendlyName + ' {\n'
+ '\tpublic function new(){\n'
+ '\t\t\n'
+ '\t}\n'
+ '\n'
+ '\tpublic function update():Void {\n'
+ '\t\t\n'
+ '\t}\n'
+ '\n'
+ '\tpublic function render(framebuffer:Framebuffer):Void {\n'
+ '\t\t\n'
+ '\t}\n'
+ '}\n';
fs.writeFileSync(path.join(from, 'Sources', friendlyName + '.hx'), projectsource, { encoding: 'utf8' });
}
}
exports.run = run;
//ORIGINAL CODE
// "use strict";
// Object.defineProperty(exports, "__esModule", { value: true });
// const fs = require("fs");
// const path = require("path");
// function run(name, from, projectfile) {
// if (!fs.existsSync(path.join(from, projectfile))) {
// fs.writeFileSync(path.join(from, projectfile), 'let project = new Project(\'New Project\');\n'
// + 'project.addAssets(\'Assets/**\');\n'
// + 'project.addSources(\'Sources\');\n'
// + 'resolve(project);\n', { encoding: 'utf8' });
// }
// if (!fs.existsSync(path.join(from, 'Assets')))
// fs.mkdirSync(path.join(from, 'Assets'));
// if (!fs.existsSync(path.join(from, 'Sources')))
// fs.mkdirSync(path.join(from, 'Sources'));
// let friendlyName = name;
// friendlyName = friendlyName.replace(/ /g, '_');
// friendlyName = friendlyName.replace(/-/g, '_');
// if (!fs.existsSync(path.join(from, 'Sources', 'Main.hx'))) {
// let mainsource = 'package;\n\nimport kha.System;\n\n'
// + 'class Main {\n'
// + '\tpublic static function main() {\n'
// + '\t\tSystem.init({title: "' + name + '", width: 1024, height: 768}, function () {\n'
// + '\t\t\tnew ' + friendlyName + '();\n'
// + '\t\t});\n'
// + '\t}\n'
// + '}\n';
// fs.writeFileSync(path.join(from, 'Sources', 'Main.hx'), mainsource, { encoding: 'utf8' });
// }
// if (!fs.existsSync(path.join(from, 'Sources', friendlyName + '.hx'))) {
// let projectsource = 'package;\n\nimport kha.Framebuffer;\nimport kha.Scheduler;\nimport kha.System;\n\n'
// + 'class ' + friendlyName + ' {\n'
// + '\tpublic function new() {\n'
// + '\t\tSystem.notifyOnRender(render);\n'
// + '\t\tScheduler.addTimeTask(update, 0, 1 / 60);\n'
// + '\t}\n'
// + '\n'
// + '\tfunction update(): Void {\n'
// + '\t\t\n'
// + '\t}\n'
// + '\n'
// + '\tfunction render(framebuffer: Framebuffer): Void {\n'
// + '\t\t\n'
// + '\t}\n'
// + '}\n';
// fs.writeFileSync(path.join(from, 'Sources', friendlyName + '.hx'), projectsource, { encoding: 'utf8' });
// }
// }
//exports.run = run;
//# sourceMappingURL=init.js.map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment