Skip to content

Instantly share code, notes, and snippets.

@lewislepton
Last active May 20, 2020 13:13
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lewislepton/808d6d2bef1c1c71cf76 to your computer and use it in GitHub Desktop.
Save lewislepton/808d6d2bef1c1c71cf76 to your computer and use it in GitHub Desktop.
snippets to use inside Kode Studio
{
/*
KHA/HAXE SNIPPETS
Lewis Lepton
https://lewislepton.com
*/
"new function": {
"prefix": "function",
"body": [
"public function ${NAME}(){",
"\t",
"}"
],
"description": "new public function"
},
"new function void": {
"prefix": "functionvoid",
"body": [
"public function ${NAME}():Void {",
"\t",
"}"
],
"description": "new public void function"
},
"new private function": {
"prefix": "functionprivate",
"body": [
"private function ${NAME}(){",
"\t",
"}"
],
"description": "new private function"
},
"new private function void": {
"prefix": "functionprivatevoid",
"body": [
"private function ${NAME}():Void {",
"\t",
"}"
],
"description": "new private function void"
},
"new zui function": {
"prefix": "functionzui",
"body": [
"public function ${NAME}(graphics:Graphics){",
"\t",
"\tui.begin(graphics);",
"\tif (ui.window(Id.window(), 0, 0, 200, 300)){",
"\t\tif (ui.node(Id.node(), 'NAME', 1, true)){",
"\t\t //ui code",
"\t\t}",
"\t}",
"\tui.end();",
"}"
],
"description": "new zui function"
},
"function onMouseDown": {
"prefix": "functionOnMouseDown",
"body": [
"public function onMouseDown(button:Int, x:Int, y:Int):Void {",
"\t",
"}"
],
"description": "new on mouse down function"
},
"function onMouseUp": {
"prefix": "functionOnMouseUp",
"body": [
"public function onMouseUp(button:Int, x:Int, y:Int):Void {",
"\t",
"}"
],
"description": "new on mouse up function"
},
"function onMouseMove": {
"prefix": "functionOnMouseMove",
"body": [
"public function onMouseMove(x:Int, y:Int, mx:Int, my:Int):Void {",
"\t",
"}"
],
"description": "new on mouse move function"
},
"function onKeyDown": {
"prefix": "functionOnKeyDown",
"body": [
"public function onKeyDown(keyCode:KeyCode):Void {",
"\t",
"}"
],
"description": "new on key down function"
},
"function onKeyUp": {
"prefix": "functionOnKeyUp",
"body": [
"public function onKeyUp(keyCode:KeyCode):Void {",
"\t",
"}"
],
"description": "new on key up function"
},
"function onGamepadAxis": {
"prefix": "functionOnGamepadAxis",
"body": [
"public function onGamepadAxis(axis:Int, value:Float):Void {",
"\t",
"}"
],
"description": "new on gamepad axis function"
},
"function onGamepadButton": {
"prefix": "functionOnGamepadButton",
"body": [
"public function onGamepadButton(button:Int, value:Float):Void {",
"\t",
"}"
],
"description": "new on gamepad button function"
},
"function onTouchDown": {
"prefix": "functionOnTouchDown",
"body": [
"public function onTouchDown(id:Int, x:Int, y:Int):Void {",
"\t",
"}"
],
"description": "new on touch down function"
},
"function onTouchUp": {
"prefix": "functionOnTouchUp",
"body": [
"public function onTouchUp(id:Int, x:Int, y:Int):Void {",
"\t",
"}"
],
"description": "new on touch up function"
},
"function onTouchMove": {
"prefix": "functionOnTouchMove",
"body": [
"public function onTouchMove(id:Int, x:Int, y:Int):Void {",
"\t",
"}"
],
"description": "new on touch move function"
},
"if statement": {
"prefix": "if",
"body": [
"if ($2){",
"\t",
"}"
],
"description": "if statement"
},
"while statement": {
"prefix": "while",
"body": [
"while ($2){",
"\t",
"}"
],
"description": "while statement"
},
"if statement single": {
"prefix": "ifsingle",
"body": [
"if ($2) $3;"
],
"description": "if single statment"
},
"if else statement": {
"prefix": "ifelse",
"body": [
"if ($2){",
"\t",
"} else {",
"\t",
"}"
],
"description": "if else statement"
},
"if else if statement": {
"prefix": "ifelseif",
"body": [
"if ($2){",
"\t",
"} else if (){",
"\t",
"}"
],
"description": "if else statement"
},
"else if statement": {
"prefix": "elseif",
"body": [
"else if ($2){",
"\t",
"}"
],
"description": "else if statement"
},
"else statement": {
"prefix": "else",
"body": [
"else {",
"\t$2",
"}"
],
"description": "else statement"
},
"switch statement": {
"prefix": "switch",
"body": [
"switch ($2){",
"\t",
"default: return;",
"}"
],
"description": "switch statement"
},
"trace": {
"prefix": "trace",
"body": [
"trace($2);"
],
"description": "trace"
},
"for": {
"prefix": "for",
"body": [
"for ($2 in 0 ... $3){",
"\t",
"}"
],
"description": "for loop"
},
"class": {
"prefix": "class",
"body": [
"class ${NAME} {",
"\tpublic function new(){",
"\t\t",
"\t}",
"}"
],
"description": "class"
},
"classgraphics": {
"prefix": "classgraphics",
"body": [
"import kha.graphics2.Graphics;",
"using kha.graphics2.GraphicsExtension;",
"import kha.Color;",
"import kha.Assets;",
"",
"class ${NAME} {",
"\tpublic function new(){",
"\t\t",
"\t}",
"",
"\tpublic function update(){",
"\t\t",
"\t}",
"",
"\tpublic function render(graphics:Graphics){",
"\t\t",
"\t}",
"}"
],
"description": "classgraphics"
},
"classcanvas": {
"prefix": "classcanvas",
"body": [
"import kha.Canvas;",
"using kha.graphics2.GraphicsExtension;",
"import kha.Color;",
"import kha.Assets;",
"",
"class ${NAME} {",
"\tpublic function new(){",
"\t\t",
"\t}",
"",
"\tpublic function update(){",
"\t\t",
"\t}",
"",
"\tpublic function render(canvas:Canvas){",
"\t\t",
"\t}",
"}"
],
"description": "classcanvas"
},
"classimage": {
"prefix": "classimage",
"body": [
"import kha.graphics2.Graphics;",
"import kha.Color;",
"import kha.Image;",
"import kha.Assets;",
"",
"class ${NAME} {",
"\tpublic function new(){",
"\t\t",
"\t}",
"",
"\tpublic function update(){",
"\t\t",
"\t}",
"",
"\tpublic function render(graphics:Graphics){",
"\t\t",
"\t}",
"}"
],
"description": "classimage"
},
"enum": {
"prefix": "enum",
"body": [
"enum $2 {",
"\t",
"}"
],
"description": "enum"
},
/// CONTROL
"arrow movement": {
"prefix": "arrow bool",
"body": [
"public var up:Bool;",
"public var down:Bool;",
"public var left:Bool;",
"public var right:Bool;"
],
"description": "arrow bool"
},
"arrow movement update delta": {
"prefix": "arrow movement update delta",
"body": [
"if (left){",
"\tthis.x -= Math.round(speed) * delta;",
"} else if (right){",
"\tthis.x += Math.round(speed) * delta;",
"}",
"",
"if (up){",
"\tthis.y -= Math.round(speed) * delta;",
"} else if (down){",
"\tthis.y += Math.round(speed) * delta;",
"}"
],
"description": "arrow movement update delta"
},
"arrow movement update": {
"prefix": "arrow movement update",
"body": [
"if (left){",
"\tthis.x -= Math.round(speed);",
"} else if (right){",
"\tthis.x += Math.round(speed);",
"}",
"",
"if (up){",
"\tthis.y -= Math.round(speed);",
"} else if (down){",
"\tthis.y += Math.round(speed);",
"}"
],
"description": "arrow movement update"
},
"arrow switch movement onKeyDown": {
"prefix": "arrow switch movement onKeyDown",
"body": [
"switch (keyCode){",
"\tcase KeyCode.Up: up = true;",
"\tcase KeyCode.Down: down = true;",
"\tcase KeyCode.Left: left = true;",
"\tcase KeyCode.Right: right = true;",
"default: return;",
"}"
],
"description": "arrow switch movement onKeyDown"
},
"arrow switch movement onKeyUp": {
"prefix": "arrow switch movement onKeyUp",
"body": [
"switch (keyCode){",
"\tcase KeyCode.Up: up = false;",
"\tcase KeyCode.Down: down = false;",
"\tcase KeyCode.Left: left = false;",
"\tcase KeyCode.Right: right = false;",
"default: return;",
"}"
],
"description": "arrow switch movement onKeyUp"
},
"function randomRangeFloat": {
"prefix": "functionRandomRangeFloat",
"body": [
"public function randomRangeFloat(min:Float, max:Float):Float {",
"\treturn Math.floor(Math.random() * (1 + max - min)) + min;",
"}"
],
"description": "function random range float"
},
"function activate": {
"prefix": "functionActivate",
"body": [
"public function activate(?x:Float = 0, ?y:Float = 0){",
"\tactive = true;",
"}"
],
"description": "function activate"
},
"functionDegToRad": {
"prefix": "functionDegToRad",
"body": [
"public function degToRad(angle:Float):Float {",
"\treturn Math.PI / 180 * angle;",
"}"
],
"description": "degrees to radians"
},
"new function settings": {
"prefix": "new function settings",
"body": "?x:Float = 0, ?y:Float = 0, ?width:Float = 64, ?height:Float = 64",
"description": "preset for the new function brackets"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment