Skip to content

Commit

Permalink
Start using haxe-formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Gama11 committed Jun 14, 2019
1 parent 9a4602f commit 82ffa86
Show file tree
Hide file tree
Showing 57 changed files with 8,641 additions and 6,314 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"[haxe]": {
"editor.formatOnSave": true
}
}
75 changes: 40 additions & 35 deletions flixel/addons/ui/Anchor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,74 +10,75 @@ class Anchor implements IFlxDestroyable
{
public var x:AnchorPoint;
public var y:AnchorPoint;

public static inline var LEFT:String = "left";
public static inline var RIGHT:String = "right";
public static inline var TOP:String = "top";
public static inline var BOTTOM:String = "bottom";
public static inline var CENTER:String = "center";
public static inline var UNKNOWN:String = "unknown";
public function new(XOff:Float,YOff:Float,XSide:String,YSide:String,XFlush:String,YFlush:String)

public function new(XOff:Float, YOff:Float, XSide:String, YSide:String, XFlush:String, YFlush:String)
{
x = new AnchorPoint(XOff, XSide, XFlush);
y = new AnchorPoint(YOff, YSide, YFlush);
}

public function destroy():Void {

public function destroy():Void
{
x = null;
y = null;
}

public function anchorThing(thing:FlxObject, destination:FlxObject):Void
{
var destX:Float = 0;
var destY:Float = 0;
destX = switch(x.side)

destX = switch (x.side)
{
case Anchor.LEFT: destination.x;
case Anchor.RIGHT: destination.x + destination.width;
case Anchor.CENTER: destination.x + (destination.width / 2);
case Anchor.LEFT: destination.x;
case Anchor.RIGHT: destination.x + destination.width;
case Anchor.CENTER: destination.x + (destination.width / 2);
default: destination.x;
}
destY = switch(y.side)
destY = switch (y.side)
{
case Anchor.TOP: destination.y;
case Anchor.BOTTOM: destination.y + destination.height;
case Anchor.CENTER: destination.y + (destination.height / 2);
case Anchor.TOP: destination.y;
case Anchor.BOTTOM: destination.y + destination.height;
case Anchor.CENTER: destination.y + (destination.height / 2);
default: destination.y;
}
destX = switch(x.flush)
destX = switch (x.flush)
{
case Anchor.LEFT: destX; //no change
case Anchor.RIGHT: destX - thing.width;
case Anchor.LEFT: destX; // no change
case Anchor.RIGHT: destX - thing.width;
case Anchor.CENTER: destX = destX - (thing.width / 2);
default: destX;
}
destY = switch(y.flush)
destY = switch (y.flush)
{
case Anchor.TOP: destY; //no change
case Anchor.BOTTOM: destY - thing.height;
case Anchor.CENTER: destY - (thing.height / 2);
case Anchor.TOP: destY; // no change
case Anchor.BOTTOM: destY - thing.height;
case Anchor.CENTER: destY - (thing.height / 2);
default: destY;
}
thing.x = destX + x.offset;
thing.y = destY + y.offset;
}

public function getFlipped(FlipX:Bool, FlipY:Bool, ?AnchorObject:Anchor):Anchor
{
var xoff = FlipX ? -1 * x.offset : x.offset;
var yoff = FlipY ? -1 * y.offset : y.offset;

var xside = FlipX ? flipAnchorSide(x.side) : x.side;
var yside = FlipY ? flipAnchorSide(y.side) : y.side;

var xflush = FlipX ? flipAnchorSide(x.flush) : x.flush;
var yflush = FlipY ? flipAnchorSide(y.flush) : y.flush;
if(AnchorObject == null)

if (AnchorObject == null)
{
AnchorObject = new Anchor(xoff, yoff, xside, yside, xflush, yflush);
}
Expand All @@ -90,21 +91,25 @@ class Anchor implements IFlxDestroyable
AnchorObject.x.flush = xflush;
AnchorObject.y.flush = yflush;
}

return AnchorObject;
}

public function clone():Anchor
{
return new Anchor(x.offset, y.offset, x.side, y.side, x.flush, y.flush);
}

private function flipAnchorSide(str:String):String
{
if (str == Anchor.LEFT) return Anchor.RIGHT;
if (str == Anchor.RIGHT) return Anchor.LEFT;
if (str == Anchor.TOP) return Anchor.BOTTOM;
if (str == Anchor.BOTTOM) return Anchor.TOP;
if (str == Anchor.LEFT)
return Anchor.RIGHT;
if (str == Anchor.RIGHT)
return Anchor.LEFT;
if (str == Anchor.TOP)
return Anchor.BOTTOM;
if (str == Anchor.BOTTOM)
return Anchor.TOP;
return str;
}
}
}
12 changes: 6 additions & 6 deletions flixel/addons/ui/AnchorPoint.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package flixel.addons.ui;

class AnchorPoint
{
public var offset:Float = 0; //Manual offset from the anchor point
public var side:String = Anchor.CENTER; //Which side of thing B is the anchor? Anchor.LEFT/RIGHT/TOP/BOTTOM/CENTER
public var flush:String = Anchor.CENTER; //Which side of thing A is flush against the anchor? Anchor.LEFT/RIGHT/TOP/BOTTOM/CENTER
public function new(Offset:Float,Side:String,Flush:String)
public var offset:Float = 0; // Manual offset from the anchor point
public var side:String = Anchor.CENTER; // Which side of thing B is the anchor? Anchor.LEFT/RIGHT/TOP/BOTTOM/CENTER
public var flush:String = Anchor.CENTER; // Which side of thing A is flush against the anchor? Anchor.LEFT/RIGHT/TOP/BOTTOM/CENTER

public function new(Offset:Float, Side:String, Flush:String)
{
offset = Offset;
side = Side;
flush = Flush;
}
}
}
57 changes: 35 additions & 22 deletions flixel/addons/ui/BorderDef.hx
Original file line number Diff line number Diff line change
@@ -1,63 +1,76 @@
package flixel.addons.ui;

import flixel.text.FlxText;
import flixel.util.FlxColor;

class BorderDef
{
public var style:FlxTextBorderStyle;
public var color:FlxColor;
public var style:FlxTextBorderStyle;
public var color:FlxColor;
public var size:Float;
public var quality:Float;

public function new(Style:FlxTextBorderStyle, Color:FlxColor, Size:Float=1, Quality:Float=1) {

public function new(Style:FlxTextBorderStyle, Color:FlxColor, Size:Float = 1, Quality:Float = 1)
{
style = Style;
color = Color;
size = Size;
quality = Quality;
}

public function clone():BorderDef
{
return new BorderDef(style, color, size, quality);
}

public function apply(f:FlxText):FlxText
{
f.setBorderStyle(style, color, size, quality);
return f;
}

public static function fromXML(data:Xml):BorderDef
{
var border_str:String = U.xml_str(data, "border");
var border_style:FlxTextBorderStyle = NONE;
var border_color:Int = U.xml_color(data, "border_color", true, FlxColor.TRANSPARENT);
var border_size:Float = U.xml_f(data, "border_size", 1);
var border_quality:Float = U.xml_f(data, "border_quality", 0);

var borderDef = new BorderDef(border_style, border_color, border_size, border_quality);
switch(border_str)

switch (border_str)
{
case "false", "none": borderDef.style = NONE;
case "shadow": borderDef.style = SHADOW;
case "outline": borderDef.style = OUTLINE;
case "outline_fast": borderDef.style = OUTLINE_FAST;
case "false", "none":
borderDef.style = NONE;
case "shadow":
borderDef.style = SHADOW;
case "outline":
borderDef.style = OUTLINE;
case "outline_fast":
borderDef.style = OUTLINE_FAST;
case "":
//no "border" value, check for shortcuts:
//try "outline"
// no "border" value, check for shortcuts:
// try "outline"
border_str = U.xml_str(data, "shadow", true, "");
if (border_str != "" && border_str != "false" && border_str != "none") {
if (border_str != "" && border_str != "false" && border_str != "none")
{
borderDef.style = SHADOW;
borderDef.color = U.parseHex(border_str, false, true);
}else{
}
else
{
border_str = U.xml_str(data, "outline", true, "");
if (border_str != "" && border_str != "false" && border_str != "none") {
if (border_str != "" && border_str != "false" && border_str != "none")
{
borderDef.style = OUTLINE;
borderDef.color = U.parseHex(border_str, false, true);
}else{
}
else
{
border_str = U.xml_str(data, "outline_fast");
if (border_str != "" && border_str != "false" && border_str != "none") {
if (border_str != "" && border_str != "false" && border_str != "none")
{
borderDef.style = OUTLINE_FAST;
borderDef.color = U.parseHex(border_str, false, true);
}
Expand All @@ -66,4 +79,4 @@ class BorderDef
}
return borderDef;
}
}
}
35 changes: 21 additions & 14 deletions flixel/addons/ui/ButtonLabelStyle.hx
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
package flixel.addons.ui;

import flixel.text.FlxText;

class ButtonLabelStyle
class ButtonLabelStyle
{
public var font:FontDef=null;
public var border:BorderDef=null;
public var color:Null<Int>=null;
public var align:FlxTextAlign=null;

public function new(?Font:FontDef, ?Align:FlxTextAlign, ?Color:Int, ?Border:BorderDef) {
public var font:FontDef = null;
public var border:BorderDef = null;
public var color:Null<Int> = null;
public var align:FlxTextAlign = null;

public function new(?Font:FontDef, ?Align:FlxTextAlign, ?Color:Int, ?Border:BorderDef)
{
font = Font;
border = Border;
color = Color;
align = Align;
}

public function apply(f:FlxText):Void {
if (font != null) {

public function apply(f:FlxText):Void
{
if (font != null)
{
font.apply(f);
}
if (border != null) {
if (border != null)
{
border.apply(f);
}
if (color != null) {
if (color != null)
{
f.color = color;
}
if (align != null) {
if (align != null)
{
f.alignment = align;
}
}
}
}
Loading

0 comments on commit 82ffa86

Please sign in to comment.