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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
|
#include "missionlog.h"
#include "iff_defs/iff_defs.h"
#include "ship/ship.h"
#include "globalincs/alphacolors.h"
#include "parse/parselo.h"
#include "scripting/api/objs/color.h"
namespace scripting {
namespace api {
log_entry_h::log_entry_h() : section(-1) {}
log_entry_h::log_entry_h(int l_section) : section(l_section) {}
const log_line_complete* log_entry_h::getSection() const
{
if (!isValid())
return nullptr;
return mission_log_scrollback_get_line(section);
}
bool log_entry_h::isValid() const
{
return section >= 0 && section < mission_log_scrollback_num_lines();
}
message_entry_h::message_entry_h() : section(-1) {}
message_entry_h::message_entry_h(int l_section) : section(l_section) {}
const line_node* message_entry_h::getSection() const
{
if (!isValid())
return nullptr;
return &Msg_scrollback_vec[section];
}
bool message_entry_h::isValid() const
{
return section >= 0 && section < (int)Msg_scrollback_vec.size();
}
//**********HANDLE: log entry
ADE_OBJ(l_Log_Entry, log_entry_h, "log_entry", "Log Entry handle");
ADE_FUNC(isValid, l_Log_Entry, nullptr, "Detects whether handle is valid", "boolean", "true if valid, false if handle is invalid, nil if a syntax/type error occurs")
{
log_entry_h current;
if (!ade_get_args(L, "o", l_Log_Entry.Get(¤t)))
return ADE_RETURN_NIL;
return ade_set_args(L, "b", current.isValid());
}
ADE_VIRTVAR(Timestamp, l_Log_Entry, nullptr, "The timestamp of the log entry", "string", "The timestamp")
{
log_entry_h current;
if (!ade_get_args(L, "o", l_Log_Entry.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (!current.isValid()) {
return ade_set_error(L, "s", "");
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
int seconds = f2i(current.getSection()->timestamp);
// format the time information into strings
SCP_string time;
sprintf(time, "%.1d:%.2d:%.2d", (seconds / 3600) % 10, (seconds / 60) % 60, seconds % 60);
return ade_set_args(L, "s", time.c_str());
}
ADE_VIRTVAR(paddedTimestamp, l_Log_Entry, nullptr, "The timestamp of the log entry that accounts for timer padding", "string", "The timestamp")
{
log_entry_h current;
if (!ade_get_args(L, "o", l_Log_Entry.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (!current.isValid()) {
return ade_set_error(L, "s", "");
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
int seconds = f2i(current.getSection()->timestamp) + current.getSection()->timer_padding;
// format the time information into strings
SCP_string time;
sprintf(time, "%.1d:%.2d:%.2d", (seconds / 3600) % 10, (seconds / 60) % 60, seconds % 60);
return ade_set_args(L, "s", time.c_str());
}
ADE_VIRTVAR(Flags, l_Log_Entry, nullptr, "The flag of the log entry. 1 for Goal True, 2 for Goal Failed, 0 otherwise.", "number", "The flag")
{
log_entry_h current;
if (!ade_get_args(L, "o", l_Log_Entry.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (!current.isValid()) {
return ade_set_error(L, "i", 0);
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
int this_flag = 0;
if (current.getSection()->objective.flags & LOG_FLAG_GOAL_TRUE)
this_flag = 1;
if (current.getSection()->objective.flags & LOG_FLAG_GOAL_FAILED)
this_flag = 2;
return ade_set_args(L, "i", this_flag);
}
ADE_VIRTVAR(ObjectiveText, l_Log_Entry, nullptr, "The objective text of the log entry", "string", "The objective text")
{
log_entry_h current;
if (!ade_get_args(L, "o", l_Log_Entry.Get(¤t))) {
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()->objective.text.get());
}
ADE_VIRTVAR(ObjectiveColor, l_Log_Entry, nullptr, "The objective color of the log entry.", "color", "The objective color")
{
log_entry_h current;
if (!ade_get_args(L, "o", l_Log_Entry.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (!current.isValid()) {
return ade_set_error(L, "o", l_Color.Set(Color_text_normal));
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
auto ac = log_line_get_color(current.getSection()->objective.color);
return ade_set_args(L, "o", l_Color.Set(*ac));
}
ADE_VIRTVAR(SegmentTexts,
l_Log_Entry,
nullptr,
"Gets a table of segment texts in the log entry",
"{ number => string ... }",
"The segment texts table")
{
log_entry_h current;
if (!ade_get_args(L, "o", l_Log_Entry.Get(¤t))) {
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()->segments.size(); i++) {
table.addValue(i + 1, current.getSection()->segments[i].text.get()); // translate to Lua index
}
return ade_set_args(L, "t", &table);
}
ADE_VIRTVAR(SegmentColors,
l_Log_Entry,
nullptr,
"Gets a table of segment colors in the log entry.",
"{ number => color ... }",
"The segment colors table")
{
log_entry_h current;
if (!ade_get_args(L, "o", l_Log_Entry.Get(¤t))) {
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()->segments.size(); i++) {
auto ac = log_line_get_color(current.getSection()->segments[i].color);
table.addValue(i + 1, l_Color.Set(*ac)); // translate to Lua index
}
return ade_set_args(L, "t", &table);
}
//**********HANDLE: message entry
ADE_OBJ(l_Message_Entry, message_entry_h, "message_entry", "Message Entry handle");
ADE_FUNC(isValid, l_Message_Entry, nullptr, "Detects whether handle is valid", "boolean", "true if valid, false if handle is invalid, nil if a syntax/type error occurs")
{
message_entry_h current;
if (!ade_get_args(L, "o", l_Message_Entry.Get(¤t)))
return ADE_RETURN_NIL;
return ade_set_args(L, "b", current.isValid());
}
ADE_VIRTVAR(Timestamp, l_Message_Entry, nullptr, "The timestamp of the message entry", "string", "The timestamp")
{
message_entry_h current;
if (!ade_get_args(L, "o", l_Message_Entry.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (!current.isValid()) {
return ade_set_error(L, "s", "");
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
int seconds = f2i(current.getSection()->time);
// format the time information into strings
SCP_string time;
sprintf(time, "%.1d:%.2d:%.2d", (seconds / 3600) % 10, (seconds / 60) % 60, seconds % 60);
return ade_set_args(L, "s", time.c_str());
}
ADE_VIRTVAR(paddedTimestamp, l_Message_Entry, nullptr, "The timestamp of the message entry that accounts for mission timer padding", "string", "The timestamp")
{
message_entry_h current;
if (!ade_get_args(L, "o", l_Message_Entry.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (!current.isValid()) {
return ade_set_error(L, "s", "");
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
int seconds = f2i(current.getSection()->time) + current.getSection()->timer_padding;
// format the time information into strings
SCP_string time;
sprintf(time, "%.1d:%.2d:%.2d", (seconds / 3600) % 10, (seconds / 60) % 60, seconds % 60);
return ade_set_args(L, "s", time.c_str());
}
ADE_VIRTVAR(Color, l_Message_Entry, nullptr, "The color of the message entry.", "color", "The color")
{
message_entry_h current;
if (!ade_get_args(L, "o", l_Message_Entry.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (!current.isValid()) {
return ade_set_error(L, "o", l_Color.Set(Color_text_normal));
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
const color *this_color;
int team = HUD_source_get_team(current.getSection()->source);
if (team >= 0) {
this_color = iff_get_color_by_team(team, Player_ship->team, 0);
} else {
switch (current.getSection()->source) {
case HUD_SOURCE_TRAINING:
this_color = &Color_bright_blue;
break;
case HUD_SOURCE_TERRAN_CMD:
this_color = &Color_bright_white;
break;
case HUD_SOURCE_IMPORTANT:
case HUD_SOURCE_FAILED:
case HUD_SOURCE_SATISFIED:
this_color = &Color_bright_white;
break;
default:
this_color = &Color_text_normal;
break;
}
}
return ade_set_args(L, "o", l_Color.Set(*this_color));
}
ADE_VIRTVAR(Text, l_Message_Entry, nullptr, "The text of the message entry", "string", "The text")
{
message_entry_h current;
if (!ade_get_args(L, "o", l_Message_Entry.Get(¤t))) {
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()->text.c_str());
}
} // namespace api
} // namespace scripting
|