Use int-based colors for tag-color systems in NAT. Close #167
This commit is contained in:
1
.DocumentModel.json
Normal file
1
.DocumentModel.json
Normal file
@@ -0,0 +1 @@
|
||||
{"wordFrequencies":"[]","charFrequencies":"[[\" \",[[\"A\",7],[\"a\",8],[\"B\",2],[\"b\",1],[\"\\\"\",2],[\"C\",4],[\"c\",6],[\"D\",2],[\"d\",4],[\"E\",2],[\"F\",3],[\"f\",3],[\"g\",1],[\"H\",1],[\"(\",3],[\"h\",1],[\"I\",7],[\"i\",5],[\"K\",1],[\"l\",1],[\"L\",3],[\"m\",2],[\"M\",2],[\"N\",3],[\"n\",2],[\"O\",14],[\"o\",5],[\"p\",6],[\"P\",3],[\"2\",1],[\"r\",2],[\"s\",7],[\"S\",8],[\"T\",7],[\"t\",14],[\"U\",2],[\"u\",1],[\"w\",3],[\"W\",5]]],[\"\",[[\"L\",1]]],[\"A\",[[\" \",1],[\"I\",1],[\"R\",8],[\"B\",3],[\"C\",2],[\"S\",1],[\"L\",2],[\"M\",1],[\"U\",1],[\"N\",7],[\"G\",1]]],[\"a\",[[\"l\",4],[\"t\",3],[\" \",1],[\"i\",1],[\"b\",1],[\"n\",7],[\"r\",7],[\"s\",2]]],[\"B\",[[\"L\",1],[\"E\",1],[\"I\",2],[\"U\",1]]],[\"\\\"\",[[\",\",1],[\"A\",1],[\")\",1],[\"S\",1]]],[\"b\",[[\"l\",2],[\"t\",1],[\"e\",1],[\"u\",1],[\"y\",1],[\"j\",1],[\"s\",1],[\"o\",1]]],[\"C\",[[\"T\",3],[\"H\",1],[\"L\",2],[\"U\",1],[\"O\",3],[\"o\",1]]],[\"c\",[[\"l\",2],[\"t\",2],[\"h\",1],[\"u\",1],[\"i\",1],[\")\",1],[\"e\",5],[\"o\",6]]],[\"D\",[[\",\",2],[\" \",3],[\"A\",1],[\"I\",1],[\"E\",3]]],[\"d\",[[\" \",6],[\",\",1],[\"i\",4],[\"e\",2],[\"/\",1],[\"o\",2]]],[\"E\",[[\"X\",1],[\" \",11],[\"A\",1],[\"\\n\",1],[\"R\",6],[\"C\",1],[\"S\",4],[\",\",1],[\"T\",1],[\"D\",3],[\"M\",1],[\".\",1],[\"N\",2],[\"V\",1]]],[\"e\",[[\" \",18],[\"a\",1],[\"\\\"\",1],[\"b\",1],[\"\\n\",1],[\"r\",8],[\"c\",1],[\"s\",4],[\"l\",1],[\"d\",4],[\",\",6],[\"e\",1],[\".\",1],[\"n\",4]]],[\"F\",[[\" \",4],[\"T\",3],[\"I\",1],[\"R\",2],[\"O\",2]]],[\"f\",[[\"t\",6],[\" \",4],[\"u\",1],[\"y\",1],[\"i\",1],[\"r\",1],[\"o\",1]]],[\"G\",[[\"H\",1],[\" \",2],[\"S\",1],[\"E\",2]]],[\"g\",[[\" \",3],[\"r\",1],[\"h\",3],[\"e\",2]]],[\"H\",[[\" \",1],[\"T\",1],[\"A\",2],[\"E\",11],[\"O\",3]]],[\"h\",[[\",\",1],[\"t\",3],[\"i\",2],[\"a\",2],[\"e\",11],[\"o\",4]]],[\"(\",[[\"t\",1],[\"c\",1],[\"M\",1]]],[\"i\",[[\"a\",2],[\"b\",1],[\"c\",6],[\"s\",9],[\"l\",1],[\"t\",5],[\"e\",2],[\"m\",1],[\"f\",1],[\"n\",8],[\"o\",7],[\"g\",3]]],[\"I\",[[\"A\",2],[\"C\",1],[\"S\",4],[\"T\",8],[\"D\",1],[\"L\",2],[\"M\",3],[\"E\",2],[\"N\",11],[\"O\",2],[\"G\",1]]],[\")\",[[\",\",1],[\" \",1],[\"\\n\",1]]],[\"j\",[[\"e\",1]]],[\"\\n\",[[\"P\",1],[\"A\",1],[\"I\",1],[\"a\",1],[\"i\",1],[\"\\n\",5],[\"c\",1],[\"C\",1],[\"L\",1],[\"T\",4],[\"t\",1],[\"=\",1],[\"F\",1],[\"f\",1],[\"O\",1],[\"o\",1]]],[\"K\",[[\"I\",1]]],[\"l\",[[\" \",3],[\"l\",4],[\"i\",3],[\"u\",2],[\"e\",1],[\"\\n\",2],[\"o\",1]]],[\",\",[[\"\\n\",2],[\" \",20]]],[\"L\",[[\"D\",1],[\" \",1],[\"L\",1],[\"E\",1],[\"A\",2],[\"U\",1],[\"I\",7],[\"i\",2]]],[\"m\",[[\" \",1],[\"e\",2],[\"i\",4],[\"a\",1],[\"o\",1]]],[\"M\",[[\",\",2],[\"P\",1],[\"A\",1],[\"E\",2],[\"I\",3]]],[\"N\",[[\" \",6],[\"I\",1],[\"Y\",2],[\"\\n\",1],[\"C\",1],[\"T\",6],[\"D\",2],[\"E\",2],[\"N\",1],[\"F\",1],[\"G\",4],[\"O\",3]]],[\".\",[[\" \",1],[\"\\n\",1]]],[\"n\",[[\" \",6],[\"i\",2],[\"y\",1],[\"\\n\",1],[\"c\",2],[\"s\",6],[\"t\",3],[\"d\",5],[\",\",1],[\"o\",2],[\"g\",3]]],[\"O\",[[\"P\",1],[\" \",2],[\"R\",11],[\"S\",1],[\"L\",1],[\"T\",4],[\"M\",1],[\"U\",2],[\"V\",1],[\"F\",7],[\"N\",5]]],[\"/\",[[\"o\",1]]],[\"o\",[[\" \",8],[\"p\",6],[\"r\",3],[\"b\",1],[\"c\",2],[\"t\",2],[\"l\",1],[\",\",1],[\"d\",1],[\"m\",2],[\"u\",2],[\"v\",1],[\"f\",10],[\"n\",10],[\"w\",1]]],[\"p\",[[\"i\",2],[\"u\",1],[\"e\",4],[\"y\",4],[\"o\",1]]],[\"0\",[[\"1\",1]]],[\"P\",[[\"L\",1],[\"Y\",1],[\"U\",1],[\"A\",1],[\"e\",1],[\"R\",2],[\"O\",1]]],[\"1\",[[\"5\",1]]],[\"R\",[[\"P\",1],[\" \",11],[\"I\",3],[\"A\",3],[\"\\n\",2],[\"R\",2],[\"S\",2],[\"C\",1],[\"T\",2],[\"E\",4],[\"W\",1],[\"O\",2]]],[\"r\",[[\" \",2],[\"a\",1],[\"i\",5],[\"\\n\",1],[\"s\",2],[\"t\",1],[\"m\",3],[\"e\",9],[\"n\",1],[\"g\",2]]],[\"2\",[[\"0\",1]]],[\"S\",[[\"H\",1],[\" \",9],[\"I\",1],[\"E\",3],[\"\\\"\",1],[\"S\",2],[\"o\",5],[\"O\",3]]],[\"s\",[[\"h\",3],[\" \",9],[\"i\",2],[\":\",1],[\"\\n\",2],[\"s\",3],[\"t\",4],[\"u\",3],[\"e\",5],[\"o\",5]]],[\"T\",[[\"H\",13],[\" \",8],[\"h\",3],[\"A\",1],[\"I\",4],[\"Y\",3],[\")\",1],[\"R\",1],[\",\",1],[\"E\",1],[\".\",1],[\"N\",1],[\"W\",3],[\"O\",2]]],[\"t\",[[\"h\",11],[\" \",6],[\"i\",8],[\"a\",4],[\"r\",2],[\"s\",1],[\"e\",4],[\"o\",7],[\"w\",6]]],[\"u\",[[\"d\",2],[\"t\",3],[\"m\",1],[\"r\",1],[\"b\",4],[\"s\",1]]],[\"5\",[[\" \",1]]],[\"U\",[[\"L\",1],[\"D\",1],[\"T\",4],[\"R\",1],[\"S\",1],[\"s\",1]]],[\"V\",[[\"E\",1],[\"I\",1]]],[\"v\",[[\"e\",1]]],[\"W\",[[\"H\",1],[\"I\",3],[\"A\",5]]],[\"w\",[[\"h\",1],[\"i\",3],[\"a\",6]]],[\"X\",[[\"P\",1]]],[\"Y\",[[\"R\",1],[\",\",2],[\" \",3]]],[\"y\",[[\",\",2],[\"\\n\",1],[\" \",2],[\"r\",2]]],[\":\",[[\"\\n\",1]]],[\"=\",[[\"\\n\",1],[\"=\",6]]]]","filesLearnedFrom":"[[\"README.md\",true]]"}
|
@@ -182,7 +182,8 @@
|
||||
// Preserve the capitalization of the command name for pretty help message
|
||||
(commandNames.push ,(symbolName name))
|
||||
// Store the command name without capitalization for forgiving call conventions
|
||||
(dictSet commands ,(ReaderExp.StrExp (.toLowerCase (symbolNameValue name))) (object args [,@commandArgs] handler (the Function ,name)))}))
|
||||
(dictSet commands ,(ReaderExp.StrExp (.toLowerCase (symbolNameValue name))) (object args [,@commandArgs] handler (the Function ,name)))
|
||||
}))
|
||||
|
||||
(var :Array<String> commandNames [])
|
||||
|
||||
@@ -211,25 +212,25 @@
|
||||
(archive.addSystem (new KeyShortcutSystem this))
|
||||
(archive.addSystem (new DLSystem))
|
||||
(archive.addSystem (new AutoStepperSystem))
|
||||
(archive.addSystem (new ColorSystem))
|
||||
|
||||
// TODO this needs to use epsilon!
|
||||
(localFunction colorEqual [:nat.components.Color c1 :nat.components.Color c2]
|
||||
(localFunction colorEqual [:nat.components.ColorI c1 :nat.components.ColorI c2]
|
||||
(and (= c1.r c2.r) (= c1.g c2.g) (= c1.b c2.b) (= c1.a c2.a)))
|
||||
(localFunction colorsContain [:Array<nat.components.Color> cs :nat.components.Color c1]
|
||||
(localFunction colorsContain [:Array<nat.components.ColorI> cs :nat.components.ColorI c1]
|
||||
(doFor c2 cs
|
||||
(when (colorEqual c2 c1)
|
||||
(return true)))
|
||||
(return false))
|
||||
(localFunction addColorTagSystems [:Map<String,nat.components.Color> info]
|
||||
(localFunction addColorTagSystems [:Map<String,nat.components.ColorI> info]
|
||||
(let [colors (collect (info.iterator))]
|
||||
(doFor =>tagExp color info
|
||||
(archive.addSystem (new TagSystem tagExp ->[archive e &opt ui]
|
||||
(when (or !(hasComponent e Color) (colorsContain colors (readComponent e Color)))
|
||||
(addComponent archive e Color color)))))))
|
||||
(when (or !(hasComponent e ColorI) (colorsContain colors (readComponent e ColorI)))
|
||||
(AddColorIRGBA [e] color.r color.g color.b color.a)))))))
|
||||
(addColorTagSystems [
|
||||
=>"(or active enabled)" (object r 0 g 1 b 0 a 1)
|
||||
=>"(or inactive disabled)" (object r 0.5 g 0.5 b 0.5 a 1)
|
||||
=>"todo" (object r 1 g 0.5 b 0 a 1)])
|
||||
=>"(or active enabled)" (object r 0 g 255 b 0 a 255)
|
||||
=>"(or inactive disabled)" (object r 128 g 128 b 128 a 255)
|
||||
=>"todo" (object r 255 g 128 b 0 a 255)])
|
||||
|
||||
(whenLet [ps (ui.playgroundSystem)]
|
||||
(set playgroundSystem ps)
|
||||
@@ -397,7 +398,11 @@
|
||||
(for e entries
|
||||
(addConnections archive e entriesToRemove)))
|
||||
|
||||
(defCommand AddColorRGBA [entries (SelectedEntries 1 null) r (Number 0 1 null) g (Number 0 1 null) b (Number 0 1 null) a (Number 0 1 null)]
|
||||
(defCommand AddColorFRGBA [entries (SelectedEntries 1 null) r (Number 0 1 null) g (Number 0 1 null) b (Number 0 1 null) a (Number 0 1 null)]
|
||||
(for e entries
|
||||
(addColorRGBA archive e r g b a)))
|
||||
(addColorFRGBA archive e r g b a)))
|
||||
|
||||
(defCommand AddColorIRGBA [entries (SelectedEntries 1 null) r (Number 0 255 1) g (Number 0 255 1) b (Number 0 255 1) a (Number 0 255 1)]
|
||||
(for e entries
|
||||
(addColorIRGBA archive e (Std.int r) (Std.int g) (Std.int b) (Std.int a))))
|
||||
)
|
||||
|
@@ -149,8 +149,21 @@
|
||||
(doFor e2 entriesToRemove (conn.remove e2.id))))
|
||||
e)
|
||||
|
||||
(function addColorRGBA [:nat.Archive archive :nat.Entry e :Float r :Float g :Float b :Float a]
|
||||
(addComponent archive e Color (objectWith r g b a)))
|
||||
(function colorIFromF [:nat.components.ColorF cf]
|
||||
(object r (Std.int (* 255 cf.r)) g (Std.int (* 255 cf.g)) b (Std.int (* 255 cf.b)) a (Std.int (* 255 cf.a))))
|
||||
|
||||
(function colorFFromI [:nat.components.ColorI ci]
|
||||
(object r (/ ci.r 255.0) g (/ ci.g 255.0) b (/ ci.b 255.0) a (/ ci.a 255)))
|
||||
|
||||
(function addColorFRGBA [:nat.Archive archive :nat.Entry e :Float r :Float g :Float b :Float a]
|
||||
(let [cf (objectWith r g b a)]
|
||||
(addComponent archive e ColorF cf)
|
||||
(addComponent archive e ColorI (colorIFromF cf))))
|
||||
|
||||
(function addColorIRGBA [:nat.Archive archive :nat.Entry e :Int r :Int g :Int b :Int a]
|
||||
(let [ci (objectWith r g b a)]
|
||||
(addComponent archive e ColorI ci)
|
||||
(addComponent archive e ColorF (colorFFromI ci))))
|
||||
|
||||
(function isEntry [o]
|
||||
(let [fields (Reflect.fields o)]
|
||||
|
8
projects/nat-archive-tool/src/nat/components/ColorF.hx
Normal file
8
projects/nat-archive-tool/src/nat/components/ColorF.hx
Normal file
@@ -0,0 +1,8 @@
|
||||
package nat.components;
|
||||
|
||||
typedef ColorF = {
|
||||
r:Float,
|
||||
g:Float,
|
||||
b:Float,
|
||||
a:Float
|
||||
};
|
8
projects/nat-archive-tool/src/nat/components/ColorI.hx
Normal file
8
projects/nat-archive-tool/src/nat/components/ColorI.hx
Normal file
@@ -0,0 +1,8 @@
|
||||
package nat.components;
|
||||
|
||||
typedef ColorI = {
|
||||
r:Int,
|
||||
g:Int,
|
||||
b:Int,
|
||||
a:Int
|
||||
};
|
8
projects/nat-archive-tool/src/nat/systems/ColorSystem.hx
Normal file
8
projects/nat-archive-tool/src/nat/systems/ColorSystem.hx
Normal file
@@ -0,0 +1,8 @@
|
||||
package nat.systems;
|
||||
|
||||
import kiss.Prelude;
|
||||
import kiss.List;
|
||||
import nat.System;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class ColorSystem extends System {}
|
14
projects/nat-archive-tool/src/nat/systems/ColorSystem.kiss
Normal file
14
projects/nat-archive-tool/src/nat/systems/ColorSystem.kiss
Normal file
@@ -0,0 +1,14 @@
|
||||
(load "../Lib.kiss")
|
||||
|
||||
// Converts outdated Color component into a ColorF component and a ColorI component
|
||||
|
||||
(defNew []
|
||||
(super
|
||||
->[archive e]
|
||||
(hasComponent e Color)
|
||||
->[archive e &opt ui]
|
||||
(let [c (readComponent e Color)]
|
||||
(addComponent archive e ColorF c)
|
||||
(addComponent archive e ColorI (colorIFromF c))
|
||||
(removeComponent archive e Color))))
|
||||
|
@@ -5,7 +5,7 @@
|
||||
(method :String getPlaygroundKey [] _playgroundKey)
|
||||
|
||||
(prop :Map<String,TagList> playgroundDefaultTags (new Map))
|
||||
(prop :Map<String,Color> playgroundBGColors (new Map))
|
||||
(prop :Map<String,ColorF> playgroundBGColors (new Map))
|
||||
|
||||
(defNew [&prop :ArchiveUI ui
|
||||
:EntryChecker canProcess
|
||||
@@ -25,7 +25,7 @@
|
||||
(if (hasComponent e CatsMatchExp)
|
||||
(archive.changePlaygrounds ->:Void [:DynamicAccess<Dynamic> p] (set .catsMatch (dictGet p name) (readComponent e CatsMatchExp)))
|
||||
(addComponent archive e CatsMatchExp .catsMatch (dictGet archive.playgrounds name)))
|
||||
(dictSet playgroundBGColors name (readComponentOr e Color (object r 0.0 g 0.0 b 0.0 a 1.0)))
|
||||
(dictSet playgroundBGColors name (readComponentOr e ColorF (object r 0.0 g 0.0 b 0.0 a 1.0)))
|
||||
(dictSet playgroundDefaultTags name (readComponentOr e TagList []))))
|
||||
|
||||
// Process Entries belonging to the current playground
|
||||
@@ -52,7 +52,7 @@
|
||||
})
|
||||
(process ui.controller.archive ui))
|
||||
|
||||
(method :Void clear [:Color color]
|
||||
(method :Void clear [:ColorF color]
|
||||
(throw "(PlaygroundSystem.clear <color>) not implemented"))
|
||||
|
||||
(prop &mut :Bool setupProcess false)
|
||||
|
@@ -36,8 +36,8 @@
|
||||
(FlxSpriteUtil.drawCircle this -1 -1 c.radius FlxColor.TRANSPARENT (object thickness CIRCLE_THICKNESS color color))))
|
||||
(true
|
||||
(set pixels .pixels
|
||||
(let [color (if (hasComponent e Color)
|
||||
(let [c (readComponent e Color)]
|
||||
(let [color (if (hasComponent e ColorF)
|
||||
(let [c (readComponent e ColorF)]
|
||||
(FlxColor.fromRGBFloat c.r c.g c.b c.a))
|
||||
DEFAULT_COLOR)
|
||||
t (new FlxText 0 0 0 (readComponent e Name) PlayState.TEXT_SIZE)]
|
||||
|
@@ -39,7 +39,7 @@
|
||||
(sprites.remove e.id))
|
||||
}))
|
||||
|
||||
(method &override :Void clear [:Color color]
|
||||
(method &override :Void clear [:ColorF color]
|
||||
(set playState.bgColor (FlxColor.fromRGBFloat color.r color.g color.b color.a))
|
||||
(playState.debugLayer.clear)
|
||||
(sprites.clear)
|
||||
|
Reference in New Issue
Block a user