Coder Social home page Coder Social logo

havasi-scarlet-5 / deepnightlibs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from deepnight/deepnightlibs

0.0 0.0 0.0 3.98 MB

The general personal libs I use in my Haxe projects.

Home Page: https://deepnight.net

License: MIT License

Haxe 100.00%

deepnightlibs's Introduction

About

The general purpose libs I use in all my Haxe projects. If you want to build one of my project, you will need them.

Unit tests

Install

Stable

Use this version if you plan to use the libs for your own projects.

haxelib install deepnightLibs

Latest Git version (mostly stable)

This is the version I use and update very frequently.

Pick this version if you're building one of my GitHub projects, such as LDtk or one of my gamejam entry.

haxelib git deepnightLibs https://github.com/deepnight/deepnightLibs

Usage

In your HXML file, add:

-lib deepnightLibs

All the libs are in the dn.* package.

class MyProject {
	public function new() {
		trace( dn.M.fmin(0.3,0.8) ); // 0.3
	}
}

Tips

Use global imports! To import libs in every HX files, just add a import.hx (this exact name & caps) file to the root of your src folder:

dn.*;
dn.Col as C;
  • The first line imports all classes in dn package,

  • The second one imports dn.Col as an alias "C",

  • Feel free to add your own convenient imports there.

Noteworthy classes

dn.M

My re-implementation of the Math class, with high-performances in mind:

M.fmin(0.5, 0.9); // 0.5
M.frandRange(0, 2); // random Float number between 0 -> 2
M.randRange(0, 2); // either 0, 1 or 2
M.pow(val, 2); // turns into val*val at compilation time

dn.Col

The color management lib, with performance in mind.

A color is an abstract class that revolves around a single Integer value (the color in 0xaarrggbb format). Most methods are just operations on this internal Int value.

import dn.Col;
var c : Col = 0xff0000;  // red
var c : Col = Red;  // also red, but using and enum constant
var c : Col = "#ff0000"; // still red, but the conversion from a constant String to Int is hard-inlined using macros. Costs 0 at runtime.
var darker = c.toBlack(0.5); // return a 50% darker red
var c2 = c.to(Yellow, 0.3); // return a mix from current color with 30% of the standard yellow

dn.DecisionHelper

A nice tool to easily pick a value among many others using any custom criterion.

var arr = [ "a", "foo", "bar", "food", "hello" ];

var dh = new dn.DecisionHelper(arr);

/* Iterates all values in arr and increase their internal score by 1 if they contain the letter "o". */
dh.score( v -> StringTools.contains(v,"o") ? 1 : 0 );

/* Increase score of each values using 10% of their length (ie. longer strings get slightly higher score) */
dh.score( v -> v.length*0.1 );

/* Discard any value containing the letter "h" */
dh.remove( v -> StringTools.contains(v,"h") );

/* Only keep values with length>1 */
dh.keepOnly( v -> v.length>1 );

trace( dh.getBest() ); // -> food
/* Internal scores: a (discarded), foo (1.3), bar (0.3), food (1.4), hello (discarded). */

deepnightlibs's People

Contributors

deepnight avatar grimo0 avatar qkdreyer avatar vincent-lamouroux-redartgames avatar tipyx avatar theneikos avatar qlambert-pro avatar gcardozo123 avatar jcward avatar josuigoa avatar lojemiru avatar markknol avatar klabz avatar sheepolution avatar wolfkabal avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.