diff --git a/common/Navigation/Campspot.iss b/common/Navigation/Campspot.iss new file mode 100644 index 0000000..51cb80c --- /dev/null +++ b/common/Navigation/Campspot.iss @@ -0,0 +1,7 @@ +#ifndef _mr_campspot_ +#define _mr_campspot_ +objectdef MRCampSpot +{ + +} +#endif \ No newline at end of file diff --git a/common/Navigation/Movement.iss b/common/Navigation/Movement.iss new file mode 100644 index 0000000..68166a1 --- /dev/null +++ b/common/Navigation/Movement.iss @@ -0,0 +1,85 @@ +#ifndef _mr_movement_ +#define _mr_movement_ +objectdef MovememntKeyMap +{ + variable string MoveForwardKey = "w" +} + +objectdef MRNavigation +{ + variable bool MoveToRequested = FALSE + variable point3f MoveToPoint + variable float Percision = 5 + + method SetPercision(float persision) + { + Percision:Set[${persision}] + } + + method MoveTo(point3f point) + { + MoveToRequested:Set[TRUE] + MoveToPoint:Set[${point.X}, ${point.Z}, ${point.Z}] + } + + method MoveToComplete() + { + MoveToRequested:Set[FALSE] + } +} + +variable(global) MRNavigation MRNav +variable MovememntKeyMap MRMoveKeyMap + +variable jsonvalue _debounceChecks = "{}"; +function Debounce(string command, string id, int interval) +{ + if !${_debounceChecks.Has["${id}"]} || !${_debounceChecks.Get["${id}"]} + { + variable weakref commandRef = "${command}" + _debounceChecks:Set["${id}", TRUE] + execute ${command} + TimedCommand ${interval} Script["${Script.Filename}"].Variable["_debounceChecks"]:Erase["${id}"] + } +} + +function FacePoint(point3f point) +{ + call Debounce "face ${point.X} ${point.Z}" "face" 3 +} + +function MoveTo(point3f point) +{ + + while ${Math.Distance[${Me.X},${Me.Z},${MRNav.MoveToPoint.X},${MRNav.MoveToPoint.Z}]} > ${MRNav.Percision} + { + call FacePoint ${point} + + if !${Me.IsMoving} + { + + call Debounce "press -hold ${MRMoveKeyMap.MoveForwardKey}" "moveForward" 5 + } + wait 1 + + call Debounce "echo Distance ${Math.Distance[${Me.X},${Me.Z},${MRNav.MoveToPoint.X},${MRNav.MoveToPoint.Z}]} > ${MRNav.Percision}" "debugDistance" 5 + } + press -release ${MRMoveKeyMap.MoveForwardKey} + MRNav:MoveToComplete +} + +function main() +{ + while 1 + { + if !${MRNav.MoveToRequested} + { + continue + } + + call Debounce "call MoveTo ${MRNav.MoveToPoint}" "move" 5 + + } + +} +#endif \ No newline at end of file diff --git a/common/Navigation/Test.iss b/common/Navigation/Test.iss new file mode 100644 index 0000000..db6aaf8 --- /dev/null +++ b/common/Navigation/Test.iss @@ -0,0 +1,39 @@ +objectdef TestController +{ + variable string Name="Apple" + variable string Color="Red" + method Initialize() + { + echo "TestController::Initialize" + LGUI2:LoadPackageFile["Test.json"] + RunScript "${LavishScript.HomeDirectory}/Scripts/mr/common/Navigation/Movement" + } + + method Shutdown() + { + echo "TestController::Shutdown" + LGUI2:UnloadPackageFile["Test.json"] + EndScript Movement + } + + method OnClose() + { + echo "TestController::OnClose" + Script:End + } + + method Test() + { + MRNav:MoveTo["${Me.Target.Loc}"] + } +} + +variable(global) TestController MRTestController +function main() +{ + + while 1 + { + wait 5 + } +} \ No newline at end of file diff --git a/common/Navigation/Test.json b/common/Navigation/Test.json new file mode 100644 index 0000000..70d98de --- /dev/null +++ b/common/Navigation/Test.json @@ -0,0 +1,77 @@ +{ + "$schema": "http://www.lavishsoft.com/schema/lgui2Package.json", + "skin": { + "name": "MRSkin", + "brushes": { + "window.titleBar.backgroundBrush": { + "color": "#211C18" + } + }, + "templates": { + "window.title": { + "verticalAlignment": "center", + "margin": [2, 0, 0, 0] + }, + "button": { + "jsonTemplate": "default:button", + "margin": [2, 2, 2, 2], + "color": "#f4f3ee" + }, + "checkbox": { + "jsonTemplate": "default:checkbox", + "margin": [2, 2, 2, 2] + }, + "window": { + "jsonTemplate": "default:window", + "backgroundBrush": { + "color": "#463f3a" + }, + "color": "#f4f3ee", + "font": { + "face": "Segoe UI", + "height": 16 + } + }, + "listbox.contentContainerFitWidth": { + "jsonTemplate": "listbox.contentContainer", + "horizontalScroll": "fit" + } + } + }, + "elements": [ + { + "type": "window", + "skin": "MRSkin", + "title": "MR Test", + "name": "mr.test.miniwindow", + "borderThickness": 2, + "hideOnClose": false, + "minSize": { + "width": 100, + "height": 50 + }, + "maxSize": { + "width": 150, + "height": 125 + }, + "eventHandlers": { + "onCloseButtonClick": ["method", "MRTestController", "OnClose"] + }, + "content": { + "type": "stackpanel", + "uniform": true, + "heightFactor": 1, + "children": [ + { + "type": "button", + "content": "Test", + "horizontalAlignment": "stretch", + "eventHandlers": { + "onRelease": ["method", "MRTestController", "Test"] + } + } + ] + } + } + ] +} diff --git a/mr.iss b/mr.iss index 5238d15..cf1c293 100644 --- a/mr.iss +++ b/mr.iss @@ -17,6 +17,6 @@ function main(... params) elseif ${params[1].Lower.Equal["test"]} { ConsoleClear - run mr/test ${params[2]} + run "mr/common/Navigation/test" } } \ No newline at end of file diff --git a/test.iss b/test.iss deleted file mode 100644 index d6d6af0..0000000 --- a/test.iss +++ /dev/null @@ -1,14 +0,0 @@ -#include "${LavishScript.HomeDirectory}/Scripts/mr/common/Api.iss" - -function main(string forWho) -{ - echo "Checking forWho ${forWho}" - if ${MRApi.IsForMe["${forWho}"]} - { - echo "This is for me!" - } - else - { - echo "This is not for me!" - } -} \ No newline at end of file