8.3 KiB
Laptop Mod API
Add new hardware nodes
laptop.register_hardware(name, hwdef)
name
- Item name (prefix) The created node names are name_varianthwdef.description
- Computer item namehwdef.hw_infotext
- Text shown if node is pointedhwdef.sequence
= { "variant_1_name", "variant_2_name", "variant_3_name" } On punch swaps sequence. the first variant is in creative inventoryhwdef.custom_launcer
- optional - custom launcher namehwdef.custom_theme
- optional - custom initial theme namehwdef.hw_capabilities
= { "hdd", "floppy", "usb", "net", "liveboot" } Table with hardware capabilities. Default is all, if nothing sethwdef.node_defs
- A list for node definitions for each variant. with hw_state parameter for OS-initialization
hwdef.node_defs = {
variant_1_name = {
hw_state = "resume", "power_on" or "power_off", -- Hardware state
--node 1 definiton
},
variant_2_name = {
hw_state = "resume", "power_on" or "power_off", -- Hardware state
--node 2 definiton
},
}
laptop.os_get(pos)
- Get an OS object. Usefull in on_construct or on_punch to initialize or do anything with OS Needed in on_receive_fields to be able to call mtos:receive_fields(fields, sender) for interactive appslaptop.after_place_node
/laptop.after_dig_node
- (optional) can be used directly for node definition. Move laptop apps data to ItemStack if digged and restored back if placed again. So you can take along your laptop. Note: you need to setstack_max = 1
because the data can be stored per stack only, not per item.
Operating system object
local mtos = laptop.os_get(pos)
- Get the Operating system object. Used internally, but usable for remote operations. mtos is passed to app methods as parameter
Operating system methods
mtos:power_on(new_node_name)
- Free RAM, activate the launcher and if given swap node to new_node_namemtos:resume(new_node_name)
- Restore the last running app after power_off. Means no free ram and no switch to launcher. Update formspec and if given swap node to new_node_namemtos:power_off(new_node_name)
- Remove the formspec and if given swap node to new_node_namemtos:swap_node(new_node_name)
- Swap the node only without any changes on OSmtos:set_infotext(infotext)
- Set the mouseover infotext for laptop nodemtos:get_app(appname)
- Get the app instancemtos:set_app(appname)
- Start/Enable/navigate to appname. If no appname given the launcher is calledmtos:get_theme(theme)
- Get theme data current or requested (theme parameter is optional)mtos:set_theme(theme)
- Activate thememtos:save()
- Store all app-data to nodemeta. Called mostly internally so no explicit call necessarymtos:pass_to_app(method, reshow, sender, ...)
- call custom "method" on app object. Used internally. Reshow means update formspec after update
Operating system attributes
`mtos.pos` - Computers position vector
`mtos.node` = minetest.get_node(pos)
`mtos.hwdef` = Merged hardware definition (Hardware + Hardware node attributes merged to 1 object)
`mtos.meta` = Nade meta - mostly managed by block device framework
`mtos.bdev` = Block device framework object
`mtos.sysram` = System/OS ram partition, mtos.bdev:get_app_storage('ram', 'os')
`mtos.sysdata` = System/OS data partition, mtos.bdev:get_app_storage('system', 'os')
`mtos.theme` = Selected theme object
Apps
Definition attributes
laptop.register_app(internal_shortname, { definitiontable })
- add a new app or view
app_name
- App name shown in launcher. If not defined the app is just a view, not visible in launcher but can be activated. This way multi-screen apps are possibleapp_icon
- Icon to be shown in launcher. If nothing given the default icon is usedapp_info
- Short app info visible in launcher tooltipfullscreen
- (boolean) Do not add app-background and window buttonsview
- (boolean) The definition is a view. That means the app/view is not visible in launcherformspec_func(app, mtos)
- Function, should return the app formspec (mandatory) During definition the "app" and the "mtos" are availableappwindow_formspec_func(launcher_app, app, mtos)
- Only custom launcher app: App background / Window decorations and buttonsreceive_fields_func(app, mtos, sender, fields)
Function for input processing. The "app" and the "mtos" are available inside the callallow_metadata_inventory_put(app, mtos, player, listname, index, stack)
- Optional: custom actions on item putallow_metadata_inventory_take(app, mtos, player, listname, index, stack)
- Optional: custom actions on item takeallow_metadata_inventory_move(app, mtos, player, from_list, from_index, to_list, to_index, count)
- Optional: custom actions on item moveon_metadata_inventory_put(app, mtos, player, listname, index, stack)
- Optional: custom check on items puton_metadata_inventory_take(app, mtos, player, listname, index, stack)
- Optional: custom check on items puton_metadata_inventory_move(app, mtos, player, from_list, from_index, to_list, to_index, count)
- Optional: custom check on items put
laptop.register_view(internal_shortname, { definitiontable })
- add a new app or view
same as register_app, but the view flag is set. app_name and app_icon not necessary
App Object
local app = mtos:get_app(appname)
- Give the app object internal_shortname, connected to given mtos. Not necessary in formspec_func or receive_fields_func because given trough interface
app:back_app()
- Go back to previous app/viewapp:exit_app()
- Delete call stack and return to launcher
Themes
Theme definition
laptop.register_theme(name, definitiontable)
- add a new theme. All parameters optional, if missed, the default is used
Definitiontable:
launcher_bg
Launcher background imageapp_bg
Apps background imagecontrast_bg
dark background to place under white text elements that does not support textcolortextcolor
Default text color for buttons and labels. For buttons the major_textcolor and minor_textcolor supportedback_button
Back Button imageexit_button
Exit button imageapp_button
App button background in launchermajor_button
Major (highlighted) button imageminor_button
Minor button imagenode_color
Palette number to set if the node is paramtype2 = "colorfacedir"
Theme methods
function laptop.get_theme(theme_name)
theme:get_button(area, prefix, code, text)
get a themed [prefix]_button in area 'x,y;w,h' with code an texttheme:get_label(pos, text)
get a themed label text starting at pos 'x,y'
Block devices / Data objects
mtos.bdev = laptop.get_bdev_handler(mtos)
Low-Level methods
Can be used for non-data and/or system tasks. For usual data store please use the storage methods
bdev:get_ram_disk()
ram store - a table with all app-related storage partitionsbdev:get_hard_disk()
hdd store - a table with all app-related storage partitions, if hard disk capatibility existsbdev:get_removable_disk()
removable data object (drive)bdev:get_cloud_disk(store_name)
- Get named cloud storagebdev:sync()
- Write/store all opened and maybe changed data
Storage methods
get_boot_disk()
- Check which device can be booted. possible return value is "hdd" or "removable"get_app_storage(disk_type, store_name)
- Get data storage table to be used in apps.- disk_type can be 'ram', 'hdd', 'removable', 'cloud' or 'system'. System is eather hdd or removable storage depending on booted device
- store_name is usually the app name. 'os' is reserved for System related saves
Low-level Removable data
data = bdev:get_removable_disk()
bdev.inv
- node inventory (the slot)bdev.label
- Meda label. Item name by defaultbdev.def
- Registered item definition (read-only)bdev.stack
- The item stackbdev.meta
- Stack metadatabdev.os_format
- The format type: "none", "boot", "backup", "filesystem" (read-only)bdev.rtype
- Removable type. "usb" or "floppy"bdev.storage
- Data table used for app storage, if format is data compatiblebdev:reload()
- Reload all data from node inventory
Compatible Items
There is no own compatible items registrator. The item needs to match the item group to be usable with the laptops
laptop_removable_floppy = 1
- The item is a floppylaptop_removable_usb = 1
- The item is usb storage disk