Skip to content

Instantly share code, notes, and snippets.

View nadako's full-sized avatar

Dan Korostelev nadako

View GitHub Profile
@nadako
nadako / Scheduler.hx
Last active December 15, 2015 10:29
Time scheduling for turn-based roguelikes.
package dungeons.utils;
/*
A simple time scheduling system based on energy. Can be used for player, monsters, hp regenerators, effect counters,
basically everything.
Loosely based on python example from this article:
http://roguebasin.roguelikedevelopment.org/index.php?title=An_elegant_time-management_system_for_roguelikes
*/
@nadako
nadako / Main.hx
Created April 29, 2013 20:25
Why, neko?
class Main
{
private static function main()
{
function newEmptyHandler():Void->Void
{
return function():Void {};
}
var a:Void->Void = newEmptyHandler();
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.DisplayObject;
import flash.display.GradientType;
import flash.display.IBitmapDrawable;
import flash.display.MovieClip;
import flash.display.Shape;
@nadako
nadako / Globals.hx
Last active February 7, 2021 06:43
A small hack to make JS global variable easily available in Haxe
extern class Globals
{
public static var context(get, never):Context;
inline static function get_context():Context return untyped __js__("context");
}
extern class Context
{
public function doStuff():Void;
}
@nadako
nadako / Main.hx
Last active December 19, 2015 12:48
Type inference fail.
package;
class Main
{
public function new(root)
{
root.addEventListener(flash.events.Event.ENTER_FRAME, onEnterFrame);
}
function onEnterFrame(_)
@nadako
nadako / TestUtils.hx
Last active December 22, 2015 03:38
Haxe assertRaises with macro sugar :)
class TestUtils
{
/**
* Макро-функция для удобного тестирования эксепшенов.
*
* Использовать так:
* assertExprRaises({ throw "OMG"; });
* или так:
* assertExprRaises({ throw "OMG"; }, { assertThat(e, equalTo("OMG")) });
*
@nadako
nadako / SchemaTypeBuilder.hx
Last active October 31, 2020 03:34
JSON-schema type builder prototype.
#if macro
import haxe.macro.Context;
import haxe.macro.Expr;
class SchemaTypeBuilder
{
public static function build(ref:String):haxe.macro.Type
{
var schema = haxe.Json.parse(sys.io.File.getContent(ref));
var type:ComplexType = parseType(schema);
@nadako
nadako / IntRange.hx
Last active July 3, 2018 07:31
IntRange iterator
class IntRange
{
var index:Int;
var end:Int;
var step:Int;
inline function new(start, end, step)
{
this.index = start;
this.end = end;
private typedef TileRule =
{
var tileIndex:Int;
var map:{nw:String, n:String, ne:String, w:String, e:String, sw:String, s:String, se:String};
}
private typedef TileType =
{
var typeStr:String;
var defaultTileIndex:Int;
using StringTools;
/**
* Супер-принтер для JSON.
*
* От не-супер принтера его отличают две вещи:
* 1. Он делает оступы
* 2. Он сортирует поля объектов при сериализации
*
* Он был написан для того чтобы собирать дефы под разными платформами