-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tile Map #210
Open
SquareLi
wants to merge
1
commit into
aduros:master
Choose a base branch
from
SquareLi:TileMap
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Tile Map #210
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package flambe.math; | ||
|
||
/** | ||
* ... | ||
* @author Ang Li(李昂) | ||
*/ | ||
class Size | ||
{ | ||
|
||
public var width : Float; | ||
public var height : Float; | ||
public function new(?width : Float = 0, ?height : Float = 0) | ||
{ | ||
this.width = width; | ||
this.height = height; | ||
} | ||
|
||
public function setSize(width : Float , height : Float) { | ||
this.width = width; | ||
this.height = height; | ||
} | ||
|
||
public function equals(size : Size) : Bool { | ||
if (this.width == size.width && this.height == size.height) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
public function toString() : String { | ||
return '$width x $height'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
package flambe.tilemap; | ||
|
||
import haxe.io.Bytes; | ||
import haxe.io.BytesInput; | ||
import haxe.zip.InflateImpl; | ||
#if flash | ||
import flash.utils.ByteArray; | ||
import flash.utils.Endian; | ||
#end | ||
|
||
class TMXBase64 | ||
{ | ||
|
||
public function new() | ||
{ | ||
|
||
} | ||
private static inline var BASE64_CHARS:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; | ||
|
||
public static function decode(input : String ) : String { | ||
input = StringTools.ltrim(input); | ||
input = StringTools.rtrim(input); | ||
var output : Array<String> = []; | ||
var enc1 : Int; | ||
var enc2 : Int; | ||
var enc3 : Int; | ||
var enc4 : Int; | ||
var i : Int = 0; | ||
var chr1 : Int; | ||
var chr2 : Int; | ||
var chr3 : Int; | ||
|
||
while (i < input.length) { | ||
enc1 = BASE64_CHARS.indexOf(input.charAt(i++)); | ||
enc2 = BASE64_CHARS.indexOf(input.charAt(i++)); | ||
enc3 = BASE64_CHARS.indexOf(input.charAt(i++)); | ||
enc4 = BASE64_CHARS.indexOf(input.charAt(i++)); | ||
|
||
chr1 = (enc1 << 2) | (enc2 >> 4); | ||
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); | ||
chr3 = ((enc3 & 3) << 6) | enc4; | ||
|
||
output.push(String.fromCharCode(chr1)); | ||
if (enc3 != 64) { | ||
output.push(String.fromCharCode(chr2)); | ||
} | ||
if (enc4 != 64) { | ||
output.push(String.fromCharCode(chr3)); | ||
} | ||
} | ||
|
||
var o : String = output.join(''); | ||
var count : Int = 0; | ||
for (i in output) { | ||
var x = i.charCodeAt(0); | ||
count++; | ||
} | ||
return o; | ||
} | ||
|
||
public static function decodeAsArray(input : String , lineWidth : Int , ?bytes : Int = 4) : Array<Int> { | ||
var dec : String = decode(input); | ||
var ar : Array<Int> = []; | ||
var len : Int = Std.int(dec.length / bytes); | ||
|
||
for (i in 0...len) { | ||
ar[i] = 0; | ||
var j = bytes - 1; | ||
while (j >= 0) { | ||
var t = dec.charCodeAt((i * bytes) + j) << (j * 8); | ||
ar[i] += t; | ||
j--; | ||
} | ||
} | ||
return ar; | ||
} | ||
|
||
private static function decodeAsOneArray(input : String , lineWidth : Int , ?bytes : Int = 4) : Array<Int> { | ||
var dec : String = decode(input); | ||
var ar : Array<Int> = []; | ||
var len : Int = Std.int(dec.length / bytes); | ||
|
||
for (i in 0...len) { | ||
ar[i] = 0; | ||
var j = bytes - 1; | ||
while (j >= 0) { | ||
var t = dec.charCodeAt((i * bytes) + j) << (j * 8); | ||
ar[i] += t; | ||
j--; | ||
} | ||
} | ||
return ar; | ||
} | ||
|
||
private static function decodeAsArrayBytes(byte : Bytes , lineWidth : Int , ?bytes : Int = 4) : Array<Int> { | ||
var ar : Array<Int> = []; | ||
var len : Int = Std.int(byte.length / bytes); | ||
|
||
for (i in 0...len) { | ||
ar[i] = 0; | ||
var j = bytes - 1; | ||
while (j >= 0) { | ||
var t = byte.get((i * bytes) + j) << (j * 8); | ||
ar[i] += t; | ||
j--; | ||
} | ||
} | ||
|
||
return ar; | ||
} | ||
|
||
#if js | ||
public static function unzip(input : String, lineWidth : Int ) : Array<Int> { | ||
var tempString1 : String = decode(input); | ||
var arr : Array<Int> = TMXBase64.decodeAsOneArray(input, 0, 1); | ||
|
||
var b = Bytes.ofData(cast arr); | ||
var bytes : Bytes = InflateImpl.run(new BytesInput(b)); | ||
var ret : Array<Int> = TMXBase64.decodeAsArrayBytes(bytes, lineWidth); | ||
|
||
return ret; | ||
} | ||
#end | ||
|
||
#if flash | ||
public static function unzip(chunk : String, lineWidth : Int) : Array<Int> { | ||
var result:Array<Int> = new Array<Int>(); | ||
var data:ByteArray = base64ToByteArray(chunk); | ||
data.uncompress(); | ||
data.endian = Endian.LITTLE_ENDIAN; | ||
while(data.position < data.length) | ||
{ | ||
|
||
result.push(data.readInt()); | ||
} | ||
return result; | ||
} | ||
|
||
private static function base64ToByteArray(data:String):ByteArray | ||
{ | ||
var output:ByteArray = new ByteArray(); | ||
|
||
var lookup:Array<Int> = new Array<Int>(); | ||
var c:Int; | ||
for (c in 0...BASE64_CHARS.length) | ||
{ | ||
lookup[BASE64_CHARS.charCodeAt(c)] = c; | ||
} | ||
|
||
var i:Int = 0; | ||
while (i < data.length - 3) | ||
{ | ||
if (data.charAt(i) == " " || data.charAt(i) == "\n") | ||
{ | ||
i++; continue; | ||
} | ||
|
||
var a0:Int = lookup[data.charCodeAt(i)]; | ||
var a1:Int = lookup[data.charCodeAt(i + 1)]; | ||
var a2:Int = lookup[data.charCodeAt(i + 2)]; | ||
var a3:Int = lookup[data.charCodeAt(i + 3)]; | ||
|
||
//convert to and write 3 bytes | ||
if(a1 < 64) | ||
output.writeByte((a0 << 2) + ((a1 & 0x30) >> 4)); | ||
if(a2 < 64) | ||
output.writeByte(((a1 & 0x0f) << 4) + ((a2 & 0x3c) >> 2)); | ||
if(a3 < 64) | ||
output.writeByte(((a2 & 0x03) << 6) + a3); | ||
|
||
i += 4; | ||
} | ||
|
||
output.position = 0; | ||
return output; | ||
} | ||
#end | ||
|
||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered using haxe.crypto.BaseCode instead of maintaining your own base64 implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I tried BaseCode.decode(), but it does not work.
My base64 string is "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".
but the BaseCode requires that base length must be a power of two. Then I tried to removed the "=", but the result of decode is empty.