Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Submodule problems... Fixed now I hope
  • Loading branch information
davidmi committed Jun 21, 2012
1 parent 9ed8e7d commit db9b98e
Show file tree
Hide file tree
Showing 33 changed files with 733 additions and 1 deletion.
1 change: 0 additions & 1 deletion TMXLoader
Submodule TMXLoader deleted from 255316
8 changes: 8 additions & 0 deletions TMXLoader/.classpath
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
33 changes: 33 additions & 0 deletions TMXLoader/.project
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>TMXLoader</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
20 changes: 20 additions & 0 deletions TMXLoader/AndroidManifest.xml
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="davidiserovich.TMXLoader"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".TMXLoaderActivity"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:label="@string/app_name"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>


</manifest>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions TMXLoader/bin/jarlist.cache
@@ -0,0 +1,3 @@
# cache for current jar dependecy. DO NOT EDIT.
# format is <lastModified> <length> <SHA-1> <path>
# Encoding is UTF-8
Binary file added TMXLoader/bin/res/drawable-hdpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TMXLoader/bin/res/drawable-ldpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TMXLoader/bin/res/drawable-mdpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TMXLoader/bin/tmxloader.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions TMXLoader/gen/davidiserovich/TMXLoader/BuildConfig.java
@@ -0,0 +1,6 @@
/** Automatically generated file. DO NOT MODIFY */
package davidiserovich.TMXLoader;

public final class BuildConfig {
public final static boolean DEBUG = true;
}
26 changes: 26 additions & 0 deletions TMXLoader/gen/davidiserovich/TMXLoader/R.java
@@ -0,0 +1,26 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/

package davidiserovich.TMXLoader;

public final class R {
public static final class attr {
}
public static final class drawable {
public static int icon=0x7f020000;
}
public static final class id {
public static int MapImage=0x7f050000;
}
public static final class layout {
public static int main=0x7f030000;
}
public static final class string {
public static int app_name=0x7f040001;
public static int hello=0x7f040000;
}
}
15 changes: 15 additions & 0 deletions TMXLoader/project.properties
@@ -0,0 +1,15 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-4
android.library=true
Binary file added TMXLoader/res/drawable-hdpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TMXLoader/res/drawable-ldpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TMXLoader/res/drawable-mdpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions TMXLoader/res/layout/main.xml
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<SurfaceView android:id="@+id/MapImage" android:layout_width="fill_parent" android:layout_height="fill_parent"></SurfaceView>


</LinearLayout>
5 changes: 5 additions & 0 deletions TMXLoader/res/values/strings.xml
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">The image below was loaded from a TMX file</string>
<string name="app_name">TMXLoader</string>
</resources>
252 changes: 252 additions & 0 deletions TMXLoader/src/davidiserovich/TMXLoader/TMXHandler.java
@@ -0,0 +1,252 @@
package davidiserovich.TMXLoader;

import java.util.HashMap;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

//import android.sax.StartElementListener;
import android.util.Log;

public class TMXHandler extends DefaultHandler {
/*
* This is an SAX2 XML parser that interprets the input TMX
* file and creates a TileMapData object.
*/

// NOTE: Map Object loading is not yet implemented

// Markers for which tag we're in
private boolean inTileSet, inTile, inLayer, inData, inObjectGroup, inProperties;

// ID of the current tile that we're adding properties to.
// This is actually an OFFSET from firstGID of the tile in
// the tileset. Beware.
private String currentTileID;
private String currentObjectGroupName;
TileMapData.TMXObject currentObject;

TileMapData.TileSet currentTileSet;
TileMapData.Layer currentLayer;

HashMap<String, HashMap<String, String>> currentTileSetProperties;
HashMap<String, String> currentLayerProperties;


private TileMapData data;

/*
* These fields hold the buffer and data to
* help decode the long stream of gids in the
* data field
*/
private char buffer[];
private int bufferIndex;
private int currentX;
private int currentY;
public int MAX_INT_DECIMAL_LENGTH = 10;

public TMXHandler(){
super();
buffer = new char[MAX_INT_DECIMAL_LENGTH];
bufferIndex = 0;
currentX = 0;
currentY = 0;
}


public TileMapData getData(){ return data; }

@Override
public void startDocument() throws SAXException{
data = new TileMapData();
}

@Override
public void endDocument() throws SAXException{

}

@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
if(localName.equals("map")) {
//inMap = true;
// Check that the orientation is orthogonal
if (!(atts.getValue("orientation").equals("orthogonal"))){
throw new SAXException("Unsupported orientation. Parse Terminated.");
}
data.orientation = atts.getValue("orientation");
Log.d("Checking", data.orientation);
data.height = Integer.parseInt(atts.getValue("height"));
data.width = Integer.parseInt(atts.getValue("width"));
data.tilewidth = Integer.parseInt(atts.getValue("tilewidth"));
data.tileheight = Integer.parseInt(atts.getValue("tileheight"));


//data.sectionId = atts.getValue("id");
} else if(localName.equals("tileset")) {
inTileSet = true;
currentTileSet = new TileMapData.TileSet();
currentTileSet.firstGID = Integer.parseInt(atts.getValue("firstgid"));
currentTileSet.tileWidth = Integer.parseInt(atts.getValue("tilewidth"));
currentTileSet.tileHeight = Integer.parseInt(atts.getValue("tileheight"));
currentTileSet.name = atts.getValue("name");
currentTileSetProperties = new HashMap<String, HashMap<String, String>>();

} else if (inTileSet && localName.equals("image")){
currentTileSet.ImageFilename = atts.getValue("source");
currentTileSet.imageWidth = Integer.parseInt(atts.getValue("width"));
currentTileSet.imageHeight = Integer.parseInt(atts.getValue("height"));

} else if (inTileSet && localName.equals("tile")){
inTile = true;
currentTileID = atts.getValue("id");

} else if (inTile && localName.equals("properties")){
inProperties = true;
Log.d("Tile ID", currentTileID);
currentTileSetProperties.put(currentTileID, new HashMap<String, String>());

} else if (inLayer && localName.equals("properties")){
inProperties = true;

} else if (inTile && inProperties && localName.equals("property") ){
(currentTileSetProperties.get(currentTileID)).put(atts.getValue("name"), atts.getValue("value"));

} else if (inLayer && inProperties && localName.equals("property")){
currentLayerProperties.put(atts.getValue("name"), atts.getValue("value"));
} else if (localName.equals("layer")){
inLayer = true;

currentLayer = new TileMapData.Layer();
currentLayer.name = atts.getValue("name");
currentLayer.width = Integer.parseInt(atts.getValue("width"));
currentLayer.height = Integer.parseInt(atts.getValue("height"));
if (atts.getValue("opacity") != null) currentLayer.opacity = Double.parseDouble(atts.getValue("opacity"));
currentLayer.tiles = new long[currentLayer.height][currentLayer.width];

currentLayerProperties = new HashMap<String, String>();

} else if(localName.equals("data")){
/* Data is loaded directly into the int array in characters()
* We just check if the encoding is supported here. */
inData = true;
String encoding = atts.getValue("encoding");
if (!encoding.equals("csv")){
throw new SAXException("Unsupported encoding. Parse Terminated.");
}

} else if(localName.equals("objectgroup")){
inObjectGroup = true;
currentObjectGroupName = atts.getValue("name");

} else if(localName.equals("object")){
currentObject = new TileMapData.TMXObject();
currentObject.name = atts.getValue("name");
currentObject.type = atts.getValue("type");
currentObject.x = Integer.parseInt(atts.getValue("x"));
currentObject.y = Integer.parseInt(atts.getValue("y"));
currentObject.width = Integer.parseInt(atts.getValue("width"));
currentObject.height = Integer.parseInt(atts.getValue("height"));
if(inObjectGroup){
currentObject.objectGroup = currentObjectGroupName;
} else { currentObject.objectGroup = null; }

}
}

@Override
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {

if(localName.equals("map")) {
//inMap = false;

} else if(localName.equals("tileset")) {
inTileSet = false;
currentTileSet.properties = currentTileSetProperties;
currentTileSetProperties = null;
data.tilesets.add(currentTileSet);
currentTileSet = null; // Clear it just in case

} else if (localName.equals("tile")){
inTile = false;
currentTileID = "-1"; // -1 won't be produced when searching for properties. Just a safeguard for improperly formatted files.

} else if (localName.equals("properties")){
inProperties = false;

} else if(localName.equals("layer")){
inLayer = false;
currentLayer.properties = currentLayerProperties;
data.layers.add(currentLayer);
currentLayer = null; // Clear it just in case
} else if(localName.equals("data")){
inData = false;
// In case we missed the last entry (no non-numeral chars before tag end)
if (bufferIndex > 0){
currentLayer.tiles[currentY][currentX] = Long.parseLong(new String(buffer, 0, bufferIndex));
}
// Clear buffer
bufferIndex = 0;
currentX = 0;
currentY = 0;

} else if(localName.equals("objectgroup")){
inObjectGroup = false;

} else if (localName.equals("object")){
data.objects.add(currentObject);
}
}

@Override
public void characters(char ch[], int start, int length) {
/* Java has no unsigned types, so we have to use a long
* instead of an int so we can "simulate" an unsigned int.
* Disgusting.
* Anyway, we're going to add the numbers from the character
* stream to a buffer until we hit a comma, at which point we
* empty the buffer and convert it to a long, and dump it
* into the array. These are raw, so the horizontal and vertical
* flip bits may be set - to get the actual GID number, we'll use
* TileMapData's getGIDAt(x, y), which will mask it properly.
*/
if (inData){
for(int i = 0; i < length; i++){
if (ch[start+i] <= '9' && ch[start+i] >= '0'){
buffer[bufferIndex] = ch[start+i];
//Log.d("Wrote to index", String.valueOf(bufferIndex));
bufferIndex++;

}else{
// When we hit a comma or any non-number character, empty the buffer and enter the relevant
// GID into the data field
//int what = Integer.parseInt(new String(buffer, 0, bufferIndex));
//Log.d("Number", new String(buffer, 0, bufferIndex));
String nextNumber = new String(buffer, 0, bufferIndex);
if ((nextNumber != null) && ((nextNumber.trim()) != "") && (bufferIndex != 0)){
//Log.d("Checking", nextNumber + " yes");
currentLayer.tiles[currentY][currentX] = Long.parseLong(nextNumber);
bufferIndex = 0;

// Move to the next tile
if (currentX < (currentLayer.width - 1)){
currentX++;

}else if (currentY < (currentLayer.height - 1)){
currentX = 0;
currentY++;
}
}

}

}
}

}



}

0 comments on commit db9b98e

Please sign in to comment.