scmframework is a framework that allows you to make your mods based on SComputers and with SComputers functionality!
something like busybox for Scrap Mechanic
the framework is compiled using a special script from the SComputers scripts folder. the output is a single file
the scmframework build script comes with the mod and you can find it in the directory: USER/documentation/scmframework
the build script is designed for the windows operating system and runs through luajit
as the first argument, the script takes the path to the SComputers Scripts folder
the scmframework is a single file, your shape script can be either separate or inserted at the end of this file
the scmframework contains almost all SComputers, but without 3D models and textures
it also does not contain fonts converted from windows fonts, as they weighed too much
please note that although the framework itself is single-file, in order to use such things as displays, holographic projectors, GUIs, and standard samples in the synthesizer, you need to download additional files for scmframework
if you want to use a touchscreen, then most likely you will have to use the original display models from SComputers, you can download them and embed them in your mod
if you use scmframework in your mod, then leave a message about it in the description with a link to this page
scmframework demo
this mod demonstrates the capabilities of scmframework
the scmframework allows you to use SComputers features inside your mods
it's completely free and anyone can use the scmframework to create their own mods
if you only need displays from SComputers, then you can use canvasAPI
the scmframework contains canvasAPI inside itself
scmframework.scomputers - SComputers API for creating addons, it is not available here through sm.scomputers
scmframework.dofile(path) - the dofile of the scmframework. It can load not only real files, but also files packaged inside the framework
scmframework.scmframeworkClass - the class that you need to inherit from in order to add virtual shapes from SComputers to your shape
scmframework.defaultSettings - standard mod settings
scmframework.unrestrictedSettings - mod settings that disable lag protection, motors resource consumption, and component connectivity checks during operation. recommended when using the framework. does not activate unsafe mode by itself by default
scmframework.setSComputersSettings(settings) - changes SComputers settings. you can use the standard preset or create your own custom settings table
scmframeworkClass callbacks
scmframeworkClass.scmframework_init - it is called on the server and on the client when creating the block. from here, you need to set the configuration, create the necessary virtual blocks and the connections between them.
scmframeworkClass methods
scmframeworkClass:addVirtualShape(class, scriptedData:table|nil, defaultStorage:table|nil):virtualShape - creates a virtual shape
scmframeworkClass:addVirtualComputer(defaultScript:string|nil, defaultData:string|nil, alwaysOn:boolean|nil, unsafe:boolean|nil, localEnvHook:function(self, env)):virtualShape - creates a virtual computer. you can specify the default script and the default state of the data section (accessed via setData/getData) as a string (not a path)
you can also create unsafe computer, it will always be able to write to the chat and will always work in unsafe mode with full access. anti-lag will not be applied to it, and the CPU time limit will be at least 40 ticks, regardless of the SComputers configuration
you can pass a function to create an ENV hook. please note that in this case your ENV hook can also be called on the client when using clientInvoke in unsafe mode
scmframeworkClass:addVirtualClassicDisplay(width:number, height:number):virtualShape - creates a virtual display shape. made specifically for use with a 3D model of the display from SComputers itself and therefore does not require specifying the size. allows you to use the touchscreen when using the SComputers model. When using, make sure that the aspect ratio of the resolution corresponds to the actual aspect ratio of the 3D model used
scmframeworkClass:addVirtualSynthesizer():virtualShape - creates a virtual synthesizer shape
scmframeworkClass:addVirtualGps():virtualShape - creates a virtual gps shape
virtualShape methods
virtualShape:interact(character, state) - simulates pressing the E button on shape
virtualShape:tinker(character, state) - simulates pressing the U button on shape
virtualShape:canInteract(character):boolean - returns true if shape can handle the E button at the moment
virtualShape:canTinker(character):boolean - returns true if shape can handle the U button at the moment
virtualShape:createVirtualLink(child) - makes a virtual connection within one shape between two virtual shapes. although in most cases the direction of virtual communication does not matter, it is better to do it in the direction of how the components connect to real SComputers, otherwise not all components may work correctly
virtualShape:setOpenedOutput(boolean) - makes the output "open" and allows the virtual shape to interact with the real shapes (default: false)
virtualShape:setOpenedInput(boolean) - makes the input "open" and allows the virtual shape to interact with the real shapes (default: false)
virtual computer methods
virtualShape:getEnv():table - returns the ENV table. use this to read the table only, use localEnvHook for writing, as the table can be recreated at any time (for example, during reboot)
virtualShape:reboot() - reboot the computer
virtualShape:setActive(boolean) - activates the computer. Instead, the computer can be activated using the always on flag at creation or by using a real logic signal from outside if its input is open using setOpenedInput
virtualShape:isActive():boolean - returns true if the computer is currently running
dofile("$CONTENT_DATA/Scripts/scmframework.lua")
scmtest = class(scmframework.scmframeworkClass)
function scmtest:scmframework_init()
--although the code is declared as constant here, it is not constant and can be changed via "setCode" inside the program. just like it happens in regular SComputers
self.computer = self:addVirtualComputer([[local colors = require("colors")
local display = getComponent("display")
local synthesizer = getComponent("synthesizer")
function onStart()
synthesizer.stopLoops()
synthesizer.startLoop(1, "chapter2_alarm", {alarm = 2})
end
function onTick()
local width = display.getWidth()
local height = display.getHeight()
for x = 0, width - 1 do
display.fillRect(x, 0, 1, height, colors.combineColorToNumber(x / (width - 1), colors.pack(colors.hsvToRgb256(255 - (getUptime() % 256), 255, 255)), colors.pack(colors.hsvToRgb256(getUptime() % 256, 255, 255))))
end
display.flush()
end
function onStop()
display.clear()
display.flush()
synthesizer.stopLoops()
end
_enableCallbacks = true]], nil, true)
self.display = self:addVirtualDisplay(128, 64, 1, 1.2)
self.computer:createVirtualLink(self.display)
self.synthesizer = self:addVirtualSynthesizer()
self.computer:createVirtualLink(self.synthesizer)
end
--[[
--you can allow the user to open the computer code if you uncomment this:
function scmtest:client_onInteract(character, state)
self.computer:interact(character, state)
end
]]