this repo has no description

some more keybinds, and syncing doesn't shit itself anymore

phaz.uk 0f24d541 3de4485c

verified
Changed files
+91 -18
src
src-tauri
src
frontend_calls
-3
src-tauri/src/frontend_calls/sync_tab.rs
··· 18 18 19 19 let mut config = conf.store.lock().unwrap(); 20 20 config.loaded_tabs.remove(&id); 21 - drop(config); 22 - 23 - conf.save(); 24 21 }
+4 -6
src/App.tsx
··· 12 12 import { TabMenu } from "./components/TabMenu"; 13 13 import { ConfirmationPopup } from "./components/ConfirmationPopup"; 14 14 15 - let App = () => { 16 - // TODO: Keybind system 17 - // TODO: Delete selected node when delete key is pressed 18 - // TODO: Copy / paste 19 - // TODO: Add undo / redo -ing 20 - // TODO: Multi-select 15 + import * as keybinds from './keybinds'; 21 16 17 + let App = () => { 22 18 let [ selectedNode, setSelectedNode ] = createSignal<Node | null>(null); 23 19 24 20 let canvas!: HTMLCanvasElement; ··· 324 320 isDrawing = false; 325 321 isMouseDown = false; 326 322 } 323 + 324 + keybinds.load(selectedNode); 327 325 328 326 requestAnimationFrame(update); 329 327 });
+24 -8
src/Mangers/NodeManager.tsx
··· 7 7 import { NodesByID } from "../Nodes/Nodes"; 8 8 import { save } from "@tauri-apps/plugin-dialog"; 9 9 import { ConfirmationManager } from "./ConfirmationManager"; 10 - import { getCurrentWindow } from "@tauri-apps/api/window"; 11 10 12 11 export interface TabHashMap { 13 12 [details: string] : Tab; ··· 23 22 24 23 constructor(){ 25 24 NodeManager.Instance = this; 25 + 26 + setInterval(() => { 27 + let tabs = Object.values(this._tabs).filter(x => x.needSync); 28 + console.log('Syncing ' + tabs.length + ' tabs'); 29 + for(let tab of tabs){ 30 + invoke('sync_tab', { graph: this._generateTabGraph(tab.id)[0], id: tab.id, name: tab.name, location: tab.saveLocation }); 31 + tab.needSync = false; 32 + } 33 + }, 1000); 26 34 27 35 listen('load_new_tab', ( ev: any ) => { 28 36 this._loadFromConfig(ev.payload.path, null, ev.payload.graph); ··· 78 86 private _tabUpdateHook: ( tabs: TabHashMap ) => void = () => {}; 79 87 private _tabChangeHook: () => void = () => {}; 80 88 89 + public CurrentTab(): Tab | null{ 90 + if(!this._selectedTab)return null 91 + return this._tabs[this._selectedTab] || null; 92 + } 93 + 81 94 public async AddTab( name: string, id: string | null = null ): Promise<Tab>{ 82 95 let [ selected, setSelected ] = createSignal(false); 83 96 let [ needsSave, setNeedsSave ] = createSignal(false); ··· 94 107 needsSave, 95 108 setNeedsSave, 96 109 97 - refuseSync: false 110 + needSync: false 98 111 }; 99 112 100 113 this._tabs[tab.id] = tab; ··· 189 202 } 190 203 } 191 204 192 - public async SaveTab( tab: Tab ){ 205 + public async SaveTab( tab: Tab, ignoreSaveLocation: boolean = false ){ 193 206 let path = 194 - tab.saveLocation || 207 + tab.saveLocation && !ignoreSaveLocation ? 208 + tab.saveLocation : 195 209 await save({ defaultPath: tab.name + '.macro', filters: [ { name: 'Macro Files', extensions: [ 'macro' ] } ] }); 196 210 197 211 if(!path)throw new Error("Cannot save"); ··· 246 260 let tab = this._tabs[this._selectedTab]; 247 261 if(!tab)return; 248 262 249 - if(tab.refuseSync)return; 250 - invoke('sync_tab', { graph: this._generateTabGraph(tab.id)[0], id: tab.id, name: tab.name, location: tab.saveLocation }); 263 + tab.nodes = this._nodes; 264 + tab.needSync = true; 251 265 252 266 if(needsSave)tab.setNeedsSave(true); 253 267 } ··· 262 276 )return; 263 277 264 278 let tab = await this.AddTab(json.tab_name, id); 265 - tab.refuseSync = true; 279 + tab.needSync = false; 266 280 tab.saveLocation = path; 267 281 268 282 this._nodes = []; ··· 293 307 let input = output.connections[k]; 294 308 let node = this._nodes.find(x => x.id === input.node)!; 295 309 310 + if(!node)continue; 311 + 296 312 let realInput = node.inputs.find(x => x.index === input.index); 297 313 let realOutput = outputParentNode.outputs[j]; 298 314 ··· 318 334 tab.setNeedsSave(false); 319 335 tab.nodes = this._nodes; 320 336 321 - tab.refuseSync = false; 337 + tab.needSync = false; 322 338 if(!id)this.UpdateConfig(false); 323 339 } 324 340
+62
src/keybinds.ts
··· 1 + import { Accessor } from "solid-js"; 2 + import { NodeManager } from "./Mangers/NodeManager"; 3 + import { Node } from "./structs/node"; 4 + 5 + let isKeyDown: any = {}; 6 + 7 + export let load = ( selectedNode: Accessor<Node | null> ) => { 8 + // TODO: Keybind system 9 + // TODO: Delete selected node when delete key is pressed 10 + // TODO: Copy / paste 11 + // TODO: Add undo / redo -ing 12 + 13 + window.onkeydown = ( e ) => { 14 + isKeyDown[e.key] = true; 15 + 16 + console.log(e.key); 17 + 18 + switch(e.key){ 19 + case 'Delete': 20 + let node = selectedNode(); 21 + if(!node)return; 22 + 23 + node.inputs.map(input => { 24 + input.connections.map(partner => { 25 + partner.connections = partner.connections.filter(x => x != input); 26 + }) 27 + }) 28 + 29 + node.outputs.map(output => { 30 + output.connections.map(partner => { 31 + partner.connections = partner.connections.filter(x => x != output); 32 + }) 33 + }) 34 + 35 + // TODO: If node is currently selected, deselect it. 36 + NodeManager.Instance.RemoveNode(node); 37 + break; 38 + case 's': 39 + if(e.ctrlKey){ 40 + let currentTab = NodeManager.Instance.CurrentTab(); 41 + if(!currentTab)return; 42 + 43 + // Save 44 + NodeManager.Instance.SaveTab(currentTab); 45 + } 46 + break; 47 + case 'S': 48 + if(e.ctrlKey){ 49 + let currentTab = NodeManager.Instance.CurrentTab(); 50 + if(!currentTab)return; 51 + 52 + // Save 53 + NodeManager.Instance.SaveTab(currentTab, true); 54 + } 55 + break; 56 + } 57 + } 58 + 59 + window.onkeyup = ( e ) => { 60 + isKeyDown[e.key] = false; 61 + } 62 + }
+1 -1
src/structs/Tab.ts
··· 13 13 needsSave: Accessor<boolean>, 14 14 setNeedsSave: Setter<boolean>, 15 15 16 - refuseSync: boolean 16 + needSync: boolean 17 17 }