Skip to content

Commit f18c945

Browse files
authored
docs: Update code_guidance.md (#201)
Mostly formatting, added point_and_click, will add more over time
1 parent b60cf7b commit f18c945

File tree

1 file changed

+89
-26
lines changed

1 file changed

+89
-26
lines changed

docs/code_guidance.md

Lines changed: 89 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,102 @@
11
Coders guidance
22
add to as you see fit, but try to keep doc easy to use
33

4-
Useful functions:
5-
TTRPG_stats(faction, comp, mar, class = "marine")
6-
creates a new unit struct see scr_marine_struct.gml for more info
74

8-
9-
unit_Struct.name_role()
10-
provides a string representation of the unit name combined with the unit role
11-
taking into account the unit role display name as provided by the units squad type
12-
13-
scr_random_marine(argument0, argument1)
14-
selects a random player unit within the parameters given
15-
if no marine is available with give parameters returns "none"
16-
17-
18-
keys and data:
5+
### keys and data:
196
faction key:
207
imperium:2
218
mechanics:3
229
inquisition:4
2310
sororities:5
2411

25-
26-
Visual and draw functions
27-
28-
tooltip_draw(x,y,tooltip_text)
29-
creates a hover over tool tip at the given coordinate where:
30-
x is the left most point of the tooltip box
31-
y is the topmost point of the tooltip box,
32-
tooltip_text is the text to display (text should be preformatted e.g string_hash_to_newline() to create lines)
33-
34-
scr_convert_company_to_string(marine company)
35-
returns a sting representation of a marines compant
36-
How does combat work?????
12+
# Useful functions:
13+
14+
## Common functions
15+
Creating a Marine
16+
```gml
17+
/// @function TTRPG_stats
18+
/// @description creates a new unit struct see scr_marine_struct.gml for more info
19+
/// @param {array} rect x1, y1, x2, y2 array.
20+
/// @returns {bool}
21+
function TTRPG_stats(faction, comp, mar, class = "marine", other_spawn_data={})
22+
```
23+
Display a marine's role
24+
```gml
25+
/// provides a string representation of the unit name combined with the unit role
26+
/// taking into account the unit role display name as provided by the units squad type
27+
unit_Struct.name_role()
28+
```
29+
Get a random marine with filter
30+
```gml
31+
/// selects a random player unit within the parameters given
32+
/// @param {Real|Array[Real]} role id or list of ids e.g. 2 = Honour Guard
33+
/// @param {Real} exp_req minimum exp requirement
34+
/// @param {String|Struct} search_params attributes to search for
35+
/// if params is a struct, can use traits or stats as part of the search
36+
/// if no marine is available with give parameters returns "none"
37+
function scr_random_marine(role, exp_req, search_params="none")
38+
/// @example - finding a random chaplain candidate
39+
random_marine=scr_random_marine([obj_ini.role[100][8],obj_ini.role[100][18],obj_ini.role[100][10],obj_ini.role[100][9]],60,{"stat":[["piety", 35, "more"],["charisma", 30, "more"]]});
40+
```
41+
42+
## Visual and draw functions
43+
44+
Click handling
45+
```gml
46+
/// @function point_and_click
47+
/// @description Returns true if left mouse button was clicked on the desired rectangle area.
48+
/// @param {array} rect x1, y1, x2, y2 array.
49+
/// @param {Real} cooldown how many frames/steps until another click can be registered with the same params
50+
/// @returns {bool} usually used as part of an if statement in a Draw handler to run code when the player clicks something like a button
51+
function point_and_click(rect, cooldown = 60)
52+
```
53+
Mouse Cursor Hover
54+
```gml
55+
/// @function scr_hit
56+
/// @description Returns true if mouse is hovering on the specified rectangle area.
57+
/// @returns {bool}
58+
function scr_hit(x1=0, y1=0, x2=0, y2=0)
59+
```
60+
Drawing an image from file
61+
```gml
62+
/// @description Draws a png image
63+
/// For actual sprites with multiple frames, don't use this.
64+
/// @param {String} path the file path after 'images' in the 'datafiles' folder. e.g. "creation/chapters/icons"
65+
/// @param {Real} image_id the name of the image. Convention follows using numbers, e.g. "1.png", so that loops are useful, and it can be stored at it's own array index in the cache.
66+
/// @param {Real} x1 the x coordinates to start drawing
67+
/// @param {Real} y1 the y coordinates to start drawing
68+
/// @param {Real} width the width of the image
69+
/// @param {Real} height the height of the image
70+
function scr_image(path, image_id, x1, y1, width, height)
71+
/// @example
72+
scr_image("creation/chapters/icons", 1, 450, 250, 32, 32); // draws the Dark Angels chapter icon at x 450 and y 250 at size 32x32px
73+
```
74+
75+
Tooltips
76+
```gml
77+
/// creates a hover over tool tip at the given coordinate where:
78+
/// x is the left most point of the tooltip box
79+
/// y is the topmost point of the tooltip box,
80+
/// tooltip_text is the text to display (text should be preformatted e.g string_hash_to_newline() to create lines)
81+
function tooltip_draw(_tooltip="", _width=350, _coords=return_mouse_consts_tooltip(), _text_color=#50a076, _font=fnt_40k_14, _header="", _header_font=fnt_40k_14b, _force_width=false){
82+
```
83+
84+
Company id to string
85+
```gml
86+
/// @function scr_convert_company_to_string
87+
/// @description Accepts a number and adds an affix to convert it to ordinal form.
88+
/// @param {real} company_num Company number.
89+
/// @param {bool} possessive Add 's affix?
90+
/// @param {bool} flavour Add company designation text (Veteran, Battle, Reserve, etc.)?
91+
/// @returns {string}
92+
function scr_convert_company_to_string(company_num, possessive = false, flavour=false)
93+
/// @example
94+
scr_convert_company_to_string(1, true, true); // 1st Veteran Company
95+
scr_convert_company_to_string(7, true, true); // 7th Reserve Company
96+
```
97+
98+
99+
# How does combat work?????
37100

38101
- First obj_ncombat is creates.
39102
- second scr_battle_Roster is run with the location planet and star as arguments to collect player forces in battle

0 commit comments

Comments
 (0)