diff --git a/hGameTest/res/textures/sheets/sheet.htex.json b/hGameTest/res/textures/sheets/sheet.htex.json index 30ee1b76..1c427651 100644 --- a/hGameTest/res/textures/sheets/sheet.htex.json +++ b/hGameTest/res/textures/sheets/sheet.htex.json @@ -9,28 +9,28 @@ "tileSize":{ "x":16, "y":16 - }, - "tilesetGeneric":{ - "baseTexture":"textures/sheets/sheet.png", - "tiles":[ - "testTile1", - "testTile2", - "testTile3", - "testTile4", - "testTile5", - "testTile6", - "testTile7", - "testTile8", - "testTile9", - "testTile10", - "testTile11", - "testTile12", - "testTile13", - "testTile14", - "testTile15", - "testTile16" - ] } + }, + "tilesetGeneric":{ + "baseTexture":"textures/sheets/sheet.png", + "tiles":[ + "testTile1", + "testTile2", + "testTile3", + "testTile4", + "testTile5", + "testTile6", + "testTile7", + "testTile8", + "testTile9", + "testTile10", + "testTile11", + "testTile12", + "testTile13", + "testTile14", + "testTile15", + "testTile16" + ] } } } \ No newline at end of file diff --git a/hGameTest/res/textures/sheets/sheetAnim.htex.json b/hGameTest/res/textures/sheets/sheetAnim.htex.json index 04d58c08..cb10303f 100644 --- a/hGameTest/res/textures/sheets/sheetAnim.htex.json +++ b/hGameTest/res/textures/sheets/sheetAnim.htex.json @@ -2,35 +2,21 @@ "datascheme":"htex", "version":"1", "textureData":{ - "texName":"testsheet", + "texName":"testanimsheet", "texType":"atlas", "atlas":{ - "atlasType":"tilesetgeneric", + "atlasType":"tilesetanimated", "tileSize":{ "x":16, "y":16 }, - "tilesetGeneric":{ - "baseTexture":"textures/sheets/sheet.png", - "tiles":[ - "testTile1", - "testTile2", - "testTile3", - "testTile4", - "testTile5", - "testTile6", - "testTile7", - "testTile8", - "testTile9", - "testTile10", - "testTile11", - "testTile12", - "testTile13", - "testTile14", - "testTile15", - "testTile16" - ] - } + "tilesetAnimated":{ + "baseTexture":"textures/sheets/sheet.png", + "sequences":[ + {"name":"testsequence1","sequenceStart":0,"sequenceEnd":7}, + {"name":"testsequence2","sequenceStart":8,"sequenceEnd":15} + ] + } } } } \ No newline at end of file diff --git a/hGameTest/res/textures/sprites/missing.png b/hGameTest/res/textures/sprites/missing.png new file mode 100644 index 00000000..d3f3d0c6 Binary files /dev/null and b/hGameTest/res/textures/sprites/missing.png differ diff --git a/hGameTest/src/Game.hx b/hGameTest/src/Game.hx index 6798ea96..4bbb61d4 100644 --- a/hGameTest/src/Game.hx +++ b/hGameTest/src/Game.hx @@ -1,3 +1,4 @@ +import assets.tilesets.TilesetGeneric; import openfl.display.Bitmap; import openfl.display.Stage; import openfl.display.Bitmap; @@ -5,9 +6,9 @@ import openfl.display.BitmapData; import openfl.display.Sprite; import openfl.events.Event; import openfl.Assets; -import assets.TextureData; -import assets.SpriteSheet; import assets.Scanner; +import assets.HTex; + class Game { @@ -23,14 +24,19 @@ class Game //player.graphics.lineStyle(2,0xFF0000); //player.graphics.drawRect(0,0,16,16); // var bitmapData:BitmapData = Assets.getBitmapData("textures/sprites/character.png"); - var sheetData:BitmapData = Assets.getBitmapData("textures/sheets/sheet.png"); - var sheet:SpriteSheet = new SpriteSheet(sheetData); - - var playerBitmap:Bitmap = new Bitmap(sheet.sprites[15]); - playerBitmap.scaleX = playerBitmap.scaleY = 10; - player.addChild(playerBitmap); - //TextureData.parseConfig(); Scanner.scanTextureDir(); + var sheetData:BitmapData = Assets.getBitmapData("textures/sheets/sheet.png"); + for(tex in Scanner.textures){ + HTex.createTextureObjectFromJSON(tex); + } + //var sheet:SpriteSheet = new SpriteSheet(sheetData); + + var playerBitmap:Bitmap = new Bitmap(TilesetGeneric.tilesetGenericMap["testsheet"].tileMap["testTile5"]); + var someotherbitmap:Bitmap = new Bitmap(TilesetGeneric.tilesetGenericMap["testsheet"].tileMap["testTile3"]); + + playerBitmap.scaleX = playerBitmap.scaleY = 10; + player.addChild(playerBitmap); + //TextureData.parseConfig(); //Sys. } public function onEnterFrame(e:Event):Void diff --git a/hGameTest/src/assets/HTex.hx b/hGameTest/src/assets/HTex.hx index 8481b13e..491af41f 100644 --- a/hGameTest/src/assets/HTex.hx +++ b/hGameTest/src/assets/HTex.hx @@ -1,26 +1,38 @@ package assets; import openfl.display.BitmapData; -import assets.schema.HTexSchema.TexV1; +import openfl.Assets; +import assets.schema.HTexSchema; +import assets.tilesets.TilesetGeneric; +import assets.tilesets.TextureAtlas; +import haxe.Json; class HTex{ public static var hTexArray:Array = []; public var bitmaps:Array; public var name:String = ""; public function new(_name:String){ - name = _name; - if(hTexArray[name] == null) - hTexArray[name] = name; + // name = _name; + // if(hTexArray[name] == null) + // hTexArray[name] = name; } public static function createTextureObjectFromJSON(path:String){ var DATA:TexV1; var loadedData:String = Assets.getText(path); var jsondata = Json.parse(loadedData); DATA = jsondata; - DATA = TexV1; - if(DATA.dataScheme == "htex"){ + if(DATA.datascheme == "htex"){ if(DATA.version == 1){ - var texdata:TextureDataV1 = Data.textureData; + var td:TextureDataV1 = DATA.textureData; + var width:Int = td.atlas.tileSize.x; + var height:Int = td.atlas.tileSize.y; + if(td.atlas.atlasType == "tilesetgeneric"){ + var baseTexturePath:String = td.tilesetGeneric.baseTexture; + var tileNames:Array = td.tilesetGeneric.tiles; + var atlas:TextureAtlas = new TextureAtlas(Assets.getBitmapData(baseTexturePath),width,height); + var tileSetGeneric = new TilesetGeneric(td.texName, atlas, tileNames); + trace(tileSetGeneric); + } } } } diff --git a/hGameTest/src/assets/TextureData.hx b/hGameTest/src/assets/TextureData.hx deleted file mode 100644 index 227ad5bb..00000000 --- a/hGameTest/src/assets/TextureData.hx +++ /dev/null @@ -1,44 +0,0 @@ -package assets; - -import openfl.Assets; -import haxe.Json; - -typedef TexturesV1={ - var dataScheme:String; - var version:Int; - var textureData:{ - var spriteSheets:Array<{ - var sheetNamekeke:String; - var path:String; - var sheetDataPath:String; - var explicitDimensions:Bool; - var tileDimensions:{ - var width:Int; - var height:Int; - }; - }>; - var sprites:Array<{ - var spriteName:String; - var path:String; - }>; - }; -} - -class TextureData{ - public static var textures:Array = []; - public static function parseConfig(path:String = "data/textures.json"){ - var DATA:TexturesV1; - var loadedData:String = Assets.getText(path); - var jsondata = Json.parse(loadedData); - DATA = jsondata; - //var test:String = File.getContent(test.txt); - trace(DATA); - /*typedef DataModal= - { - var ID:Int; - var NAME:String; - var TAGS:Array; - } - */ - } -} diff --git a/hGameTest/src/assets/files/TextureFile.hx b/hGameTest/src/assets/files/TextureFile.hx new file mode 100644 index 00000000..8f57e11a --- /dev/null +++ b/hGameTest/src/assets/files/TextureFile.hx @@ -0,0 +1,27 @@ +package assets; + +import openfl.display.BitmapData; +import openfl.Assets; +import haxe.Json; +import assets.tilesets.Tileset; + +class TextureFile{ + public static var pathMap:Map; + public static function addUser(path:String, user:Dynamic):Void + { + if(pathMap[path] == null){ + pathMap[path] = new TextureFile(); + } + pathMap[path].users.push(user); + } + public static function removeUser():Void + { + if() + } + public var bitmapData:BitmapData = null; + public var users:Array=[]; + public var path:String; + private function new(){ + + } +} diff --git a/hGameTest/src/assets/schema/HTexSchema.hx b/hGameTest/src/assets/schema/HTexSchema.hx index 66f4f3e6..bafc1f5e 100644 --- a/hGameTest/src/assets/schema/HTexSchema.hx +++ b/hGameTest/src/assets/schema/HTexSchema.hx @@ -6,7 +6,6 @@ typedef TileSetGenericV1={ var baseTexture:String; var tiles:Array; } - typedef TileSetAnimatedV1={ var baseTexture:String; var animations:Array<{ @@ -23,25 +22,14 @@ typedef TextureDataV1={ var tileSize:{ var x:Int; var y:Int; - }, - var tileSetGeneric:TileSetGenericV1; - var tileSetAnimated:TileSetAnimatedV1; + }; } - var path:String; - var sheetDataPath:String; - var explicitDimensions:Bool; - var tileDimensions:{ - var width:Int; - var height:Int; - }; - var sprites:Array<{ - var spriteName:String; - var path:String; - }>; + var tilesetGeneric:TileSetGenericV1; + var tilesetAnimated:TileSetAnimatedV1; } typedef TexV1={ - var dataScheme:String; + var datascheme:String; var version:Int; var textureData:TextureDataV1; } \ No newline at end of file diff --git a/hGameTest/src/assets/tilesets/Sequence.hx b/hGameTest/src/assets/tilesets/Sequence.hx index 1f63ad69..e843930b 100644 --- a/hGameTest/src/assets/tilesets/Sequence.hx +++ b/hGameTest/src/assets/tilesets/Sequence.hx @@ -4,7 +4,6 @@ import openfl.display.BitmapData; class Sequence{ public var bitmaps:Array = []; public var name:String = ""; - public var currentFrame = 0; public function new(_name:String, _bitmaps:Array){ name = _name; bitmaps = _bitmaps; diff --git a/hGameTest/src/assets/SpriteSheet.hx b/hGameTest/src/assets/tilesets/TextureAtlas.hx similarity index 63% rename from hGameTest/src/assets/SpriteSheet.hx rename to hGameTest/src/assets/tilesets/TextureAtlas.hx index 8573f842..ce278070 100644 --- a/hGameTest/src/assets/SpriteSheet.hx +++ b/hGameTest/src/assets/tilesets/TextureAtlas.hx @@ -1,25 +1,24 @@ -package assets; +package assets.tilesets; import openfl.geom.Point; import openfl.geom.Rectangle; import openfl.display.BitmapData; import openfl.display.Bitmap; -class SpriteSheet{ - public static var spriteSheetArray:Array = []; +class TextureAtlas{ + public static var tileSetArray:Array = []; public var sprites:Array = []; + public var columns:Int; + public var rows:Int; public function new(bmp:BitmapData = null, sprWidth:Int = 16, sprHeight:Int = 16){ - spriteSheetArray.push(this); - var columns:Int = cast((bmp.width / sprWidth),Int); - var rows:Int = cast((bmp.height / sprHeight),Int); - //trace("columns:"+columns); - //trace("rows"+rows); + tileSetArray.push(this); + columns = cast((bmp.width / sprWidth),Int); + rows = cast((bmp.height / sprHeight),Int); for(i in 0...rows){ for (j in 0...columns){ var bmpd:BitmapData = new BitmapData(sprWidth, sprHeight,true,0x00000000); var rect:Rectangle = new Rectangle(j*sprWidth,i*sprHeight,sprWidth,sprHeight); bmpd.copyPixels(bmp, rect, new Point(0,0)); sprites.push(bmpd); - //trace("i:"+i+",j:"+j); } } } diff --git a/hGameTest/src/assets/tilesets/Tileset.hx b/hGameTest/src/assets/tilesets/Tileset.hx new file mode 100644 index 00000000..5bc50acf --- /dev/null +++ b/hGameTest/src/assets/tilesets/Tileset.hx @@ -0,0 +1,13 @@ +package assets.tilesets; + + +class Tileset{ + public static var tilesetMap:Map = []; + public var texName:String; + public var texAtlas:TextureAtlas; + public function new(name:String, atlas:TextureAtlas){ + texName = name; + texAtlas = atlas; + tilesetMap[name] = this; + } +} \ No newline at end of file diff --git a/hGameTest/src/assets/tilesets/TilesetGeneric.hx b/hGameTest/src/assets/tilesets/TilesetGeneric.hx index 15423347..8456c8f8 100644 --- a/hGameTest/src/assets/tilesets/TilesetGeneric.hx +++ b/hGameTest/src/assets/tilesets/TilesetGeneric.hx @@ -1,8 +1,20 @@ package assets.tilesets; +import openfl.display.BitmapData; +import assets.tilesets.TextureAtlas; -class TilesetGeneric { - +class TilesetGeneric extends Tileset{ + public var tileMap:Map = []; + public function new(name:String, atlas:TextureAtlas ,tileNames:Array){ + super(name,atlas); + for(i in 0...texAtlas.sprites.length-1){ + trace(i); + trace(tileNames[i]); + var sprites:Array = texAtlas.sprites; + tileMap[tileNames[i]] = texAtlas.sprites[i]; + } + trace(tileMap); + } } \ No newline at end of file