-
Notifications
You must be signed in to change notification settings - Fork 6
Add a Lua server/client console debug tool. #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
721cce4
Add a Lua server/client console debug tool.
max99x 90ee5d5
Lua console visual/UX polish.
max99x 82abe37
Add an optional hotkey (tilde/backtick) for toggling the Lua console.
max99x 672f324
Visual Lua console tweaks.
max99x c932ffb
Polish Lua console in response to code review.
max99x File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <script type="text/x-handlebars" data-template-name="luaConsoleIcon"> | ||
| <div id="luaConsoleIcon" title="Lua Console"></div> | ||
| </script> | ||
|
|
||
| <script type="text/x-handlebars" data-template-name="luaConsole"> | ||
| <div id="luaConsole"> | ||
| <div class="header"> | ||
| Lua Console | ||
| <div id="toolbar"> | ||
| <a id="serverButton" href="#" {{action "switchToServer" target="view"}} class="button selected" title="Run commands on the server"> | ||
| server | ||
| </a> | ||
| <a id="clientButton" href="#" {{action "switchToClient" target="view"}} class="button" title="Run commands on the client"> | ||
| client | ||
| </a> | ||
| </div> | ||
| <div id="closeConsoleButton"></div> | ||
| </div> | ||
| <div id="body"> | ||
| {{view view.envContainer viewName="envContainerInstance"}} | ||
| </div> | ||
| </div> | ||
| </script> | ||
|
|
||
| <script type="text/x-handlebars" data-template-name="stonehearthLuaConsoleEnvironment"> | ||
| <div id="stonehearthLuaConsoleEnvironment"> | ||
| <div class="output"> | ||
| <div id="title">[{{view.env}}] If an entity is selected, it can be accessed through the global "e" variable.</div> | ||
| </div> | ||
| <div class="input"> | ||
| <input id="input" /> | ||
| </div> | ||
| </div> | ||
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| $(document).on('stonehearthReady', function(){ | ||
| App.debugDock.addToDock(App.StonehearthLuaConsoleIcon); | ||
| radiant.call('radiant:get_config', 'mods.debugtools.enable_lua_console_hotkey') | ||
| .done(function (o) { | ||
| if (o['mods.debugtools.enable_lua_console_hotkey']) { | ||
| $(top).bind('keydown', function (e) { | ||
| if (e.keyCode == 192 && !e.originalEvent.repeat) { // Tilde/backtick | ||
| App.debugView.getView(App.StonehearthLuaConsoleIcon).$().click(); | ||
| e.preventDefault(); | ||
| e.stopPropagation(); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| App.StonehearthLuaConsoleIcon = App.View.extend({ | ||
| templateName: 'luaConsoleIcon', | ||
| classNames: ['debugDockIcon'], | ||
|
|
||
| didInsertElement: function() { | ||
| $('#luaConsoleIcon').tooltipster(); | ||
| this.$().click(function () { | ||
| var view = App.debugView.getView(App.StonehearthLuaConsoleView); | ||
| if (view) { | ||
| view.$().toggle(); | ||
| if (view.$().is(':visible')) { | ||
| view.focus(); | ||
| } | ||
| } else { | ||
| App.debugView.addView(App.StonehearthLuaConsoleView); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| App.StonehearthLuaConsoleView = App.View.extend({ | ||
| templateName: 'luaConsole', | ||
| uriProperty: 'model', | ||
| envContainer: Ember.ContainerView.extend(), | ||
|
|
||
| didInsertElement: function() { | ||
| var self = this; | ||
|
|
||
| this.$().draggable({ handle: '.header' }); | ||
|
|
||
| this.$('.button').tooltipster({ | ||
| theme: 'tooltipster-shdt', | ||
| arrow: true, | ||
| }); | ||
|
|
||
| this.$("#closeConsoleButton").click(function () { | ||
| self.$().hide(); | ||
| }); | ||
|
|
||
| self.clientEnv = App.StonehearthLuaConsoleEnvironmentView.create({ env: 'client' }); | ||
| self.serverEnv = App.StonehearthLuaConsoleEnvironmentView.create({ env: 'server' }); | ||
|
|
||
| self.get('envContainerInstance').pushObject(self.serverEnv); | ||
| self.get('envContainerInstance').pushObject(self.clientEnv); | ||
|
|
||
| setTimeout(function () { self.switchEnv(true); }, 1); | ||
| }, | ||
|
|
||
| switchEnv: function (isClient) { | ||
| var toShow = isClient ? this.clientEnv : this.serverEnv; | ||
| var toHide = isClient ? this.serverEnv : this.clientEnv; | ||
|
|
||
| toHide.$().hide(); | ||
| toShow.$().show(); | ||
| toShow.focus(); | ||
|
|
||
| var toSelect = isClient ? '#clientButton' : '#serverButton'; | ||
| var toDeselect = isClient ? '#serverButton' : '#clientButton'; | ||
| this.$(toSelect).addClass('selected'); | ||
| this.$(toDeselect).removeClass('selected'); | ||
| }, | ||
|
|
||
| focus: function () { | ||
| if (this.clientEnv.$().is(':visible')) { | ||
| this.clientEnv.focus(); | ||
| } else { | ||
| this.serverEnv.focus(); | ||
| } | ||
| }, | ||
|
|
||
| actions: { | ||
| switchToServer: function () { | ||
| this.switchEnv(false); | ||
| }, | ||
|
|
||
| switchToClient: function () { | ||
| this.switchEnv(true); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| App.StonehearthLuaConsoleEnvironmentView = App.View.extend({ | ||
| templateName: 'stonehearthLuaConsoleEnvironment', | ||
| uriProperty: 'model', | ||
| env: null, | ||
|
|
||
| init: function () { | ||
| this._super(); | ||
| this._history = []; | ||
| this._curHistoryIdx = 0; | ||
| this._curCommand = ''; | ||
| }, | ||
|
|
||
| didInsertElement: function() { | ||
| var self = this; | ||
|
|
||
| self.$('#input').keydown(function(e) { | ||
| if (e.keyCode == 13 && !e.originalEvent.repeat) { // Enter | ||
| var command = $(this).val(); | ||
| if (!command) return; | ||
| self._history.push(command); | ||
| $(this).val(''); | ||
| self._curHistoryIdx = self._history.length - 1; | ||
|
|
||
| var outputArea = self.$('.output'); | ||
| outputArea.append($('<div class="cmdIn">').text('> ' + command)); | ||
|
|
||
| var resultContainer = $('<div class="cmdOut progress">').text('...'); | ||
| outputArea.append(resultContainer); | ||
|
|
||
| var currentEntity = App.stonehearthClient.getSubSelectedEntity(); | ||
| if (!currentEntity) { | ||
| currentEntity = App.stonehearthClient.getSelectedEntity(); | ||
| } | ||
| radiant.call('debugtools:exec_script_' + self.env, command, currentEntity) | ||
| .done(function (o) { | ||
| resultContainer.removeClass('progress').text(o.result); | ||
| outputArea.scrollTop(outputArea[0].scrollHeight); | ||
| }) | ||
| .fail(function (o) { | ||
| if (typeof o.error == 'string') { | ||
| // Client failures don't decode. We should fix it at the root, but this hack here is fine for now. | ||
| o = JSON.parse(o.error) | ||
| } | ||
| resultContainer.removeClass('progress').addClass('error').text(o.result); | ||
| outputArea.scrollTop(outputArea[0].scrollHeight); | ||
| }); | ||
|
|
||
| outputArea.scrollTop(outputArea[0].scrollHeight); | ||
| } else if (e.keyCode == 27) { // Esc | ||
| App.debugView.getView(App.StonehearthLuaConsoleIcon).$().click(); | ||
| e.preventDefault(); | ||
| e.stopPropagation(); | ||
| } | ||
| }); | ||
|
|
||
| this.$('#input').keydown(function (e) { | ||
| if (e.keyCode == 38) { // UpArrow | ||
| if (self._curHistoryIdx == self._history.length - 1) { | ||
| // Remember our current command, if any. | ||
| if ($(this).val() != '') { | ||
| self._curCommand = $(this).val(); | ||
| } | ||
| } | ||
|
|
||
| $(this).val(self._history[self._curHistoryIdx]); | ||
|
|
||
| self._curHistoryIdx--; | ||
| if (self._curHistoryIdx < 0) { | ||
| self._curHistoryIdx = 0; | ||
| } | ||
| e.preventDefault(); | ||
| } else if (e.keyCode == 40) { // DownArrow | ||
| if (self._curHistoryIdx == self._history.length - 1) { | ||
| if (self._curCommand != '') { | ||
| $(this).val(self._curCommand); | ||
| self._curCommand = ''; | ||
| } | ||
| return; | ||
| } | ||
| self._curHistoryIdx++; | ||
| $(this).val(self._history[self._curHistoryIdx]); | ||
| e.preventDefault(); | ||
| } | ||
| }); | ||
| }, | ||
|
|
||
| focus: function () { | ||
| this.$('#input').focus(); | ||
| }, | ||
| }); | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like naming the variable
entityis more intuitive thane.eis less verbose though 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started off with "entity", but after playing with it for a while, it was a pain to type that every time. I considered using something particularly weird like $ and replacing it with some auto-generated variable name in the script before compiling, but that seems worse,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair. Lets stick with
ethen