-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
115 lines (94 loc) · 4.6 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
--[[-- Ubiquitousse main module.
Set of various Lua libraries to make game development easier, mainly made to be used alongside the [LÖVE](https://love2d.org/) game framework.
Nothing that hasn't been done before, but these are tailored to what I need. They can be used independently too, and are relatively portable, even without LÖVE.
This is the main module, which will try to load every other Ubiquitousse module when required,
and also perform a quick LÖVE version check and show a warning in case of potential incompatibility.
**Regarding Ubiquitousse's organization**
Ubiquitousse may or may not be used in its totality. You can delete the modules directories you don't need and Ubiquitousse
should adapt accordingly. You can also simply copy the modules directories you need and use them directly, without using this
file at all.
However, some modules may provide more feature when other modules are available.
These dependencies are written at the top of every main module file.
Ubiquitousse's original goal was to run everywhere with the least porting effort possible, so while the current version now mainly focus LÖVE, it
should still be easily modifiable to work with something else. Ubiquitousse is mainly tested on LuaJIT and Lua 5.3 but should also support Lua 5.1 and 5.2.
In order to keep a good idea of how portable this all is, other dependencies, including LÖVE, are explicited at the top of every module file and in specific
functions definition using the `@require` tag (e.g., `-- @require love` for LÖVE).
Some modules are developped in [Candran](https://github.com/Reuh/candran) (`.can` files), but can easily be compiled into regular Lua code. In fact,
you will find precompiled Lua files in the ubiquitousse repository alongside the Candran files, so you don't have to install Candran yourself and everything
should be pretty much plug and play.
Regarding the documentation: Ubiquitousse uses LDoc/LuaDoc styled-comments, but since LDoc hates me and my code, the
generated result is mostly garbage, so to generate the documentation you will need to use my [LDoc fork](https://github.com/Reuh/LDoc)
which I modified to force LDoc to like me.
If you want to recompile the Candran files or the documentation yourself, there's a build script `make` available at the root of
the repository to save you a few seconds.
Units used in the API documentation, unless written otherwise:
* All distances are expressed in pixels (px)
* All durations are expressed in seconds (s)
These units are only used to make writing documentation easier; you can use other units if you want, as long as you're consistent.
Style:
* tabs for indentation, spaces for esthetic whitespace (notably in comments)
* no globals
* UPPERCASE for constants (or maybe not).
* CamelCase for class names.
* lowerCamelCase is expected for everything else.
@module ubiquitousse
@usage local ubiquitousse = require("ubiquitousse")
--]]
local p = ... -- require path
local ubiquitousse
ubiquitousse = {
--- Ubiquitousse version string (currently `"0.1.0"`).
version = "0.1.0",
--- Asset manager module, if available.
-- @see asset
asset = nil,
--- Entity Component System, if available.
-- @see ecs
ecs = nil,
--- Input management, if available.
-- @see input
input = nil,
--- LDtk level import, if available.
-- @see ldtk
ldtk = nil,
--- glTF model import, if available.
-- TODO: documentation not currently generated with LDoc.
-- @see gltf
gltf = nil,
--- Scene management, if available.
-- @see scene
scene = nil,
--- Signal management, if available.
-- @see signal
signal = nil,
--- Timer utilities, if available.
-- @see timer
timer = nil,
--- Various useful functions, if available.
-- @see util
util = nil
}
-- Check LÖVE version
local madeForLove = { 11, "x", "x" }
local actualLove = { love.getVersion() }
for i, v in ipairs(madeForLove) do
if v ~= "x" and actualLove[i] ~= v then
local txt = ("Ubiquitousse was made for LÖVE %s.%s.%s but %s.%s.%s is used!\nThings may not work as expected.")
:format(madeForLove[1], madeForLove[2], madeForLove[3], actualLove[1], actualLove[2], actualLove[3])
print(txt)
love.window.showMessageBox("Compatibility warning", txt, "warning")
break
end
end
-- We're going to require modules requiring Ubiquitousse, so to avoid stack overflows we already register the ubiquitousse package
package.loaded[p] = ubiquitousse
-- Require external submodules
for _, m in ipairs{"signal", "asset", "ecs", "input", "scene", "timer", "util", "ldtk", "gltf"} do
local s, t = pcall(require, p.."."..m)
if s then
ubiquitousse[m] = t
elseif not t:match("^module [^n]+ not found") then
error(t)
end
end
return ubiquitousse