Skip to content

Commit 228a4d6

Browse files
committed
chore(scripts): improve doc_gen.py
1 parent eb78dea commit 228a4d6

21 files changed

Lines changed: 237 additions & 344 deletions

CONTRIBUTING.md

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
# Introduction
2+
3+
SmallBase is a lightweight Lua framework designed to provide developers with the tools and foundations to create their own scripts, without imposing specific features.
4+
5+
With that out of the way, thank you for considering contributing to this small project. It's people like you that make these open source projects great!
6+
7+
## Commit Convention
8+
9+
These are recommended, but not enforced yet. SmallBase follows similar commit guidelines to [YimMenu](https://github.com/Mr-X-GTA/YimMenu/blob/master/CONTRIBUTING.md):
10+
11+
### Commit Structure
12+
13+
```text
14+
<type>(scope): <description>
15+
16+
[optional body]
17+
18+
[optional footer]
19+
```
20+
21+
- **Types (lowercase only):**
22+
- feat: New features.
23+
- fix: Bug fixes.
24+
- style: Feature and updates related to styling.
25+
- refactor: Refactoring a specific section of the codebase.
26+
- test: Everything related to testing.
27+
- docs: Everything related to documentation.
28+
- chore: Regular code maintenance.
29+
30+
- **Scope:**
31+
- A scope is a phrase describing parts of the code affected by the changes. For example `(translations)`.
32+
33+
- **Body (Optional):**
34+
- The commit body can provide additional contextual information. For breaking changes, the body MUST start with "BREAKING CHANGE".
35+
36+
- **Footer (Optional):**
37+
- A commit footer is used to reference issues affected by the code changes. For example: "Fixes #13". It can also be used to indicate breaking changes by starting with "BREAKING CHANGE".
38+
39+
- **Example:**
40+
41+
```text
42+
fix(SomeFeature): fix constructor returning an empty object.
43+
docs(Readme): document coding conventions
44+
```
45+
46+
## Coding Standards
47+
48+
### Annotations
49+
50+
Annotate all enums, classes, and class methods using [LuaLS](https://luals.github.io/wiki/annotations/)'s style.
51+
52+
Annotations are critical for readability, code completion, error checking, and automatic generation of class documentations.
53+
54+
For comments/summaries/descriptions, you can use as many dashes as you want but please leave a space between the last dash and the text.
55+
56+
- **Example:**
57+
58+
```lua
59+
-- Calculates the sum of two numbers.
60+
---@param a number The first number
61+
---@param b number The second number
62+
---@return number The sum of both numbers
63+
function MyClass:Add(a, b)
64+
return a + b
65+
end
66+
```
67+
68+
### Global Variables
69+
70+
There are two ways to declare globals:
71+
72+
1. Globals that should be serialized to JSON:
73+
Index SmallBase's `GVars` table. Even if the variable was never declared before:
74+
75+
```lua
76+
GVars.some_feature_enabled, _ = ImGui.Checkbox("My Checkbox", GVars.some_feature_enabled)
77+
```
78+
79+
2. Regular globals:
80+
Use Lua's default global table `_G`:
81+
82+
```lua
83+
some_global_number = 123
84+
```
85+
86+
### Style
87+
88+
You are free to use any style you want, except in these cases:
89+
90+
| Scope | Naming | Example |
91+
| ----------- | ----------- | ---------- |
92+
| Global Functions | PascalCase | `function DoSomething(...) end` |
93+
| Local Functions | any (consistent) | You are free to use any style as long as it stays consistent throughout the whole file |
94+
| Standard Lib Extensions | Use the lib's default style | `string.somefunc = function(...) end` |
95+
| Enums | PascalCase prefixed with a lowercase `e` | `eExampleEnum` |
96+
| Enum Members | Preferably UPPER_SNAKE_CASE but PascalCase is also allowed | `eExampleEnum.SOME_MEMBER`/`eExampleEnum.SomeMember` |
97+
| Classes | PascalCase | `MyNewClass = Class("MyNewClass")` |
98+
| Class Methods | PascalCase | `function MyNewClass:ExampleMethod(...) end` |
99+
| Class Private Variables | snake_case prefixed with an `m` | `m_handle` |
100+
101+
### Formatting
102+
103+
- **Indentations:**
104+
- Does not matter. If using tabs, make sure one tab equals **four** spaces.
105+
106+
- **Line Wrapping:**
107+
- Try to wrap wide lines using either your IDE's formatter or a Pythonic way.
108+
109+
- Example:
110+
111+
```lua
112+
SomeFunc(param1, param2, param3, param4, param5, param6, param7, param8, param9, ...)
113+
```
114+
115+
- Preferred (Pythonic) style:
116+
117+
```lua
118+
SomeFunc(
119+
param1,
120+
param2,
121+
param3,
122+
param4,
123+
param5,
124+
param6,
125+
param7,
126+
param8,
127+
param9,
128+
...
129+
)
130+
```
131+
132+
- **Nested `if` Statements:**
133+
134+
- Always try to use guarded if statements when applicable.
135+
136+
- Example:
137+
138+
```lua
139+
local cond_1 = false
140+
local cond_2 = nil
141+
local cond_3 = true
142+
143+
if cond_1 then
144+
if cond_2 then
145+
if cond_3 then
146+
DoSomething()
147+
end
148+
end
149+
end
150+
```
151+
152+
- Preferred approach:
153+
154+
```lua
155+
local cond_1 = false
156+
local cond_2 = nil
157+
local cond_3 = true
158+
159+
if not cond_1 then
160+
return
161+
end
162+
163+
if not cond_2 then
164+
return
165+
end
166+
167+
if not cond_3 then
168+
return
169+
end
170+
171+
DoSomething()
172+
```
173+
174+
- Shorter version:
175+
176+
```lua
177+
local cond_1 = false
178+
local cond_2 = nil
179+
local cond_3 = true
180+
181+
if not (cond_1 and cond_2 and cond_3) then
182+
return
183+
end
184+
185+
DoSomething()
186+
```
187+
188+
## What To Avoid
189+
190+
Avoid adding end-user features directly to the project (example: A drift minigame, a business manager, animations, etc.).
191+
192+
SmallBase is, as the name suggests, a base. It provides the tools and the foundations to create new scripts.
193+
194+
Two scripts can both use this project as a template and offer completely different sets of features.
195+
196+
If you want to share a feature, make it a standalone module that uses SmallBase.

SmallBase/includes/lib/compat.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
-- Basic compatibility layers/API stubs
22
---@diagnostic disable: lowercase-global
33

4-
---@class Compat
54
local Compat = {}
65
Compat.__index = Compat
76

SmallBase/includes/lib/mock_env.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ end
3131

3232
if (not io["exists"]) then
3333
io.exists = function(filepath)
34-
local f, _ = io.open(filepath, "r")
35-
if not f then
34+
local ok, f = pcall(io.open, filepath, "r")
35+
if not ok or not f then
3636
return false
3737
end
3838

SmallBase/includes/modules/Color.lua

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
--------------------------------------
44
-- Class: Color
55
--------------------------------------
6+
-- Color instances can be created using color names defined in `Color.string_colors`,
7+
-- self-regsitered color names (using the `RegisterNamedColor` method),
8+
-- hex strings, ABGR uint_32, RGBA floats (0 - 1), and RGBA numbers (0 - 255).
69
---@class Color
710
---@overload fun(...): Color
811
Color = Class("Color")
@@ -25,6 +28,7 @@ Color.string_colors = {
2528
["purple"] = { 1.0, 0.0, 1.0, 1.0 },
2629
}
2730

31+
---@ignore
2832
function Color:__tostring()
2933
if not self.value or not self.type then
3034
return string.format(
@@ -61,10 +65,12 @@ function Color:__tostring()
6165
)
6266
end
6367

68+
---@ignore
6469
function Color:print()
6570
print(self:__tostring())
6671
end
6772

73+
---@ignore
6874
function Color:GetValue()
6975
if not self.type or not self.arg or not self.arg[1] then
7076
return "None"
@@ -165,16 +171,14 @@ function Color.new(...)
165171
end
166172

167173
-- Allows you to register new named colors in the Color class itself
168-
--
169-
-- that you can call later using `Color.new("your_custom_color_name")`
174+
-- that you can call later using `Color("your_custom_color_name")`
170175
--
171176
-- Example usage:
172177
--
173-
-- Color:RegisterNamedColor("Magenta", "#FF00FF")
174-
--
175-
-- You can then use it like so:
176-
--
177-
-- local r, g, b, a = Color.new("Magenta"):AsRGBA()
178+
-- ```lua
179+
-- Color:RegisterNamedColor("Magenta", "#FF00FF")
180+
-- local r, g, b, a = Color("Magenta"):AsRGBA()
181+
-- ```
178182
---@param name string
179183
---@param ... any
180184
function Color:RegisterNamedColor(name, ...)
@@ -249,6 +253,7 @@ function Color:AsRGBA()
249253
end
250254

251255
-- Returns a color in float format.
256+
---@return float, float, float, float
252257
function Color:AsFloat()
253258
if not self.type then
254259
return 0, 0, 0, 0
@@ -262,6 +267,8 @@ function Color:AsFloat()
262267
end
263268
end
264269

270+
-- Returns a color hex string.
271+
---@return string|nil
265272
function Color:AsHex()
266273
if not self.type then
267274
return
@@ -275,7 +282,7 @@ function Color:AsHex()
275282
end
276283
end
277284

278-
-- Returns a uint32 color in **ABGR** format.
285+
-- Returns a uint_32 color in **ABGR** format.
279286
---@return number
280287
function Color:AsU32()
281288
if not self.type then
@@ -290,14 +297,16 @@ function Color:AsU32()
290297
end
291298
end
292299

300+
---@ignore
293301
function Color:serialize()
294302
return { __type = "color", arg = self.arg }
295303
end
296304

305+
---@ignore
297306
function Color.deserialize(t)
298307
if (type(t) ~= "table" or not t.arg) then
299308
log.warning("[Color]: Deserialization failed: invalid data!")
300-
return Color.new(0, 0, 0, 1)
309+
return Color.new("black")
301310
end
302311

303312
return Color.new(t.arg)

SmallBase/includes/modules/Decorator.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
--------------------------------------
44
-- **Global Singleton.**
55
--
6-
-- - Custom decorator to mark entities owned by this script.
6+
-- Custom decorator to mark entities owned by this script.
77
---@class Decorator
88
Decorator = {}
99
Decorator.RegisteredEntities = {}

SmallBase/includes/modules/Memory.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--------------------------------------
22
-- Class: Memory
33
--------------------------------------
4-
--[[**Global Singleton.**]]
4+
--**Global Singleton.**
55
---@class Memory
66
Memory = {}
77
Memory.__index = Memory

SmallBase/includes/modules/Object.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
--
66
-- **Parent:** `Entity`.
77
--
8-
-- - Class representing a GTA V object (Unfinished).
8+
-- Class representing a GTA V object (Unfinished).
99
---@class Object : Entity
1010
---@overload fun(handle: integer): Entity
1111
Object = Class("Object", Entity)

SmallBase/includes/modules/Ped.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
--
66
-- **Parent:** `Entity`.
77
--
8-
-- - Class representing a GTA V NPC.
8+
-- Class representing a GTA V NPC.
99
---@class Ped : Entity
1010
---@field private layout CPed
1111
---@field Create fun(_, modelHash: number, entityType: eEntityTypes, pos?: vec3, heading?: number, isNetwork?: boolean, isScriptHostPed?: boolean): Ped

SmallBase/includes/modules/Self.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
--
88
-- **Parent:** `Player`.
99
--
10-
-- - Class representing the local player.
10+
-- Class representing the local player.
1111
---@class Self: Player
1212
Self = Class("Self", Player)
1313
Self.new = nil

SmallBase/includes/modules/Time.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
--------------------------------------
88
-- Class: Time
99
--------------------------------------
10-
-- **Global Singleton.**
10+
--**Global Singleton.**
1111
---@class Time
1212
local Time = {}
1313
Time.__index = Time

0 commit comments

Comments
 (0)