From 2be5bb221bae718f0625569517178a66892ac14a Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Sat, 21 Jul 2018 23:02:51 +0200 Subject: Move arrange-text to utils module. --- scenes/game.scm | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) (limited to 'scenes') diff --git a/scenes/game.scm b/scenes/game.scm index a51fd18..4ae862d 100644 --- a/scenes/game.scm +++ b/scenes/game.scm @@ -37,6 +37,7 @@ #:use-module (characters) #:use-module (characters lorenzo) #:use-module (characters reaper) + #:use-module (utils) #:use-module (config) #:export (game)) @@ -123,28 +124,6 @@ map's object layer." #:name 'stats #:object player #:position (vec2 10.0 (- %height 10.0)))))) -(define* (arrange-text text #:key - (character-width 8.0) - (margin 0.0) - (max-width %width)) - "Take the string TEXT and split it at spaces so that it fits in the -given MAX-WIDTH. Return a list of lines." - (match (fold (lambda (chunk acc) - (match acc - ((#:width width #:result (and (current-line . tail) lines)) - (let* ((len (+ 1 (string-length chunk))) - (chunk-width (* len character-width)) - (new-width (+ chunk-width width))) - (if (< (+ new-width margin) max-width) - `(#:width ,new-width - #:result ,(cons (string-append current-line " " chunk) tail)) - `(#:width ,chunk-width - #:result ,(cons chunk lines))))))) - '(#:width 0 #:result ("")) - (string-tokenize text)) - ((#:width _ #:result lines) - (reverse lines)))) - (define* (collides? player game #:key (layer "collision")) (let* ((pos (position player)) (offset (origin game)) -- cgit v1.2.3