Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Main script for Logical: Logic simulator for ComputerCraft
- -- By daelvn
- -- Linter stuff
- local term, keys, os, fs, paintutils, io = term, keys, os, fs, paintutils, io
- local ipairs, print, pairs = ipairs, print, pairs
- local Logical = {
- Palette = {
- UI = {
- Canvas = colors.white,
- Toolbar = colors.lightGray,
- Other = colors.gray
- },
- Wire = {
- Off = colors.green,
- On = colors.lime,
- Cross = colors.yellow,
- Error = colors.red,
- }
- }
- }
- --- Create UI ---
- term.setBackgroundColor(Logical.Palette.UI.Canvas)
- term.setTextColor(colors.black)
- term.clear()
- -- Let's make it responsive, start by getting the screen size
- local ScreenX, ScreenY = term.getSize()
- -- Create the main points
- local ToolbarAX, ToolbarAY = 1, 1
- local ToolbarBX, ToolbarBY = ScreenY, 2
- local SidebarAX, SidebarAY = 1, 3
- local SidebarBX, SidebarBY = 20, ScreenY
- local CanvasAX, CanvasAY = 21, 3
- local CanvasBX, CanvasBY = ScreenX, ScreenY
- -- Draw those points
- local function drawToolbar()
- paintutils.drawFilledBox(ToolbarAX, ToolbarAY, ToolbarBX, ToolbarBY, Logical.Palette.UI.Toolbar)
- end
- local function drawSidebar()
- paintutils.drawFilledBox(SidebarAX, SidebarAY, SidebarBX, SidebarBY, Logical.Palette.UI.Toolbar)
- end
- local function drawCanvas()
- paintutils.drawFilledBox(CanvasAX, CanvasAY, CanvasBX, CanvasBY, Logical.Palette.UI.Canvas)
- end
- drawToolbar()
- drawSidebar()
- --- Initialize functions ---
- Logical.Project = {_name="", _path="", _structure={}}
- Logical.Functions = {}
- Logical.LHDL = {}
- -- Project
- function Logical.Functions.NewProject()
- -- Create a new project
- local at, name = "", ""
- drawCanvas()
- term.setCursorPos(CanvasAX, CanvasAY)
- print("Enter the base path for your project:")
- at = io.read()
- print("Enter the name for your project:")
- name = io.read()
- if fs.isDir(at) then
- fs.makeDir(fs.combine(at, name))
- Logical.Project._name = name
- Logical.Project._path = fs.combine(at, name)
- else return false end
- drawSidebar()
- drawCanvas()
- term.setCursorPos(1,3)
- print(name.." >")
- end
- function Logical.Functions.OpenProject()
- -- Open a project
- local at, name = "", ""
- drawCanvas()
- term.setCursorPos(CanvasAX, CanvasAY)
- print("Enter the path of the project:")
- at = io.read()
- if not fs.isDir(at) then return false end
- name = fs.getName(at)
- drawSidebar()
- drawCanvas()
- term.setCursorPos(1,3)
- print(name..">")
- end
- function Logical.Functions.SaveProject()
- -- Save a project
- end
- function Logical.Functions.NewFolder()
- -- Create folder under project
- end
- function Logical.Functions.RemoveFolder()
- -- Remove folder under project
- end
- -- Circuits
- function Logical.Functions.NewCircuit()
- -- Create a new circuit
- end
- function Logical.Functions.OpenCircuit()
- -- Open a circuit (Import)
- end
- function Logical.Functions.SaveCircuit()
- -- Save a circuit
- end
- function Logical.LHDL.CircuitToLHDL()
- -- Convert a circuit into LHDL
- end
- --- Initialize colors ---
- term.setPaletteColor(Logical.Palette.UI.Canvas, 0xFFFFFF)
- term.setPaletteColor(Logical.Palette.UI.Toolbar, 0xE2E2E2)
- term.setPaletteColor(Logical.Palette.UI.Other, 0xD8D8D8)
- term.setPaletteColor(Logical.Palette.Wire.Off, 0x073D13)
- term.setPaletteColor(Logical.Palette.Wire.On, 0x128E2D)
- term.setPaletteColor(Logical.Palette.Wire.Cross, 0x2EC952)
- term.setPaletteColor(Logical.Palette.Wire.Error, 0xC92E36)
- -- Now create the toolbar
- term.setCursorPos(1,1)
- io.write("Logical: ")
- Logical.Toolbar = {
- Project = {
- New = Logical.Functions.NewProject,
- Open = Logical.Functions.OpenProject,
- Save = Logical.Functions.SaveProject,
- FolderNew = Logical.Functions.NewFolder,
- DelFolder = Logical.Functions.RemoveFolder,
- },
- Circuit = {
- New = Logical.Functions.NewCircuit,
- Open = Logical.Functions.OpenCircuit,
- Save = Logical.Functions.SaveCircuit,
- ToLHDL = Logical.LHDL.CircuitToLHDL,
- }
- }
- Logical.Triggers = {}
- for menu, content in pairs(Logical.Toolbar) do
- Logical.Triggers[menu] = {key=keys[menu:sub(1,1):lower()],submenu=content}
- io.write(menu.." | ")
- end
- -- Trigger function
- function Logical.Trigger (submenu)
- term.setCursorPos(1,2)
- local triggerKeys = {
- [keys.space] = function()end
- }
- for name, tfn in pairs(submenu) do
- triggerKeys[keys[name:sub(1,1):lower()]] = tfn
- end
- while true do
- local doBreak = false
- local event, key = os.pullEvent("key")
- for tkey, tfn in ipairs(triggerKeys) do
- if tkey == key then tfn()
- doBreak = true
- break
- end
- end
- if doBreak then break end
- end
- end
- --- Main event loop ---
- while true do
- local event, key = os.pullEvent("key")
- for tname, t in pairs(Logical.Triggers) do
- term.setCursorPos(1,3)
- io.write(type(t.key))
- io.write(" / ")
- io.write(string.char(t.key))
- if t.key == key then
- Logical.Trigger(t.submenu)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement