#545 #544 added cc graphics and peripheral classes

This commit is contained in:
Mikayla Fischler
2024-09-14 22:16:12 -04:00
parent 85fc8d2920
commit ec2921e393
13 changed files with 95 additions and 30 deletions

View File

@@ -77,23 +77,14 @@ end
-- NIC: Network Interface Controller<br>
-- utilizes HMAC-MD5 for message authentication, if enabled
---@param modem table modem to use
---@param modem Modem modem to use
function network.nic(modem)
local self = {
connected = true, -- used to avoid costly MAC calculations if modem isn't even present
channels = {}
}
---@class nic
---@field isOpen fun(channel: integer) : boolean check if a channel is open
---@field isWireless fun() : boolean determine if this is a wired or wireless modem
---@field getNamesRemote fun() : string[] list all remote peripherals on the wired network
---@field isPresentRemote fun(name: string) : boolean determine if a peripheral is available on this wired network
---@field getTypeRemote fun(name: string) : string|nil get the type of a peripheral is available on this wired network
---@field hasTypeRemote fun(name: string, type: string) : boolean|nil check a peripheral is of a particular type
---@field getMethodsRemote fun(name: string) : string[] get all available methods for the remote peripheral with the given name
---@field callRemote fun(remoteName: string, method: string, ...) : table call a method on a peripheral on this wired network
---@field getNameLocal fun() : string|nil returns the network name of the current computer, if the modem is on
---@class nic:Modem
local public = {}
-- check if this NIC has a connected modem
@@ -101,7 +92,7 @@ function network.nic(modem)
function public.is_connected() return self.connected end
-- connect to a modem peripheral
---@param reconnected_modem table
---@param reconnected_modem Modem
function public.connect(reconnected_modem)
modem = reconnected_modem
self.connected = true

View File

@@ -423,7 +423,7 @@ function ppm.get_fission_reactor() return ppm.get_device("fissionReactorLogicAda
-- get the wireless modem (if multiple, returns the first)<br>
-- if this is in a CraftOS emulated environment, wired modems will be used instead
---@nodiscard
---@return table|nil modem function table
---@return Modem|nil modem function table
function ppm.get_wireless_modem()
local w_modem = nil
local emulated_env = periphemu ~= nil
@@ -440,7 +440,7 @@ end
-- list all connected monitors
---@nodiscard
---@return table monitors
---@return { [string]: ppm_entry } monitors
function ppm.get_monitor_list()
local list = {}

View File

@@ -5,6 +5,66 @@
---@class types
local types = {}
--#region CC: TWEAKED CLASSES https://tweaked.cc
---@class Redirect
---@field write fun(text: string) Write text at the current cursor position, moving the cursor to the end of the text.
---@field scroll fun(y: integer) Move all positions up (or down) by y pixels.
---@field getCursorPos fun() : x: integer, y: integer Get the position of the cursor.
---@field setCursorPos fun(x: integer, y: integer) Set the position of the cursor.
---@field getCursorBlink fun() : boolean Checks if the cursor is currently blinking.
---@field setCursorBlink fun(blink: boolean) Sets whether the cursor should be visible (and blinking) at the current cursor position.
---@field getSize fun() : width: integer, height: integer Get the size of the terminal.
---@field clear fun() Clears the terminal, filling it with the current background color.
---@field clearLine fun() Clears the line the cursor is currently on, filling it with the current background color.
---@field getTextColor fun() : color Return the color that new text will be written as.
---@field setTextColor fun(color: color) Set the colour that new text will be written as.
---@field getBackgroundColor fun() : color Return the current background color.
---@field setBackgroundColor fun(color: color) set the current background color.
---@field isColor fun() Determine if this terminal supports color.
---@field blit fun(text: string, textColor: string, backgroundColor: string) Writes text to the terminal with the specific foreground and background colors.
---@diagnostic disable-next-line: duplicate-doc-field
---@field setPaletteColor fun(index: color, color: integer) Set the palette for a specific color.
---@diagnostic disable-next-line: duplicate-doc-field
---@field setPaletteColor fun(index: color, r: number, g: number, b:number) Set the palette for a specific color. R/G/B are 0 to 1.
---@field getPaletteColor fun(color: color) : r: number, g: number, b:number Get the current palette for a specific color.
---@class Window:Redirect
---@field getLine fun(y: integer) : content: string, fg: string, bg: string Get the buffered contents of a line in this window.
---@field setVisible fun(visible: boolean) Set whether this window is visible. Invisible windows will not be drawn to the screen until they are made visible again.
---@field isVisible fun() : visible: boolean Get whether this window is visible. Invisible windows will not be drawn to the screen until they are made visible again.
---@field redraw fun() Draw this window. This does nothing if the window is not visible.
---@field restoreCursor fun() Set the current terminal's cursor to where this window's cursor is. This does nothing if the window is not visible.
---@field getPosition fun() : x: integer, y: integer Get the position of the top left corner of this window.
---@field reposition fun(new_x: integer, new_y: integer, new_width?: integer, new_height?: integer, new_parent?: Redirect) Reposition or resize the given window.
---@class Monitor:Redirect
---@field setTextScale fun(scale: number) Set the scale of this monitor.
---@field getTextScale fun() : number Get the monitor's current text scale.
---@class Modem
---@field open fun(channel: integer) Open a channel on a modem.
---@field isOpen fun(channel: integer) : boolean Check if a channel is open.
---@field close fun(channel: integer) Close an open channel, meaning it will no longer receive messages.
---@field closeAll fun() Close all open channels.
---@field transmit fun(channel: integer, replyChannel: integer, payload: any) Sends a modem message on a certain channel.
---@field isWireless fun() : boolean Determine if this is a wired or wireless modem.
---@field getNamesRemote fun() : string[] List all remote peripherals on the wired network.
---@field isPresentRemote fun(name: string) : boolean Determine if a peripheral is available on this wired network.
---@field getTypeRemote fun(name: string) : string|nil Get the type of a peripheral is available on this wired network.
---@field hasTypeRemote fun(name: string, type: string) : boolean|nil Check a peripheral is of a particular .
---@field getMethodsRemote fun(name: string) : string[] Get all available methods for the remote peripheral with the given name.
---@field callRemote fun(remoteName: string, method: string, ...) : table Call a method on a peripheral on this wired network.
---@field getNameLocal fun() : string|nil Returns the network name of the current computer, if the modem is on.
---@class Speaker
---@field playNote fun(instrument: string, volume?: number, pitch?: number) : success: boolean Plays a note block note through the speaker.
---@field playSound fun(name: string, volume?: number, pitch?: number) : success: boolean Plays a Minecraft sound through the speaker.
---@field playAudio fun(audio: number[], volume?: number) : success: boolean Attempt to stream some audio data to the speaker.
---@field stop fun() Stop all audio being played by this speaker.
--#endregion
--#region CLASSES
---@class tank_fluid