Skip to content

Commit

Permalink
Cleanup and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
01010111 committed Jan 8, 2019
1 parent 8c346f1 commit ba5a231
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 40 deletions.
33 changes: 27 additions & 6 deletions zero/ext/flx/FlxTilemapExt.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,41 @@ package zero.ext.flx;

import flixel.tile.FlxTilemap;
import flixel.math.FlxPoint;
import zero.util.IntPoint;
import zero.util.Vector;

using Math;
using zero.ext.FloatExt;
using zero.ext.flx.FlxPointExt;
using zero.ext.flx.FlxTilemapExt;

class FlxTilemapExt
{

/**
* Returns the tile index at a given point
* @param t tilemap
* @param p point
* @return Int
*/
public static inline function get_index_from_point(t:FlxTilemap, p:FlxPoint):Int return t.getTile((p.x / t.get_tile_width()).floor(), (p.y / t.get_tile_height()).floor());

/**
* Returns a tile's allowCollisions value at a given point
* @param t tilemap
* @param p point
* @return Int
*/
public static inline function get_collisions_from_point(t:FlxTilemap, p:FlxPoint):Int return t.getTileCollisions(t.get_index_from_point(p));
public static inline function get_tile_width(t:FlxTilemap) return t.width / t.widthInTiles;
public static inline function get_tile_height(t:FlxTilemap) return t.height / t.heightInTiles;

/**
* Returns the tile width of a tilemap
* @param t tilemap
* @return return
*/
public static inline function get_tile_width(t:FlxTilemap):Float return t.width / t.widthInTiles;

/**
* Returns the tile height of a tilemap
* @param t tilemap
* @return return
*/
public static inline function get_tile_height(t:FlxTilemap):Float return t.height / t.heightInTiles;

}
10 changes: 10 additions & 0 deletions zero/flxutil/ecs/components/CallbackAfterTimer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,27 @@ class CallbackAfterTimer extends Component
var timer:Float = 0;
var callback: Void -> Void;

/**
* Creates a timer object that executes a callback function when time has run out. Use reset() to start timer.
* @param callback callback function
* @param name component name
*/
public function new(callback:Void -> Void, name:String = 'callback_after_timer')
{
super(name);
this.callback = callback;
}

/**
* Start the timer with a given time
* @param time
*/
public function reset(time:Float)
{
timer = time;
}

@:dox(hide)
override public function update(dt:Float)
{
if (timer <= 0) return;
Expand Down
15 changes: 7 additions & 8 deletions zero/flxutil/ecs/components/KillAfterAnimation.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import zero.flxutil.ecs.Component;
class KillAfterAnimation extends Component
{

public function new()
{
super('kill_after_animation');
}
/**
* Kills an entity after it's animation is finished
* @return super('kill_after_animation')
*/
public function new() super('kill_after_animation');

override public function update(dt:Float)
{
if (entity.animation.finished) entity.kill();
}
@:dox(hide)
override public function update(dt:Float) if (entity.animation.finished) entity.kill();

}
9 changes: 5 additions & 4 deletions zero/flxutil/ecs/components/KillAfterTimer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package zero.flxutil.ecs.components;
class KillAfterTimer extends CallbackAfterTimer
{

public function new()
{
super(function() { entity.kill(); }, 'kill_after_timer');
}
/**
* Kills an entity after a timer. Use reset() to start timer.
* @return super(function()
*/
public function new() super(function() { entity.kill(); }, 'kill_after_timer');

}
3 changes: 2 additions & 1 deletion zero/flxutil/ecs/components/PlatformerWalker.hx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class PlatformerWalker extends Component
entity.maxVelocity.x = walk_speed;
drag.x = drag_amt;
}


@:dox(hide)
override public function update(dt:Float)
{
acceleration.x = 0;
Expand Down
3 changes: 2 additions & 1 deletion zero/flxutil/ecs/components/TopDownWalker.hx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class TopDownWalker extends Component
entity.maxVelocity.set(walk_speed, walk_speed);
drag.set(drag_amt, drag_amt);
}


@:dox(hide)
override public function update(dt:Float)
{
acceleration.set();
Expand Down
1 change: 0 additions & 1 deletion zero/flxutil/formats/BitsyFont.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package zero.flxutil.formats;

import haxe.Json;
import openfl.Assets;
import flixel.math.FlxPoint;
import flixel.system.FlxAssets;
Expand Down
11 changes: 11 additions & 0 deletions zero/flxutil/formats/OgmoLoader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ using zero.ext.StringExt;
class OgmoLoader extends FlxOgmoLoader
{

/**
* Returns 2D array of tile ids of a given tile layer
* @param tile_layer
* @return
*/
public function get_tilemap_array(tile_layer:String = 'tiles'):Array<Array<Int>> return _fastXml.node.resolve(tile_layer).innerData.csv_to_2d_int_array();

/**
* Returns CSV of tile ids of a given tile layer
* @param tile_layer
* @return
*/
public function get_tilemap_csv(tile_layer:String = 'tiles'):String return _fastXml.node.resolve(tile_layer).innerData;

}
1 change: 0 additions & 1 deletion zero/flxutil/formats/ZFont.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package zero.flxutil.formats;

import flixel.math.FlxPoint;
import flixel.system.FlxAssets;
import flixel.text.FlxText.FlxTextAlign;
import haxe.Json;
import openfl.Assets;
Expand Down
4 changes: 4 additions & 0 deletions zero/flxutil/shaders/ColorMix.hx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class ColorMix extends FlxShader
}'
)

/**
* Mixes a sprite with a given color - use color and uMix to update the color and mix amount.
* @param color
*/
public function new(color:Int = 0xFFFFFFFF)
{
super();
Expand Down
13 changes: 13 additions & 0 deletions zero/flxutil/shaders/FourColor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,20 @@ class FourColor extends FlxShader
}'
)

/**
* Creates a 4 color palette shader - useful for gameboy-like games!
* @param palette
*/
public function new(palette:Array<Int>)
{
super();
set_palette(palette);
}

/**
* Sets the palette using an array of four colors (Ints), colors should be ordered from dark to light
* @param palette
*/
public function set_palette(palette:Array<Int>)
{
if (palette.length != 4)
Expand All @@ -48,6 +56,11 @@ class FourColor extends FlxShader
set_color(WHITE, palette[3]);
}

/**
* Set a specific palette index to the given color
* @param index
* @param color
*/
public function set_color(index:PaletteIndex, color:Int)
{
switch (index) {
Expand Down
4 changes: 4 additions & 0 deletions zero/flxutil/sprites/Grid.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ using Math;
class Grid extends FlxSprite
{

/**
* Creates a sprite and draws a grid on it using given options.
* @param options
*/
public function new(options:GridOptions)
{
super(options.x, options.y);
Expand Down
16 changes: 16 additions & 0 deletions zero/flxutil/sprites/Stack.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class Stack extends FlxSprite

public var z_offset:Float;

/**
* Creates a stack - a set of sprites that fake 3D by layering and offsetting sprites. Use this.add() to add to state!
* @param options
*/
public function new(options:StackOptions)
{
super(options.position.x, options.position.y);
Expand Down Expand Up @@ -61,8 +65,14 @@ class Stack extends FlxSprite
slice_post_init(slice);
}

/**
* Adds stack to the given state.
* @param state
* @return state.add(group)
*/
public function add(state:FlxState) state.add(group);

@:dox(hide)
override public function update(dt:Float)
{
super.update(dt);
Expand All @@ -81,6 +91,10 @@ class Stack extends FlxSprite
slice.angle = angle;
}

/**
* Combines this stack with a given stack
* @param stack
*/
public function combine(stack:Stack)
{
StackManager.i.base_group.remove(stack);
Expand All @@ -90,6 +104,7 @@ class Stack extends FlxSprite

}

@:dox(hide)
class StackGroup extends FlxTypedGroup<FlxSprite>
{

Expand All @@ -111,6 +126,7 @@ class StackGroup extends FlxTypedGroup<FlxSprite>

}

@:dox(hide)
class StackManager
{

Expand Down
5 changes: 0 additions & 5 deletions zero/flxutil/ui/BitmapText.hx
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package zero.flxutil.ui;

import haxe.Json;
import openfl.Assets;
import flixel.graphics.frames.FlxBitmapFont;
import flixel.math.FlxPoint;
import flixel.system.FlxAssets;
import flixel.text.FlxBitmapText;
import flixel.text.FlxText.FlxTextAlign;
import flixel.FlxG;
import openfl.display.BitmapData;
import haxe.Utf8;

using Math;
using StringTools;

/**
* A wrapper for FlxBitmapText that makes it easy to use a monospaced bitmap font image
Expand Down
7 changes: 0 additions & 7 deletions zero/flxutil/ui/NineSliceBox.hx
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
package zero.flxutil.ui;

import flixel.addons.ui.FlxSlider;
import flixel.math.FlxRect;
import flixel.system.FlxAssets;
import flixel.FlxSprite;
import flixel.math.FlxPoint;
import openfl.display.BitmapData;
import zero.flxutil.util.GameLog.*;
import zero.util.IntPoint;

using flixel.util.FlxSpriteUtil;
using zero.ext.FloatExt;
using zero.ext.flx.FlxSpriteExt;
using Math;

class NineSliceBox extends FlxSprite
Expand Down
25 changes: 19 additions & 6 deletions zero/flxutil/ui/RichText.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package zero.flxutil.ui;

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.system.FlxAssets;
import zero.util.IntPoint;
Expand Down Expand Up @@ -31,6 +30,10 @@ class RichText extends FlxTypedGroup<RichTextChar>
var override_type_effect:Bool = false;
var wiggle_timer:Float = 0;

/**
* Creates a rich text object for animated text.
* @param options
*/
public function new(options:RichTextOptions)
{
super();
Expand All @@ -44,7 +47,7 @@ class RichText extends FlxTypedGroup<RichTextChar>
FlxG.watch.add(this, 'wiggle_timer', 'WT:');
}

public function create_defaults(options:RichTextOptions)
function create_defaults(options:RichTextOptions)
{
if (options.position == null) options.position = FlxPoint.get(0, 0);

Expand Down Expand Up @@ -84,10 +87,14 @@ class RichText extends FlxTypedGroup<RichTextChar>
return options;
}

public function get_anim_options():RichTextAnimOptions return anim_options;
public function get_current_color():Int return current_color;
public function get_wiggle_timer():Float return wiggle_timer;
@:dox(hide) public function get_anim_options():RichTextAnimOptions return anim_options;
@:dox(hide) public function get_current_color():Int return current_color;
@:dox(hide) public function get_wiggle_timer():Float return wiggle_timer;

/**
* Enqueues text to be parsed and displayed
* @param s
*/
public function queue(s:String)
{
if (s.length == 0) return;
Expand All @@ -96,7 +103,7 @@ class RichText extends FlxTypedGroup<RichTextChar>
state = READY;
}

public function parse_input(s:String):Array<String>
function parse_input(s:String):Array<String>
{
var out = [];
var temp_s = parse_new_line_chars(remove_unavailable_characters(s));
Expand Down Expand Up @@ -172,6 +179,10 @@ class RichText extends FlxTypedGroup<RichTextChar>
return lines.join(' ');
}

/**
* Invokes queued text to be displayed, returns true if there is still text enqueued. Call during text output to interrupt/show all text.
* @return Bool
*/
public function invoke():Bool
{
switch (state)
Expand All @@ -197,6 +208,7 @@ class RichText extends FlxTypedGroup<RichTextChar>
}
}

@:dox(hide)
override public function update(dt)
{
wiggle_timer = (wiggle_timer + dt) % 1;
Expand Down Expand Up @@ -312,6 +324,7 @@ class RichText extends FlxTypedGroup<RichTextChar>

}

@:dox(hide)
class RichTextChar extends Particle
{

Expand Down

0 comments on commit ba5a231

Please sign in to comment.