diff --git a/code/modules/admin/topic.dm b/code/modules/admin/topic.dm index 0fce604884c..6142c571790 100644 --- a/code/modules/admin/topic.dm +++ b/code/modules/admin/topic.dm @@ -1950,8 +1950,6 @@ if(log_index <= state_to_view.log.len) var/list/log_entry = state_to_view.log[log_index] if(log_entry["chunk"]) - LAZYINITLIST(editor.tgui_shared_states) - editor.tgui_shared_states["viewedChunk"] = json_encode(log_entry["chunk"]) - editor.tgui_shared_states["modal"] = json_encode("viewChunk") + editor.force_view_chunk = log_entry["chunk"] + editor.force_modal = "viewChunk" editor.ui_interact(usr) - editor.tgui_shared_states = null diff --git a/code/modules/admin/verbs/lua/lua_editor.dm b/code/modules/admin/verbs/lua/lua_editor.dm index 97c5ae80de4..1b0e95749ba 100644 --- a/code/modules/admin/verbs/lua/lua_editor.dm +++ b/code/modules/admin/verbs/lua/lua_editor.dm @@ -7,8 +7,17 @@ /// Arguments for a function call or coroutine resume var/list/arguments = list() - /// If set, the global table and the - var/show_debug_info = FALSE + /// If set, the global table will not be shown in the lua editor + var/show_global_table = FALSE + + /// The log page we are currently on + var/page = 0 + + /// If set, we will force the editor's modal to be this + var/force_modal + + /// If set, we will force the editor to look at this chunk + var/force_view_chunk /datum/lua_editor/New(state, _quick_log_index) . = ..() @@ -39,16 +48,24 @@ /datum/lua_editor/ui_data(mob/user) var/list/data = list() data["noStateYet"] = !current_state - data["showDebugInfo"] = show_debug_info + data["showGlobalTable"] = show_global_table if(current_state) - if(current_state.log && show_debug_info) - data["stateLog"] = kvpify_list(refify_list(current_state.log)) + if(current_state.log) + data["stateLog"] = kvpify_list(refify_list(current_state.log.Copy((page*50)+1, min((page+1)*50+1, current_state.log.len+1)))) + data["page"] = page + data["pageCount"] = CEILING(current_state.log.len/50, 1) data["tasks"] = current_state.get_tasks() - if(show_debug_info) + if(show_global_table) current_state.get_globals() data["globals"] = kvpify_list(refify_list(current_state.globals)) data["states"] = SSlua.states data["callArguments"] = kvpify_list(refify_list(arguments)) + if(force_modal) + data["forceModal"] = force_modal + force_modal = null + if(force_view_chunk) + data["forceViewChunk"] = force_view_chunk + force_view_chunk = null return data /datum/lua_editor/proc/traverse_list(list/path, list/root, traversal_depth_offset = 0) @@ -96,12 +113,14 @@ LAZYREMOVEASSOC(SSlua.editors, "\ref[current_state]", src) current_state = new_state LAZYADDASSOCLIST(SSlua.editors, "\ref[current_state]", src) + page = 0 return TRUE if("switchState") var/state_index = params["index"] LAZYREMOVEASSOC(SSlua.editors, "\ref[current_state]", src) current_state = SSlua.states[state_index] LAZYADDASSOCLIST(SSlua.editors, "\ref[current_state]", src) + page = 0 return TRUE if("runCode") var/code = params["code"] @@ -191,8 +210,14 @@ if("clearArgs") arguments.Cut() return TRUE - if("toggleShowDebugInfo") - show_debug_info = !show_debug_info + if("toggleShowGlobalTable") + show_global_table = !show_global_table + return TRUE + if("nextPage") + page = min(page+1, CEILING(current_state.log.len/50, 1)-1) + return TRUE + if("previousPage") + page = max(page-1, 0) return TRUE /datum/lua_editor/ui_close(mob/user) diff --git a/code/modules/admin/verbs/lua/lua_state.dm b/code/modules/admin/verbs/lua/lua_state.dm index a6f8efacd30..0b836aac5e1 100644 --- a/code/modules/admin/verbs/lua/lua_state.dm +++ b/code/modules/admin/verbs/lua/lua_state.dm @@ -58,7 +58,7 @@ GLOBAL_PROTECT(lua_usr) break if(append_to_log) log += list(weakrefify_list(result)) - INVOKE_ASYNC(src, .proc/update_editors) + INVOKE_ASYNC(src, /datum/lua_state.proc/update_editors) /datum/lua_state/proc/load_script(script) GLOB.IsLuaCall = TRUE diff --git a/tgui/packages/tgui/components/Section.tsx b/tgui/packages/tgui/components/Section.tsx index eedebdaf8a3..d1507f59d8b 100644 --- a/tgui/packages/tgui/components/Section.tsx +++ b/tgui/packages/tgui/components/Section.tsx @@ -66,6 +66,7 @@ export class Section extends Component { scrollable, scrollableHorizontal, children, + onScroll, ...rest } = this.props; const hasTitle = canRender(title) || canRender(buttons); @@ -89,7 +90,10 @@ export class Section extends Component { )}
-
+
{children}
diff --git a/tgui/packages/tgui/interfaces/LuaEditor/CallModal.js b/tgui/packages/tgui/interfaces/LuaEditor/CallModal.js index ac27f99b681..7260c4c7549 100644 --- a/tgui/packages/tgui/interfaces/LuaEditor/CallModal.js +++ b/tgui/packages/tgui/interfaces/LuaEditor/CallModal.js @@ -9,7 +9,9 @@ export const CallModal = (props, context) => { const [toCall, setToCall] = useLocalState(context, 'toCallTaskInfo'); const { type, params } = toCall; return ( - +
{ const [, setModal] = useLocalState(context, 'modal'); const [viewedChunk, setViewedChunk] = useLocalState(context, 'viewedChunk'); return ( - +
{ const [input, setInput] = useLocalState(context, 'newStateName', ''); const { states } = data; return ( - +
{ - const { act, data } = useBackend(context); - const { noStateYet, globals, documentation, tasks, showDebugInfo } = data; - const [modal, setModal] = useLocalState( - context, - 'modal', - noStateYet ? 'states' : null - ); - const [activeTab, setActiveTab] = useLocalState( - context, - 'activeTab', - 'tasks' - ); - const [input, setInput] = useLocalState(context, 'scriptInput', ''); - let tabContent; - switch (activeTab) { - case 'globals': { - if (!globals) { - tabContent = ( -

- Could not retrieve the global table. Was it corrupted or shadowed? -

- ); - } else { - tabContent = ( - act('vvGlobal', { indices: path })} - callType="callFunction" - /> - ); +export class LuaEditor extends Component { + constructor(props) { + super(props); + this.sectionRef = createRef(); + this.state = { + showJumpToBottomButton: false, + activeTab: 'tasks', + scriptInput: '', + }; + + this.handleSectionScroll = () => { + const { showJumpToBottomButton } = this.state; + const scrollableCurrent = this.sectionRef.current?.scrollableRef.current; + if ( + !showJumpToBottomButton && + scrollableCurrent?.scrollHeight > + scrollableCurrent?.scrollTop + scrollableCurrent?.clientHeight + ) { + this.setState({ showJumpToBottomButton: true }); + } else if ( + showJumpToBottomButton && + scrollableCurrent?.scrollTop + scrollableCurrent?.clientHeight >= + scrollableCurrent?.scrollHeight + ) { + this.setState({ showJumpToBottomButton: false }); } - break; - } - case 'tasks': { - if (!tasks) { - tabContent = ( -

- Could not retrieve task info. Was the global table corrupted or - shadowed? -

- ); - } else { - tabContent = ; - } - break; - } - case 'log': { - tabContent = ; - break; + }; + + window.addEventListener('resize', () => + this.forceUpdate(this.handleSectionScroll) + ); + } + + componentDidMount() { + const { data } = useBackend(this.context); + const { forceModal, forceViewChunk } = data; + if (forceModal || forceViewChunk) { + const [, setModal] = useLocalState(this.context, 'modal'); + const [, setViewedChunk] = useLocalState(this.context, 'viewedChunk'); + setModal(forceModal); + setViewedChunk(forceViewChunk); } } - return ( - - - - {noStateYet ? ( - -

Please select or create a lua state to get started.

-
- ) : ( - - -
- setInput(file)} - accept=".lua,.luau"> - Import - - - - }> -