Last active
August 12, 2018 14:46
-
-
Save lewislepton/ef4b480736e0c25720bc to your computer and use it in GitHub Desktop.
init script for KodeStudio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///MY CUSTOM INIT SCRIPT FOR USE WITH KODE STUDIO, BECAUSE ITS MY BITCH | |
"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, '_'); | |
///MY 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 = 1024;\n' | |
+ '\tpublic static var HEIGHT = 768;\n' | |
+ '\n' | |
+ '\tpublic static function main(){\n' | |
+ '\t\tSystem.start({\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.notifyOnFrames(function(framebuffer){\n' | |
+ '\t\t\t\t' + name + '.render(framebuffer[0]);\n' | |
+ '\t\t\t\t});\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;\nimport kha.Color;\nimport kha.Assets;\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\tvar graphics = framebuffer.g2;\n' | |
+ '\t\tgraphics.begin();\n' | |
+ '\t\t\n' | |
+ '\t\tgraphics.end();\n' | |
+ '\t}\n' | |
+ '}\n'; | |
fs.writeFileSync(path.join(from, 'Sources', friendlyName + '.hx'), projectsource, { encoding: 'utf8' }); | |
} | |
///ORIGINAL CODE | |
// if (!fs.existsSync(path.join(from, 'Sources', 'Main.hx'))) { | |
// var 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'))) { | |
// var 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 {' | |
// + '\t\t\n' | |
// + '\t}\n' | |
// + '}\n'; | |
// fs.writeFileSync(path.join(from, 'Sources', friendlyName + '.hx'), projectsource, { encoding: 'utf8' }); | |
// } | |
} | |
exports.run = run; | |
//# sourceMappingURL=init.js.map |
cheers for that bud. ive updated this & will update the kha projects we have been doing that also uses this to 2 or something
thanks again
I'm using windows and I cannot get this to work at all. I'm replacing the contents of the file init.js inside of {KodeStudio folder}\resources\app\extensions\kha\Kha\Tools\khamake\out\init.js I'm using Kode Studio 17.9.1
It seems to not do anything Cause I get different values when I init using f1, init
Edit init.js in kha downloaded from git not Kode studio
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using a value of
3
forsamplesPerPixel
results in runtime errors when building for Windows. This value needs to be 1, 2, 4, 8 or 16 to work correctly.