From 4f3f599909449f9a40ce88a1a36fb4dbc49b22b8 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Sun, 25 Apr 2021 14:55:12 -0600 Subject: [PATCH] [ascii] blitSurface basic --- kiss/src/kiss/Stream.hx | 1 - .../death-trap/assets/data/laptop.srf | 184 ++++++++++++++++++ .../death-trap/source/DeathTrapLogic.hx | 2 + .../death-trap/source/DeathTrapLogic.kiss | 9 +- .../examples/death-trap/source/PlayState.hx | 2 +- projects/asciilib2/src/asciilib/Assets.hx | 4 + projects/asciilib2/src/asciilib/Assets.kiss | 14 ++ .../asciilib2/src/asciilib/AssetsBackend.hx | 5 + projects/asciilib2/src/asciilib/Game.kiss | 9 +- projects/asciilib2/src/asciilib/GameLogic.hx | 8 +- projects/asciilib2/src/asciilib/Surface.kiss | 29 ++- .../backends/flixel/FlxAssetsBackend.hx | 7 + .../backends/flixel/FlxAssetsBackend.kiss | 3 + 13 files changed, 265 insertions(+), 12 deletions(-) create mode 100644 projects/asciilib2/examples/death-trap/assets/data/laptop.srf create mode 100644 projects/asciilib2/src/asciilib/Assets.hx create mode 100644 projects/asciilib2/src/asciilib/Assets.kiss create mode 100644 projects/asciilib2/src/asciilib/AssetsBackend.hx create mode 100644 projects/asciilib2/src/asciilib/backends/flixel/FlxAssetsBackend.hx create mode 100644 projects/asciilib2/src/asciilib/backends/flixel/FlxAssetsBackend.kiss diff --git a/kiss/src/kiss/Stream.hx b/kiss/src/kiss/Stream.hx index c28a3af9..51724935 100644 --- a/kiss/src/kiss/Stream.hx +++ b/kiss/src/kiss/Stream.hx @@ -63,7 +63,6 @@ class Stream { content = content.replace('\r', ''); } - // Life is easier with a trailing newline if (content.charAt(content.length - 1) != "\n") content += "\n"; diff --git a/projects/asciilib2/examples/death-trap/assets/data/laptop.srf b/projects/asciilib2/examples/death-trap/assets/data/laptop.srf new file mode 100644 index 00000000..f6973869 --- /dev/null +++ b/projects/asciilib2/examples/death-trap/assets/data/laptop.srf @@ -0,0 +1,184 @@ +COLORS +! 128 128 255 +" 255 255 255 +# 98 49 0 +$ 159 80 0 +% 41 41 41 +& 128 128 128 +' 106 106 106 +( 0 0 0 +INFO CODES +! . +" POINT_screen +SIZE +68 33 +CHARACTERS + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +BACKGROUND COLORS +!!!!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!!!! +!!!!%&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&%!!!! +!!!!%&''''''''''''''''''''''''''''''''''''''''''''''''''''''''&%!!!! +!!!!%&'(((((((((((((((((((((((((((((((((((((((((((((((((((((('&%!!!! +!!!!%&'(((((((((((((((((((((((((((((((((((((((((((((((((((((('&%!!!! +!!!!%&'(((((((((((((((((((((((((((((((((((((((((((((((((((((('&%!!!! +!!!!%&'(((((((((((((((((((((((((((((((((((((((((((((((((((((('&%!!!! +!!!!%&'(((((((((((((((((((((((((((((((((((((((((((((((((((((('&%!!!! +!!!!%&'(((((((((((((((((((((((((((((((((((((((((((((((((((((('&%!!!! +!!!!%&'(((((((((((((((((((((((((((((((((((((((((((((((((((((('&%!!!! +!!!!%&'(((((((((((((((((((((((((((((((((((((((((((((((((((((('&%!!!! +!!!!%&'(((((((((((((((((((((((((((((((((((((((((((((((((((((('&%!!!! +!!!!%&'(((((((((((((((((((((((((((((((((((((((((((((((((((((('&%!!!! +!!!!%&'(((((((((((((((((((((((((((((((((((((((((((((((((((((('&%!!!! +!!!!%&'(((((((((((((((((((((((((((((((((((((((((((((((((((((('&%!!!! +!!!!%&'(((((((((((((((((((((((((((((((((((((((((((((((((((((('&%!!!! +!!!!%&'(((((((((((((((((((((((((((((((((((((((((((((((((((((('&%!!!! +!!!!%&'(((((((((((((((((((((((((((((((((((((((((((((((((((((('&%!!!! +!!!!%&'(((((((((((((((((((((((((((((((((((((((((((((((((((((('&%!!!! +!!!!%&'(((((((((((((((((((((((((((((((((((((((((((((((((((((('&%!!!! +!!!!%&'(((((((((((((((((((((((((((((((((((((((((((((((((((((('&%!!!! +!!!!%&'(((((((((((((((((((((((((((((((((((((((((((((((((((((('&%!!!! +!!!!%&''''''''''''''''''''''''''''''''''''''''''''''''''''''''&%!!!! +!!!!%&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&%!!!! +!!!!%''''''''''''''''''''''''''''''''''''''''''''''''''''''''''%!!!! +!!!%&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&%!!! +!!!%&&''''''''''''''''''''''''''''''''''''''''''''''''''''''''&&%!!! +!!%&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&%!! +!!%&&''''''''''''''''''''''''''''''''''''''''''''''''''''''''''&&%!! +!%&&'&&&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&%! +!%&&''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''&&%! +%&&'&&&&&'&&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&'&&&&&'&&% +%&&''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''&&% +CHARACTER COLORS +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +OPACITY +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00001111111111111111111111111111111111111111111111111111111111110000 +00011111111111111111111111111111111111111111111111111111111111111000 +00011111111111111111111111111111111111111111111111111111111111111000 +00111111111111111111111111111111111111111111111111111111111111111100 +00111111111111111111111111111111111111111111111111111111111111111100 +01111111111111111111111111111111111111111111111111111111111111111110 +01111111111111111111111111111111111111111111111111111111111111111110 +11111111111111111111111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111111111111111111111 +SPECIAL INFO +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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projects/asciilib2/examples/death-trap/source/DeathTrapLogic.hx index cb139ebd..742e35e8 100644 --- a/projects/asciilib2/examples/death-trap/source/DeathTrapLogic.hx +++ b/projects/asciilib2/examples/death-trap/source/DeathTrapLogic.hx @@ -3,6 +3,8 @@ package; import asciilib.GameLogic; import asciilib.Graphics; import asciilib.Colors; +import asciilib.Assets; +import asciilib.Game; import kiss.Prelude; @:build(kiss.Kiss.build()) diff --git a/projects/asciilib2/examples/death-trap/source/DeathTrapLogic.kiss b/projects/asciilib2/examples/death-trap/source/DeathTrapLogic.kiss index 95ae2311..bfa6f8c9 100644 --- a/projects/asciilib2/examples/death-trap/source/DeathTrapLogic.kiss +++ b/projects/asciilib2/examples/death-trap/source/DeathTrapLogic.kiss @@ -2,9 +2,10 @@ (defmethod new [] 0) -(defmethod :Void update [:Float deltaSeconds] 0) -(defmethod :Void draw [:Void->Graphics graphics] +(defmethod :Void initialize [:Assets assets] + (assets.loadSurface "laptop" AssetPaths.laptop__srf)) +(defmethod :Void update [:Game game :Float deltaSeconds] 0) +(defmethod :Void draw [:Void->Graphics graphics :Assets assets] (when firstDraw (set firstDraw false) - (.setBackgroundColor (graphics) 5 5 Colors.White) - (.setLetter (graphics) 10 5 (object char "@" color Colors.Red)))) \ No newline at end of file + (.blitSurface (graphics) (assets.getSurface "laptop") 0 0))) \ No newline at end of file diff --git a/projects/asciilib2/examples/death-trap/source/PlayState.hx b/projects/asciilib2/examples/death-trap/source/PlayState.hx index acc0f7cb..8f8ba471 100644 --- a/projects/asciilib2/examples/death-trap/source/PlayState.hx +++ b/projects/asciilib2/examples/death-trap/source/PlayState.hx @@ -12,7 +12,7 @@ class PlayState extends FlxState override public function create() { super.create(); - game = new Game("Beware Yon Death Trap", 40, 24, 8, 12, new DeathTrapLogic(), + game = new Game("Beware Yon Death Trap", 40, 24, 8, 12, new DeathTrapLogic(), new FlxAssetsBackend(), new FlxGraphicsBackend(this, FlxGraphic.fromAssetKey("assets/images/size12.png"), "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,.;:/?!@#$%^&*()-_=+[]{}~ÁÉÍÑÓÚÜáéíñóúü¡¿0123456789\"'<>|")); } diff --git a/projects/asciilib2/src/asciilib/Assets.hx b/projects/asciilib2/src/asciilib/Assets.hx new file mode 100644 index 00000000..daae5757 --- /dev/null +++ b/projects/asciilib2/src/asciilib/Assets.hx @@ -0,0 +1,4 @@ +package asciilib; + +@:build(kiss.Kiss.build()) +class Assets {} diff --git a/projects/asciilib2/src/asciilib/Assets.kiss b/projects/asciilib2/src/asciilib/Assets.kiss new file mode 100644 index 00000000..b9f20018 --- /dev/null +++ b/projects/asciilib2/src/asciilib/Assets.kiss @@ -0,0 +1,14 @@ +(defnew [assetsBackend] + // TODO use &prop for this + [:AssetsBackend backend assetsBackend + :Map _surfaces (new Map)]) + +// TODO don't allow overriding a key -- use a macro so all load___() calls check their maps first +(defmethod loadSurface [key path] + (dictSet _surfaces key (Surface.fromString (backend.loadText path)))) + +// TODO runtime-assert that the key exists. Use a macro so all get___() calls check their maps first +(defmethod getSurface [key] + (dictGet _surfaces key)) + +// TODO freeSurface() etc. \ No newline at end of file diff --git a/projects/asciilib2/src/asciilib/AssetsBackend.hx b/projects/asciilib2/src/asciilib/AssetsBackend.hx new file mode 100644 index 00000000..9b307ea0 --- /dev/null +++ b/projects/asciilib2/src/asciilib/AssetsBackend.hx @@ -0,0 +1,5 @@ +package asciilib; + +interface AssetsBackend { + function loadText(filePath:String):String; +} diff --git a/projects/asciilib2/src/asciilib/Game.kiss b/projects/asciilib2/src/asciilib/Game.kiss index aaa203c8..fcd15df4 100644 --- a/projects/asciilib2/src/asciilib/Game.kiss +++ b/projects/asciilib2/src/asciilib/Game.kiss @@ -4,19 +4,22 @@ letterWidth letterHeight _gameLogic + assetsBackend _graphicsBackend] // TODO the type annotation on this line feels like a bit much, but is necessary: [:Graphics graphics (new Graphics width height) :GameLogic gameLogic _gameLogic + :Assets assets (new Assets assetsBackend) :GraphicsBackend graphicsBackend _graphicsBackend] - (graphicsBackend.initialize title width height letterWidth letterHeight)) + (graphicsBackend.initialize title width height letterWidth letterHeight) + (gameLogic.initialize assets)) (defmethod update [:Float deltaSeconds] - (gameLogic.update deltaSeconds)) + (gameLogic.update this deltaSeconds)) (defmethod draw [] (let [&mut changedGraphics false] - (gameLogic.draw (lambda [] (set changedGraphics true) graphics)) + (gameLogic.draw (lambda [] (set changedGraphics true) graphics) assets) (when changedGraphics (graphicsBackend.draw graphics)))) \ No newline at end of file diff --git a/projects/asciilib2/src/asciilib/GameLogic.hx b/projects/asciilib2/src/asciilib/GameLogic.hx index 9c0df81b..49fae48a 100644 --- a/projects/asciilib2/src/asciilib/GameLogic.hx +++ b/projects/asciilib2/src/asciilib/GameLogic.hx @@ -1,6 +1,10 @@ package asciilib; +// Your game's logic is an interface contained in Game instead of a class that extends Game. +// This allows ASCIILib to support libraries like HaxeFlixel where your main class is expected +// to extend another class already. interface GameLogic { - public function update(deltaSeconds:Float):Void; - public function draw(graphicsHandle:() -> Graphics):Void; + public function initialize(assets:Assets):Void; + public function update(game:Game, deltaSeconds:Float):Void; + public function draw(graphicsHandle:() -> Graphics, assets:Assets):Void; } diff --git a/projects/asciilib2/src/asciilib/Surface.kiss b/projects/asciilib2/src/asciilib/Surface.kiss index ee4fc6ba..0d1aed63 100644 --- a/projects/asciilib2/src/asciilib/Surface.kiss +++ b/projects/asciilib2/src/asciilib/Surface.kiss @@ -20,6 +20,32 @@ (letters.setChar x y letter.char) (letterColors.setPixel x y letter.color)) +(defmethod isCellOpaque [x y] + (opacity.getCell x y)) + +(defmethod setCellOpacity [x y value] + (opacity.setCell x y value)) + +(defmethod getSpecialInfo [x y] + (specialInfo.getCell x y)) + +(defmethod setSpecialInfo [x y value] + (specialInfo.setCell x y value)) + +// TODO rectangle type +// TODO optional source rectangle argument +(defmethod blitSurface [:Surface surface x y] + (doFor [srcX destX] (zip (collect (range 0 surface.width)) (collect (range x (+ x surface.width)))) + (when (< -1 destX width) + (doFor [srcY destY] (zip (collect (range 0 surface.height)) (collect (range y (+ y surface.height)))) + (when (< -1 destY height) + (when (surface.isCellOpaque srcX srcY) + (setBackgroundColor destX destY (surface.getBackgroundColor srcX srcY)) + (setLetter destX destY (surface.getLetter srcX srcY)) + (setSpecialInfo destX destY (surface.getSpecialInfo srcX srcY)) + // Cover transparent cells in the lower surface with opaque ones + (setCellOpacity destX destY true))))))) + (defun fromString [text] (let [stream (Stream.fromString text) :Map colors (new Map) @@ -67,4 +93,5 @@ (stream.dropString "SPECIAL INFO\n") (doFor y (range height) (doFor x (range width) - (surface.specialInfo.setCell x y (dictGet infoCodes (stream.expect "a special info code" ->{(stream.takeChars 1)})))))))))) \ No newline at end of file + (surface.specialInfo.setCell x y (dictGet infoCodes (stream.expect "a special info code" ->{(stream.takeChars 1)}))))) + surface))))) \ No newline at end of file diff --git a/projects/asciilib2/src/asciilib/backends/flixel/FlxAssetsBackend.hx b/projects/asciilib2/src/asciilib/backends/flixel/FlxAssetsBackend.hx new file mode 100644 index 00000000..053c6695 --- /dev/null +++ b/projects/asciilib2/src/asciilib/backends/flixel/FlxAssetsBackend.hx @@ -0,0 +1,7 @@ +package asciilib.backends.flixel; + +import asciilib.AssetsBackend; +import openfl.Assets; + +@:build(kiss.Kiss.build()) +class FlxAssetsBackend implements AssetsBackend {} diff --git a/projects/asciilib2/src/asciilib/backends/flixel/FlxAssetsBackend.kiss b/projects/asciilib2/src/asciilib/backends/flixel/FlxAssetsBackend.kiss new file mode 100644 index 00000000..b7e9a529 --- /dev/null +++ b/projects/asciilib2/src/asciilib/backends/flixel/FlxAssetsBackend.kiss @@ -0,0 +1,3 @@ +(defmethod new [] 0) + +(defmethod loadText [filePath] (Assets.getText filePath)) \ No newline at end of file