Skip to content

Commit 8ae4242

Browse files
authored
Merge pull request #8 from 01010111/dev
Dev
2 parents 9c86c6b + 82c2bb5 commit 8ae4242

File tree

19 files changed

+949
-678
lines changed

19 files changed

+949
-678
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Then you'll be set!
2222
## Usage
2323
This library is split into two distinct sections, Extensions, and Utilities.
2424

25-
Check the WIKI for specific usage instructions!
25+
Check the [API](http://01010111.com/zerolib/) for specific usage instructions!
2626

2727
### .extensions
2828
Extensions are a neat language feature of Haxe. They can add functionality to preexisting classes.
@@ -32,5 +32,4 @@ Learn more about using Extensions [here](https://github.com/01010111/zerolib/wik
3232
### .utilities
3333
A handful of utilities like vectors, a pseudo-random number generator, a tiny ECS implementation, and more!
3434

35-
**[See example usage in the Wiki](https://github.com/01010111/zerolib/wiki)**
3635
**[Browse the API](http://01010111.com/zerolib/)**

src/Main.hx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import zero.utilities.Vec2;
2-
31
class Main {
42
public static function main() {
53
trace('howdy world');

zero/extensions/ArrayExt.hx

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,28 @@ using Math;
77

88
/**
99
* A collection of extension methods for Arrays (some of these are only usable on arrays containing specific types)
10+
*
11+
* **Usage:**
12+
*
13+
* - use this extension by adding this where you normally import modules: `using zero.extensions.ArrayExt;`
14+
* - now you can use any of these functions on different arrays: `[0, 1, 2, 3].get_random(); // 2`
15+
* - or use all of the extensions in this library by adding: `using zero.extensions.Tools;`
1016
*/
1117
class ArrayExt
1218
{
1319

1420
/**
1521
* Converts an array of strings to an array of itegers
16-
* @param array input array
17-
* @return Array<Int>
22+
* @param array input array
23+
* @return Array<Int>
1824
*/
1925
public static inline function strings_to_ints(array:Array<String>):Array<Int> return [for (s in array) Std.parseInt(s)];
2026

2127
/**
2228
* Checks whether or not an array contains a value or object
23-
* @param array input array
24-
* @param value value to check
25-
* @return Bool
29+
* @param array input array
30+
* @param value value to check
31+
* @return Bool
2632
*/
2733
public static inline function contains(array:Array<Dynamic>, value:Dynamic):Bool return array.indexOf(value) >= 0;
2834

@@ -35,15 +41,15 @@ class ArrayExt
3541

3642
/**
3743
* Returns a random element from an array
38-
* @param array input array
39-
* @return Dynamic
44+
* @param array input array
45+
* @return Dynamic
4046
*/
4147
public static inline function get_random(array:Array<Dynamic>):Dynamic return array[array.length.get_random().to_int()];
4248

4349
/**
4450
* shuffles an array in place and returns it
45-
* @param array input array
46-
* @return Array<T>
51+
* @param array input array
52+
* @return Array<T>
4753
*/
4854
public static function shuffle<T>(array:Array<T>):Array<T>
4955
{
@@ -60,9 +66,9 @@ class ArrayExt
6066

6167
/**
6268
* Merges a second array (of the same type) into the first array
63-
* @param a1 first array
64-
* @param a2 second array
65-
* @return Array<T>
69+
* @param a1 first array
70+
* @param a2 second array
71+
* @return Array<T>
6672
*/
6773
public static function merge<T>(a1:Array<T>, a2:Array<T>):Array<T>
6874
{
@@ -97,9 +103,9 @@ class ArrayExt
97103
/**
98104
* Uses a flood-fill algorithm to change equal values contiguous to the input coordinates to a new value
99105
* @param array input array
100-
* @param x x coordinate
101-
* @param y y coordinate
102-
* @param value new value
106+
* @param x x coordinate
107+
* @param y y coordinate
108+
* @param value new value
103109
*/
104110
public static function flood_fill_2D(array:Array<Array<Dynamic>>, x:Int, y:Int, value:Dynamic)
105111
{
@@ -121,9 +127,9 @@ class ArrayExt
121127

122128
/**
123129
* Uses a flood-fill algorithm to change equal values contiguous to the input position to a new value
124-
* @param array input array
125-
* @param pos index position
126-
* @param value new value
130+
* @param array input array
131+
* @param pos index position
132+
* @param value new value
127133
*/
128134
public static function flood_fill_1D(array:Array<Dynamic>, pos:Int, value:Dynamic)
129135
{
@@ -143,10 +149,10 @@ class ArrayExt
143149

144150
/**
145151
* Uses a flood-fill type algorithm to generate a heat map from the coordinates
146-
* @param array input array
147-
* @param x x coordinate
148-
* @param y y coordinate
149-
* @param max_value max heat value, -1 will find the max value based on the minimum result
152+
* @param array input array
153+
* @param x x coordinate
154+
* @param y y coordinate
155+
* @param max_value max heat value, -1 will find the max value based on the minimum result
150156
* @return Array<Array<Int>>
151157
*/
152158
public static function heat_map(array:Array<Array<Dynamic>>, x:Int, y:Int, max_value:Int = -1):Array<Array<Int>>
@@ -178,9 +184,9 @@ class ArrayExt
178184

179185
/**
180186
* get a value from a 2D array with coordinates
181-
* @param array input array
182-
* @param x x coordinate
183-
* @param y y coordinate
187+
* @param array input array
188+
* @param x x coordinate
189+
* @param y y coordinate
184190
* @return Dynamic
185191
*/
186192
public static function get_xy(array:Array<Array<Dynamic>>, x:Int, y:Int):Dynamic
@@ -192,10 +198,10 @@ class ArrayExt
192198

193199
/**
194200
* set a value in a 2D array
195-
* @param array input array
196-
* @param x x coordinate
197-
* @param y y coordinate
198-
* @param value input value
201+
* @param array input array
202+
* @param x x coordinate
203+
* @param y y coordinate
204+
* @param value input value
199205
*/
200206
public static function set_xy(array:Array<Array<Dynamic>>, x:Int, y:Int, value:Dynamic)
201207
{

zero/extensions/EnumExt.hx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package zero.extensions;
2+
3+
using zero.extensions.EnumExt;
4+
using zero.extensions.ArrayExt;
5+
6+
/**
7+
* A collection of extension methods for Enums
8+
*
9+
* **Usage:**
10+
*
11+
* - use this extension by adding this where you normally import modules: `using zero.extensions.EnumExt;`
12+
* - now you can use any of these functions on different arrays: `MyEnum.get_random();`
13+
* - or use all of the extensions in this library by adding: `using zero.extensions.Tools;`
14+
*/
15+
16+
class EnumExt
17+
{
18+
19+
/**
20+
* Get an array of all enums, shortcut for Type.allEnums()
21+
* @param e input
22+
* @return Array<T> return [for (e in Type.allEnums(e)) e]
23+
*/
24+
public static inline function all<T>(e:Enum<T>):Array<T> return [for (e in Type.allEnums(e)) e];
25+
26+
/**
27+
* Returns a random enum value from input
28+
* @param e input
29+
* @return T return e.all().get_random()
30+
*/
31+
public static inline function get_random<T>(e:Enum<T>):T return e.all().get_random();
32+
33+
}

0 commit comments

Comments
 (0)