--- a/Source/com/watabou/switchhook/scenes/TitleScene.hx +++ b/Source/com/watabou/switchhook/scenes/TitleScene.hx @@ -78,7 +78,7 @@ } private function onVersion():Void { - Lib.getURL( new URLRequest( "https://twitter.com/watawatabou" ) ); + // Web port: the link to the author's Twitter page is gone. } private function processStars( elapsed:Float ):Void { --- a/Source/com/watabou/switchhook/sprites/ActorSprite.hx +++ b/Source/com/watabou/switchhook/sprites/ActorSprite.hx @@ -8,6 +8,7 @@ import com.watabou.switchhook.ui.MapView; import com.watabou.switchhook.utils.Updater; import openfl.Assets; +import openfl.utils.AssetType; import openfl.display.Bitmap; import openfl.geom.Point; import msignal.Signal.Signal0; --- a/Source/com/watabou/switchhook/ui/AttackArea.hx +++ b/Source/com/watabou/switchhook/ui/AttackArea.hx @@ -4,7 +4,7 @@ import com.watabou.switchhook.geography.HexMap; import openfl.Assets; import openfl.display.Shape; -import openfl.display.Tilesheet; +import com.watabou.switchhook.utils.Tilesheet; import openfl.geom.Point; class AttackArea extends Shape { --- a/Source/com/watabou/switchhook/ui/HealthIndicator.hx +++ b/Source/com/watabou/switchhook/ui/HealthIndicator.hx @@ -4,7 +4,7 @@ import com.watabou.switchhook.utils.Updater; import openfl.Assets; import openfl.display.Shape; -import openfl.display.Tilesheet; +import com.watabou.switchhook.utils.Tilesheet; import openfl.geom.Rectangle; class HealthIndicator extends View { --- a/Source/com/watabou/switchhook/ui/MapView.hx +++ b/Source/com/watabou/switchhook/ui/MapView.hx @@ -11,7 +11,7 @@ import openfl.Assets; import openfl.display.Graphics; import openfl.display.Sprite; -import openfl.display.Tilesheet; +import com.watabou.switchhook.utils.Tilesheet; import openfl.events.MouseEvent; import openfl.geom.Point; import openfl.geom.Rectangle; --- a/Source/com/watabou/switchhook/utils/Tilesheet.hx +++ b/Source/com/watabou/switchhook/utils/Tilesheet.hx @@ -0,0 +1,46 @@ +package com.watabou.switchhook.utils; + +import openfl.display.BitmapData; +import openfl.display.Graphics; +import openfl.geom.Matrix; +import openfl.geom.Point; +import openfl.geom.Rectangle; + +/** + * Web port: stand-in for openfl.display.Tilesheet, which OpenFL 9 no longer has. It keeps the parts the game used + * (addTileRect and drawTiles with x, y, tile index triples) and draws every tile as a bitmap-filled rectangle. + */ +class Tilesheet { + + private var bitmap : BitmapData; + private var rects : Array = []; + private var centers : Array = []; + + public function new( bitmap:BitmapData ) { + this.bitmap = bitmap; + } + + public function addTileRect( rect:Rectangle, ?centerPoint:Point ):Int { + rects.push( rect.clone() ); + centers.push( centerPoint != null ? centerPoint.clone() : new Point( 0, 0 ) ); + return rects.length - 1; + } + + public function drawTiles( graphics:Graphics, tileData:Array, smooth:Bool = false ):Void { + var matrix = new Matrix(); + var i = 0; + while (i + 2 < tileData.length) { + var index = Std.int( tileData[i + 2] ); + var r = rects[index]; + var c = centers[index]; + var dx = tileData[i] - c.x; + var dy = tileData[i + 1] - c.y; + matrix.tx = dx - r.x; + matrix.ty = dy - r.y; + graphics.beginBitmapFill( bitmap, matrix, false, smooth ); + graphics.drawRect( dx, dy, r.width, r.height ); + graphics.endFill(); + i += 3; + } + } +}