in fact, this block simply allows you to read a json file, the path to which you previously specified in the rom disk menu. being in "safe mode"
this block is just a more realistic alias to sm.json.open, however, it does not allow you to read any json file. you can only read the file the path to which you have manually specified in the disk menu
this disk can be used as an alternative to sm.json.open in safe mode
you need it so that you can upload large amounts of data along with your creation to the steam workshop
just put your json in the blueprint folder of your creation and specify the path to it in the ROM disk menu
a ROM disk does not have its own filesystem
to upload binary files to this disk, you can use the "importer" utility written in python, which is in mod along the path: USER/importer
this program collects all files from the files folder into a json file where all files are represented as base64 strings
this program allows you to import files as on a regular disk (using the import button in the disk menu) the same applies to the ROM disk (by moving the json to the blueprint folder)
after the first successful read from rom.open, the disk caches the result
to clear the cache, you can open the disk menu and click "done", re-enter into the world, or call the rom.clearCache Disk method.
UPDATED: you can now interpret the contents of a ROM disk as a filesystem and work with it through the API of a regular disk.
component name - rom
guide:
- 1. save your creation on blueprint
- 2. remove your creation from the world (so as not to get confused)
- 3. create your own json file with the data
- 4. open the folder with your creation (usually the folder with all the blueprints is located along the path: C:\Users\User\AppData\Roaming\Axolot Games\Scrap Mechanic\User\User_XXXXXXXXXXXXXXXXX\Blueprints)
- 5. find the folder with your creation and put your json there (read the description.json to make sure that you are putting the json file in the same blueprint as the ROM disk. if this is not the case, the disk will work for you, but it will not work for subscribers of your creation)
- 6. remember the UUID of your creation and the name of your json file
- 7. load your creation from blueprint and find your ROM disk on it. specify the path to your json in it (it should look something like this: $CONTENT_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/rom.json) DO NOT REMOVE YOUR CREATION FROM THE LIFT BEFORE YOU SAVE IT!
- 8. save your creation to blueprint again UNDER THE SAME NAME WITH OVERWRITING!! this is very important, without it, if you post your creation, subscribers will not get access to the data in json
- 9. as a result, it should turn out that your creation has a json file with the data you need, and it also has a ROM disk where the path to this json is indicated, where the UUID of this creation itself is located
warnings:
- 1. make sure that you do not have duplicate creations with the same name. as this may cause the ROM disk to work for you. but it won't be able to find the file from other people when you publish the creation
- 2. a creation with a duplicate name usually occurs when you insert a name instead of manually entering the name of the creation during rewriting. in this case, despite the appearance of a menu with a rewrite request, a new instance with the same name is created. what can cause you to put a file in a folder with one creation and accidentally publish another
- 3. make sure that you put the file in the folder with your creation and not another one. as this will result in the file not being found by subscribers
methods:
- rom.open() - returns the result of sm.json.open with the path specified in the ROM disk menu. please note that reading is only possible in the file that was manually specified in the rom menu
- rom.openFilesystemImage():diskapi - tries to interpret json as a disk image from the importer program that comes with the mod. returns an API identical to the regular disk component, except that it is not writable (isReadOnly returns true)
- rom.openFilesystemDump():diskapi - it works the same way as rom.openFilesystemImage() but accepts json in dump format from the ramfs library
- rom.clearCache() - clears the rom disk cache
- rom.isAvailable():boolean - returns true if the contents of the ROM disk can be read and false if it does not specify the file path or is incorrect
reading binary files made by the importer program:
local nbs = require("nbs")
local synthesizers = getComponents("synthesizer")
local rom = getComponent("rom") --specify the path in the ROM disk: $CONTENT_DATA/ROM/gamedisks/nbs.json (the path to the files of the standard nbs example in SComputers)
local disk = rom.openFilesystemImage() --interprets the contents of a ROM disk as a filesystem
local player = nbs.create()
--player.instrumentTable = {} --uncomment if you want everything to be played with one instrument
player:load(disk, "tetrisA.nbs")
player:setSynthesizers(synthesizers)
player:setSpeed(1)
player:setNoteShift(-39)
player:setNoteAligment(1)
player:setVolume(0.1)
player:setDefaultInstrument(4)
player:setNoteDuration(0) --you can try to increase this value if your chosen NBS is playing poorly on standard settings
function callback_loop()
if _endtick then
player:stop()
return
end
if not player:isPlaying() then
player:start()
end
player:tick()
end