• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

traintastic / traintastic / 20799539071

07 Jan 2026 11:10PM UTC coverage: 27.22% (+0.07%) from 27.155%
20799539071

push

github

reinder
[world] added scripting feature settings: show/hid scripting related stuff, see #71

53 of 108 new or added lines in 7 files covered. (49.07%)

1 existing line in 1 file now uncovered.

7918 of 29089 relevant lines covered (27.22%)

192.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.17
/server/src/lua/scriptlist.cpp
1
/**
2
 * This file is part of Traintastic,
3
 * see <https://github.com/traintastic/traintastic>.
4
 *
5
 * Copyright (C) 2019-2026 Reinder Feenstra
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
 */
21

22
#include "scriptlist.hpp"
23
#include "scriptlisttablemodel.hpp"
24
#include "../world/getworld.hpp"
25
#include "../core/attributes.hpp"
26
#include "../core/method.tpp"
27
#include "../core/objectproperty.tpp"
28
#include "../utils/displayname.hpp"
29

30
namespace Lua {
31

32
ScriptList::ScriptList(Object& _parent, std::string_view parentPropertyName)
208✔
33
  : ObjectList<Script>(_parent, parentPropertyName)
34
  , status{this, "status", nullptr, PropertyFlags::ReadOnly | PropertyFlags::NoStore | PropertyFlags::SubObject | PropertyFlags::NoScript | PropertyFlags::Internal}
208✔
35
  , create{*this, "create",
416✔
36
      [this]()
208✔
37
      {
38
        auto& world = getWorld(parent());
72✔
39
        return Script::create(world, world.getUniqueId("script"));
72✔
40
      }}
41
  , delete_{*this, "delete", std::bind(&ScriptList::deleteMethodHandler, this, std::placeholders::_1)}
208✔
42
  , startAll{*this, "start_all",
416✔
43
      [this]()
208✔
44
      {
45
        for(const auto& script : m_items)
×
46
          if(!script->disabled)
×
47
            script->start();
×
48
      }}
×
49
  , stopAll{*this, "stop_all",
416✔
50
      [this]()
208✔
51
      {
52
        for(const auto& script : m_items)
281✔
53
          if(!script->disabled)
73✔
54
            script->stop();
72✔
55
      }}
208✔
56
  , clearPersistentVariables{*this, "clear_persistent_variables",
416✔
57
    [this]()
208✔
58
    {
59
      for(const auto& script : m_items)
×
60
      {
61
        if(Attributes::getEnabled(script->clearPersistentVariables))
×
62
        {
63
          script->clearPersistentVariables();
×
64
        }
65
      }
66
    }}
208✔
67
{
68
  status.setValueInternal(std::make_shared<LuaStatus>(*this, status.name()));
208✔
69

70
  const bool editable = contains(getWorld(parent()).state.value(), WorldState::Edit);
208✔
71

72
  m_interfaceItems.add(status);
208✔
73

74
  Attributes::addDisplayName(create, DisplayName::List::create);
208✔
75
  Attributes::addEnabled(create, editable);
208✔
76
  m_interfaceItems.add(create);
208✔
77

78
  Attributes::addDisplayName(delete_, DisplayName::List::delete_);
208✔
79
  Attributes::addEnabled(delete_, editable);
208✔
80
  m_interfaceItems.add(delete_);
208✔
81

82
  Attributes::addEnabled(startAll, false);
208✔
83
  m_interfaceItems.add(startAll);
208✔
84

85
  Attributes::addEnabled(stopAll, false);
208✔
86
  m_interfaceItems.add(stopAll);
208✔
87

88
  Attributes::addDisplayName(clearPersistentVariables, "lua.script:clear_persistent_variables");
208✔
89
  Attributes::addEnabled(clearPersistentVariables, false);
208✔
90
  m_interfaceItems.add(clearPersistentVariables);
208✔
91
}
208✔
92

93
ScriptList::~ScriptList()
208✔
94
{
95
  removeStatus();
208✔
96
}
208✔
97

98
TableModelPtr ScriptList::getModel()
×
99
{
100
  return std::make_shared<ScriptListTableModel>(*this);
×
101
}
102

103
void ScriptList::loaded()
3✔
104
{
105
  ObjectList<Script>::loaded();
3✔
106

107
  if(!getWorld(parent()).feature(WorldFeature::Scripting))
3✔
108
  {
NEW
109
    removeStatus();
×
110
  }
111
}
3✔
112

113
void ScriptList::worldEvent(WorldState state, WorldEvent event)
13✔
114
{
115
  ObjectList<Script>::worldEvent(state, event);
13✔
116

117
  const bool editable = contains(state, WorldState::Edit);
13✔
118

119
  Attributes::setEnabled(create, editable);
13✔
120
  Attributes::setEnabled(delete_, editable);
13✔
121
}
13✔
122

NEW
123
void ScriptList::worldFeaturesChanged(const WorldFeatures features, WorldFeature changed)
×
124
{
NEW
125
  ObjectList<Script>::worldFeaturesChanged(features, changed);
×
126

NEW
127
  if(changed == WorldFeature::Scripting && !empty())
×
128
  {
NEW
129
    if(features[WorldFeature::Scripting])
×
130
    {
NEW
131
      addStatus();
×
132
    }
NEW
133
    else if(!features[WorldFeature::Scripting])
×
134
    {
NEW
135
      removeStatus();
×
136
    }
137
  }
NEW
138
}
×
139

140
void ScriptList::objectAdded(const std::shared_ptr<Script>& /*object*/)
73✔
141
{
142
  if(m_items.size() == 1)
73✔
143
  {
144
    addStatus();
73✔
145
  }
146
  updateEnabled();
73✔
147
}
73✔
148

149
void ScriptList::objectRemoved(const std::shared_ptr<Script>& /*object*/)
73✔
150
{
151
  if(empty())
73✔
152
  {
153
    removeStatus();
73✔
154
  }
155
  updateEnabled();
73✔
156
}
73✔
157

158
bool ScriptList::isListedProperty(std::string_view name)
×
159
{
160
  return ScriptListTableModel::isListedProperty(name);
×
161
}
162

163
void ScriptList::updateEnabled()
413✔
164
{
165
  bool canStart = false;
413✔
166
  bool canStop = false;
413✔
167
  bool canClearPersistentVariables = false;
413✔
168

169
  for(const auto& script : m_items)
680✔
170
  {
171
    canStart |= Attributes::getEnabled(script->start);
267✔
172
    canStop |= Attributes::getEnabled(script->stop);
267✔
173
    canClearPersistentVariables |= Attributes::getEnabled(script->clearPersistentVariables);
267✔
174
  }
175

176
  Attributes::setEnabled(startAll, canStart);
413✔
177
  Attributes::setEnabled(stopAll, canStop);
413✔
178
  Attributes::setEnabled(clearPersistentVariables, canClearPersistentVariables);
413✔
179
}
413✔
180

181
void ScriptList::addStatus()
73✔
182
{
183
  getWorld(parent()).statuses.appendInternal(status.value());
73✔
184
}
73✔
185

186
void ScriptList::removeStatus()
281✔
187
{
188
  getWorld(parent()).statuses.removeInternal(status.value());
281✔
189
}
281✔
190

191
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc