handloose make action arrows

This commit is contained in:
2022-01-28 11:15:25 -07:00
parent ed32957755
commit 5803b77c3e
4 changed files with 39 additions and 18 deletions

View File

@@ -5,8 +5,7 @@ import kiss.List;
import sys.io.File;
import sys.FileSystem;
import flixel.math.FlxRandom;
using haxe.io.Path;
import haxe.io.Path;
typedef ArrowStuff = {
text:String,

View File

@@ -1,30 +1,34 @@
(defNew [&prop :String path]
(type "") // If the file can't be written to, throw the error right away
// Use files with the same extension in the current working directory to determine letter frequencies
(walkDirectory (FileSystem.absolutePath "")
->file (when (= (file.extension) (path.extension))
(learnFrequencies (File.getContent file)))))
(walkDirectory "" (FileSystem.absolutePath "")
->file (when (= (Path.extension file) (Path.extension path))
(learnFrequencies ~(File.getContent ~file))
~charFrequencies)))
(prop &mut :String content "")
(method type [:String str]
(method :Void type [:String str]
(+= content str)
(File.saveContent path content))
(File.saveContent path content)
(print content))
(prop :Map<String,Map<String,Int>> charFrequencies (new Map))
(prop :Map<String,Map<String,Int>> wordFrequencies (new Map))
(method incFrequency [:Map<String,Map<String,Int>> m :String c :String following]
(unless (m.exists following) (dictSet m following (new Map)))
(let [followingMap (dictGet m following)]
(dictSet followingMap c (+ 1 (or (dictGet followingMap c) 0)))))
(when c
(unless (m.exists following) (dictSet m following (new Map)))
(let [followingMap (dictGet m following)]
(dictSet followingMap c (+ 1 (or (dictGet followingMap c) 0))))))
(method learnFrequencies [:String str]
(let [chars (str.split "")]
(incFrequency charFrequencies (first chars) "")
(doFor [following c] (pairs chars)
(incFrequency charFrequencies c following)))
// TODO learn word frequencies
)
(when chars
(incFrequency charFrequencies (first chars) "")
(doFor [following c] (pairs chars)
(incFrequency charFrequencies c following)))
// TODO learn word frequencies
))
(prop :FlxRandom r (new FlxRandom))
(method :ArrowStuff generateArrowStuff []
@@ -32,7 +36,7 @@
(let [lastChar (substr content -1)
charFreq (dictGet charFrequencies lastChar)
chars []
weights []]
:Array<Float> weights []]
(doFor =>c weight charFreq
(chars.push c)
(weights.push weight))

View File

@@ -1,5 +1,6 @@
package;
import flixel.FlxG;
import flixel.FlxGame;
import openfl.display.Sprite;
@@ -9,5 +10,8 @@ class Main extends Sprite
{
super();
addChild(new FlxGame(0, 0, TypingState, 1, 60, 60, true));
var t:TypingState = cast FlxG.state;
trace(Sys.args()[0]);
t.setModel(new DocumentModel(Sys.args()[0]));
}
}

View File

@@ -31,8 +31,6 @@
add(actionSprites);
var actionSprite = makeTriangleSprite(Right, "a", -SPRITE_SIZE, ()->{trace("a");});
actionSprite = makeTriangleSprite(Right, "a", -SPRITE_SIZE*4, ()->{trace("a");});
}|#)
(prop :Map<Int,ArrowDir> inputCodes (new Map))
@@ -74,6 +72,14 @@
(prop :FlxTypedGroup<ActionSprite> actionSprites (new FlxTypedGroup))
(prop &mut :DocumentModel _model null)
(method setModel [:DocumentModel m]
(set _model m)
(doFor i (range 100)
#|{
var stuff = m.generateArrowStuff();
makeTriangleSprite(DIR_ORDER[i % DIR_ORDER.length], stuff.text, -SPRITE_SIZE*i, stuff.action);
}|#))
(method :FlxSprite makeTriangleSprite [:ArrowDir dir :String text :Int y &opt :Void->Void action]
#|{
@@ -93,6 +99,14 @@
case Right:
90;
};
text = switch (text) {
case "\n": "<newline>";
case "\r": "<bad newline>";
case " ": "<space>";
case "\t": "<tab>";
default: text;
};
var text = new FlxText(text, TEXT_SIZE);
text.angle = -spr.angle;
text.color = FlxColor.BLACK;