move standalone projects into own directory

This commit is contained in:
2023-04-27 11:39:41 -06:00
parent 5d593e22b0
commit acda704057
369 changed files with 1170 additions and 5 deletions

View File

@@ -0,0 +1,26 @@
package;
class EntryPanel extends PanelContainer {
public var z:Single = 0;
public var e:Entry = null;
var parent:PlaygroundEntries = null;
public override function _Ready() {
parent = cast(getParent());
}
public function _on_EntryPanel_mouse_entered() {
var currentFocusZ = parent.currentFocusZ;
if (Mathf.isNaN(currentFocusZ) || currentFocusZ <= this.z) {
parent.currentFocus = this;
parent.currentFocusZ = this.z;
}
}
public function _on_EntryPanel_mouse_exited() {
if (parent.currentFocus == this) {
parent.currentFocus = null;
parent.currentFocusZ = Mathf.NA_N;
}
}
}

View File

@@ -0,0 +1,6 @@
package;
import kiss.Prelude;
@:build(kiss.Kiss.build())
class EntryPanelSystem extends PlaygroundSystem<PanelContainer> {}

View File

@@ -0,0 +1,45 @@
(loadFrom "nat-archive-tool" "src/nat/Lib.kiss")
(loadFrom "kiss-godot" "src/kiss_godot/Util.kiss")
(defNew [&prop :GodotUI godotUI
&prop :RootNode rootNode]
(super
"Godot EntryPanelSystem"
godotUI
->[archive e] (hasComponent e Name)
// Create Entry node:
->[archive e pos &opt ui]
(let [:PackedScene ePanelScene (GD.load "res://EntryPanel.tscn")
:EntryPanel ePanel (cast (ePanelScene.instance))
:Label eLabel (getNode ePanel "EntryLabel")]
(set eLabel.text (readComponentOr e Name ""))
(set ePanel.rectPosition (new Vector2 pos.x pos.y))
(set ePanel.z pos.z)
(set ePanel.e e)
(pgEntries.addChild ePanel)
ePanel)
// Draw line:
->[archive e pos e2 pos2 &opt ui]
null
// Remove Entry node:
->[archive e &opt ui]
null))
(prop &mut :TabContainer pgTabs null)
(prop &mut :ScrollContainer pgScrollContainer null)
(prop &mut :Node pgEntries null)
(method &override :Void switchPlaygroundKey [:String key]
(set pgTabs rootNode.pgTabs)
(unless (= .name (pgTabs.getChild pgTabs.currentTab) key)
(doFor [idx :Control tab] (enumerate (collect (pgTabs.getChildren)) -1)
(when (and tab (= tab.name key))
(set pgTabs.currentTab idx))))
(set pgScrollContainer (getNode pgTabs key))
(set pgEntries (getNode pgScrollContainer "Entries"))
(super.switchPlaygroundKey key))
(method &override :Void clear [:ColorF color]
null)

View File

@@ -0,0 +1,8 @@
package;
import kiss.Prelude;
import kiss_tools.KeyShortcutHandler;
import cs.NativeArray;
@:build(kiss.Kiss.build())
class GodotUI implements ArchiveUI {}

View File

@@ -0,0 +1,89 @@
(loadFrom "kiss-godot" "src/kiss_godot/Util.kiss")
(prop &mut :ArchiveController controller (property default default))
(prop &mut :Null<KeyShortcutHandler<Entry>> shortcutHandler (property default null))
(method :Void showPrefixMap [:Map<String,String> map] (throw "TODO Not implemented!"))
(method :Void hidePrefixMap [] (throw "TODO Not implemented!"))
(method :Null<PlaygroundSystem<Dynamic>> playgroundSystem [] pgSystem)
(method :Void enterText [:String prompt :String->Void resolve :Float maxLength]
(displayMessage prompt)
(let [lineEdit (new LineEdit)]
(unless (= maxLength Math.POSITIVE_INFINITY)
(set lineEdit.maxLength (Std.int maxLength)))
(set rootNode.resolveString
->[:String text] {
(rootNode.uiContainer.removeChild lineEdit)
(displayMessage text)
(resolve text)
})
(lineEdit.connect "text_entered" rootNode "_on_LineEdit_text_entered")
(rootNode.uiContainer.addChild lineEdit)
(lineEdit.grabFocus)))
(method :Void enterNumber [:String prompt :Float->Void resolve :Float min :Float max &opt :Null<Float> inStepsOf &opt :Null<Bool> allowNaN]
(displayMessage prompt)
(let [spinBox (new SpinBox)
nanButton (new Button)
submitButton (new Button)
resolve
->[:Float num]
{
(set rootNode.resolveFloat null)
(rootNode.uiContainer.removeChild spinBox)
(when allowNaN (rootNode.uiContainer.removeChild nanButton))
(rootNode.uiContainer.removeChild submitButton)
(displayMessage "$num")
(resolve num)
}]
(set rootNode.resolveFloat resolve)
(set spinBox.minValue min)
(set spinBox.maxValue max)
(rootNode.uiContainer.addChild spinBox)
(when allowNaN
(set nanButton.text "NaN")
(nanButton.connect "pressed" rootNode "_on_NaNButton_pressed")
(rootNode.uiContainer.addChild nanButton))
(set submitButton.text "Submit")
(submitButton.connect "pressed" rootNode "_on_SubmitNumberButton_pressed" (new godot.collections.Array (NativeArray.make spinBox)))
(rootNode.uiContainer.addChild submitButton)
(submitButton.grabFocus)))
(method :Void chooseEntry [:String prompt :Archive archive :Entry->Void resolve] (throw "TODO Not implemented!"))
(method :Void chooseEntries [:String prompt :Archive archive :Array<Entry>->Void resolve :Int min :Float max] (throw "TODO Not implemented!"))
(method :Void handleChanges [:Archive archive :ChangeSet changeSet]
null)
(method :Void displayMessage [:String message]
(let [label (new Label)]
(set label.text message)
(rootNode.uiContainer.addChild label)))
(method :Void reportError [:String error]
(displayMessage "Error! $error"))
(method :Void onSelectionChanged [:Array<Entry> selectedEntries :Array<Entry> lastSelectedEntries] (throw "TODO Not implemented!"))
(method :Void choosePosition [:String prompt :Position->Void resolve]
(displayMessage prompt)
(set rootNode.resolvePosition resolve))
(method :Option<Position> cursorPosition []
(let [pos (.getMousePosition (rootNode.getViewport))]
(Some (vector2ToPosition pos))))
(function :Position vector2ToPosition [:Vector2 pos]
(object x pos.x y pos.y z 0.0))
(method :Void chooseBetweenStrings [:String prompt :Array<String> choices :String->Void resolve] (throw "TODO Not implemented!"))
(defNew [&prop :Archive archive
&prop :RootNode rootNode]
[
:EntryPanelSystem pgSystem (new EntryPanelSystem this rootNode)
])

View File

@@ -0,0 +1,27 @@
package;
class PlaygroundEntries extends Control {
public var currentFocus:EntryPanel = null;
public var currentFocusZ = Mathf.NA_N;
var ui:GodotUI = null;
public override function _Ready() {
var rootNode:RootNode = cast(getParent().getParent().getParent());
ui = rootNode.ui;
}
public override function getDragData(position:Vector2) {
return currentFocus;
}
public override function canDropData(position:Vector2, data:Dynamic) {
return data != null;
}
public override function dropData(position:Vector2, data:Dynamic):Void {
var data:EntryPanel = cast(data);
data.rectPosition = position;
ui.playgroundSystem().savePosition(data.e, position.x, position.y, data.z);
}
}

View File

@@ -0,0 +1,6 @@
package;
import kiss.Prelude;
@:build(kiss.Kiss.build())
class RootNode extends Control {}

View File

@@ -0,0 +1,67 @@
(loadFrom "kiss-godot" "src/kiss_godot/Util.kiss")
(prop &mut :TabContainer pgTabs)
(prop &mut :PackedScene pgScene)
(prop &mut :VBoxContainer uiContainer)
(defNew []
[
// TODO find a better way to pass the archiveDir to a Godot game
:Archive archive
(let [archiveDir (or (Sys.getEnv "NAT_DIR") (throw "NAT_DIR environment variable must be set"))]
(new Archive archiveDir))
:GodotUI ui
(new GodotUI archive this)
]
&first (super))
(method &override &public :Void _Ready []
(printThroughGD)
(set pgTabs (getNode this "PlaygroundTabContainer"))
(set pgScene (GD.load "res://Playground.tscn"))
(set uiContainer (getNode this "UIPanel/ScrollContainer/UIContainer"))
(doFor =>key playground archive.playgrounds
(unless (= key "default")
(let [pg (pgScene.instance)]
(set pg.name key)
(pgTabs.addChild pg))))
(set ui.controller (new ArchiveController archive ui)))
(method &override &public :Void _Process [:Float delta]
(when (Input.isActionJustPressed "type_command")
(ui.controller.typeCommand))
(when (Input.isActionJustPressed "type_shortcut")
0 **(ui.controller.typeShortcut)))
(method :Void _on_PlaygroundTabContainer_tab_changed [:Int tab]
(when ui.controller (.switchPlaygroundKey (ui.playgroundSystem) .name (pgTabs.getChild tab))))
(prop &mut :String->Void resolveString null)
(method :Void _on_LineEdit_text_entered [:String text]
(let [rs resolveString]
(set resolveString null)
(rs text)))
(prop &mut :Position->Void resolvePosition null)
(method &override &public :Void _Input [:InputEvent event]
(typeCase [event]
([:InputEventMouseButton mouseButtonEvent]
(when (= mouseButtonEvent.buttonIndex ButtonList.Left)
(whenLet [rp resolvePosition]
(set resolvePosition null)
(rp (GodotUI.vector2ToPosition (.getMousePosition (getViewport)))))))
(otherwise)))
(prop &mut :Float->Void resolveFloat)
(method :Void _on_NaNButton_pressed []
(resolveFloat Math.NaN))
(method :Void _on_SubmitNumberButton_pressed [:SpinBox spinBox]
(resolveFloat spinBox.value))

View File

@@ -0,0 +1,15 @@
import godot.*;
import godot.GD.*;
// using godot.Utils;
import nat.Archive;
import nat.ArchiveUI;
import nat.ArchiveController;
import nat.Lib;
import nat.Entry;
import nat.System;
import nat.systems.*;
import nat.components.*;
import haxe.ds.Option;