packages: Difference between revisions

From Onset Developer Wiki
No edit summary
No edit summary
Line 7: Line 7:
==Lua context==
==Lua context==
Each package has their own LuaVM state. Lua script files that are loaded in the same package can access the same global variables.
Each package has their own LuaVM state. Lua script files that are loaded in the same package can access the same global variables.
Variables defined as ''local'' are only visible in that single .lua file.


You can export functions from one package and import them in another package. See [[AddFunctionExport]] and [[ImportPackage]].
You can export functions from one package and import them in another package. See [[AddFunctionExport]] and [[ImportPackage]].
Line 12: Line 13:


==Folder layout==
==Folder layout==
Each package has a folder that is placed inside the '''packages''' folder on your server.
Each package has a folder that is placed inside the '''packages''' folder on your server. Example layout:
<pre>
<pre>
OnsetServer.exe
OnsetServer.exe
Line 20: Line 21:
             package.json
             package.json
         /mapeditor
         /mapeditor
            package.json
             /client
             /client
                 editor.lua
                 editor.lua
             /server
             /server
                 server.lua
                 server.lua
            package.json
</pre>
</pre>


Line 54: Line 55:


== Client package cache ==
== Client package cache ==
Files downloaded from a server are being cached on the client in this folder: '''%appdata%\..\Local\Horizon\Saved\ServerContent
Files downloaded from servers are being cached on the client in the folder: '''%appdata%\..\Local\Horizon\Saved\ServerContent


That way files are only downloaded once. If you change a file on the server the checksum of it will change. In this case the client will be downloaded again by the client.
That way files are only downloaded once. If you change a file on the server the checksum of it will change. In this case the client will be downloaded again by the client.
The ''server.json'' file stores information of the server from where the files have been downloaded from.
The ''server.json'' file stores information of the server from where the files have been downloaded from.

Revision as of 16:35, 26 September 2019

A package is collection of Lua scripts and other files. You can have up to 32 packages and 255 files per package on your server.

Allowed file type extensions: lua, js, css, html, htm, png, jpg, jpeg, gif, wav, mp3, ogg, oga, flac, woff2, ttf, pak

Example packages: https://github.com/BlueMountainsIO/OnsetLuaScripts

Lua context

Each package has their own LuaVM state. Lua script files that are loaded in the same package can access the same global variables. Variables defined as local are only visible in that single .lua file.

You can export functions from one package and import them in another package. See AddFunctionExport and ImportPackage. This enables you to create packages that act as pure libraries.

Folder layout

Each package has a folder that is placed inside the packages folder on your server. Example layout:

OnsetServer.exe
server_config.json
    /packages
        /mypackagename
            package.json
        /mapeditor
            package.json
            /client
                editor.lua
            /server
                server.lua

package.json

Your package.json defines server and client script files. It also defines what files are required for this package to work. Files defined in client_scripts and files are being downloaded by clients once they join the game server.

{
	"author": "Blue Mountains",
	"version": "1.0",
	"server_scripts": [
		"server/editor.lua"
	],
	"client_scripts": [
		"client/editor.lua"
	],
	"files": [
		"client/gui/editor.html",
		"client/gui/editor.css",
		"client/gui/editor.js",
		"client/gui/jquery.js",
		"client/gui/OpenSansRegular.woff2",
		"client/gui/OpenSansBold.woff2"
	]
}

Each package has a package.json in it's root path. See the folder layout above. Additionally you have to tell the server what packages exist. See server_config to configure that.

Client package cache

Files downloaded from servers are being cached on the client in the folder: %appdata%\..\Local\Horizon\Saved\ServerContent

That way files are only downloaded once. If you change a file on the server the checksum of it will change. In this case the client will be downloaded again by the client. The server.json file stores information of the server from where the files have been downloaded from.