File: gamehelp.cpp

package info (click to toggle)
freespace2 24.2.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,716 kB
  • sloc: cpp: 595,001; ansic: 21,741; python: 1,174; sh: 457; makefile: 248; xml: 181
file content (109 lines) | stat: -rw-r--r-- 2,888 bytes parent folder | download | duplicates (2)
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
#include "gamehelp.h"

#include "gamehelp/gameplayhelp.h"

namespace scripting {
namespace api {

help_section_h::help_section_h() : section(-1) {}
help_section_h::help_section_h(int l_section) : section(l_section) {}

gameplay_help_section* help_section_h::getSection() const
{
	if (!isValid())
		return nullptr;

	return &Help_text[section];
}

bool help_section_h::isValid() const
{
	return section >= 0 && section < (int)Help_text.size();
}

//**********HANDLE: help section
ADE_OBJ(l_Help_Section, help_section_h, "help_section", "Help Section handle");

ADE_FUNC(isValid, l_Help_Section, nullptr, "Detects whether handle is valid", "boolean", "true if valid, false if handle is invalid, nil if a syntax/type error occurs")
{
	help_section_h current;
	if (!ade_get_args(L, "o", l_Help_Section.Get(&current)))
		return ADE_RETURN_NIL;

	return ade_set_args(L, "b", current.isValid());
}

ADE_VIRTVAR(Title, l_Help_Section, nullptr, "The title of the help section", "string", "The title")
{
	help_section_h current;
	if (!ade_get_args(L, "o", l_Help_Section.Get(&current))) {
		return ADE_RETURN_NIL;
	}
	if (!current.isValid()) {
		return ade_set_error(L, "s", "");
	}

	if (ADE_SETTING_VAR) {
		LuaError(L, "This property is read only.");
	}

	return ade_set_args(L, "s", current.getSection()->title);
}

ADE_VIRTVAR(Header, l_Help_Section, nullptr, "The header of the help section", "string", "The header")
{
	help_section_h current;
	if (!ade_get_args(L, "o", l_Help_Section.Get(&current))) {
		return ADE_RETURN_NIL;
	}
	if (!current.isValid()) {
		return ade_set_error(L, "s", "");
	}

	if (ADE_SETTING_VAR) {
		LuaError(L, "This property is read only.");
	}

	return ade_set_args(L, "s", current.getSection()->header);
}

ADE_VIRTVAR(Keys, l_Help_Section, nullptr, "Gets a table of keys in the help section", "{ number => string ... }", "The keys table") 
{
	help_section_h current;
	if (!ade_get_args(L, "o", l_Help_Section.Get(&current))) {
		return ADE_RETURN_NIL;
	}

	auto table = luacpp::LuaTable::create(L);
	if (!current.isValid()) {
		return ade_set_error(L, "t", &table);
	}

	for (size_t i = 0; i < current.getSection()->key.size(); i++) {
		table.addValue(i + 1, current.getSection()->key[i]); //translate to Lua index
	}

	return ade_set_args(L, "t", &table);	
}

ADE_VIRTVAR(Texts, l_Help_Section, nullptr, "Gets a table of texts in the help section", "{ number => string ... }", "The texts table")
{
	help_section_h current;
	if (!ade_get_args(L, "o", l_Help_Section.Get(&current))) {
		return ADE_RETURN_NIL;
	}

	auto table = luacpp::LuaTable::create(L);
	if (!current.isValid()) {
		return ade_set_error(L, "t", &table);
	}

	for (size_t i = 0; i < current.getSection()->text.size(); i++) {
		table.addValue(i + 1, current.getSection()->text[i]); //translate to Lua index
	}

	return ade_set_args(L, "t", &table);
}

} // namespace api
} // namespace scripting