Skip to content

Commit f105bc8

Browse files
sfan5nerzhul
authored andcommittedApr 11, 2020
A few initialization cleanups
1 parent aa3cf40 commit f105bc8

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed
 

‎src/client/client.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void Client::loadMods()
178178
infostream << mod.name << " ";
179179
infostream << std::endl;
180180

181-
// Load and run "mod" scripts
181+
// Load "mod" scripts
182182
for (const ModSpec &mod : m_mods) {
183183
if (!string_allowed(mod.name, MODNAME_ALLOWED_CHARS)) {
184184
throw ModError("Error loading mod \"" + mod.name +
@@ -188,7 +188,7 @@ void Client::loadMods()
188188
scanModIntoMemory(mod.name, mod.path);
189189
}
190190

191-
// Load and run "mod" scripts
191+
// Run them
192192
for (const ModSpec &mod : m_mods)
193193
m_script->loadModFromMemory(mod.name);
194194

@@ -197,10 +197,14 @@ void Client::loadMods()
197197

198198
// Run a callback when mods are loaded
199199
m_script->on_mods_loaded();
200+
201+
// Create objects if they're ready
200202
if (m_state == LC_Ready)
201203
m_script->on_client_ready(m_env.getLocalPlayer());
202204
if (m_camera)
203205
m_script->on_camera_ready(m_camera);
206+
if (m_minimap)
207+
m_script->on_minimap_ready(m_minimap);
204208
}
205209

206210
bool Client::checkBuiltinIntegrity()

‎src/client/game.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1407,8 +1407,11 @@ bool Game::createClient(const std::string &playername,
14071407
}
14081408

14091409
mapper = client->getMinimap();
1410-
if (mapper)
1410+
if (mapper) {
14111411
mapper->setMinimapMode(MINIMAP_MODE_OFF);
1412+
if (client->modsLoaded())
1413+
client->getScript()->on_minimap_ready(mapper);
1414+
}
14121415

14131416
return true;
14141417
}

‎src/script/scripting_client.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ ClientScripting::ClientScripting(Client *client):
5555
InitializeModApi(L, top);
5656
lua_pop(L, 1);
5757

58-
if (client->getMinimap())
59-
LuaMinimap::create(L, client->getMinimap());
60-
6158
// Push builtin initialization type
6259
lua_pushstring(L, "client");
6360
lua_setglobal(L, "INIT");
@@ -94,3 +91,8 @@ void ClientScripting::on_camera_ready(Camera *camera)
9491
{
9592
LuaCamera::create(getStack(), camera);
9693
}
94+
95+
void ClientScripting::on_minimap_ready(Minimap *minimap)
96+
{
97+
LuaMinimap::create(getStack(), minimap);
98+
}

‎src/script/scripting_client.h

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2828
class Client;
2929
class LocalPlayer;
3030
class Camera;
31+
class Minimap;
32+
3133
class ClientScripting:
3234
virtual public ScriptApiBase,
3335
public ScriptApiSecurity,
@@ -38,6 +40,7 @@ class ClientScripting:
3840
ClientScripting(Client *client);
3941
void on_client_ready(LocalPlayer *localplayer);
4042
void on_camera_ready(Camera *camera);
43+
void on_minimap_ready(Minimap *minimap);
4144

4245
private:
4346
virtual void InitializeModApi(lua_State *L, int top);

0 commit comments

Comments
 (0)
Please sign in to comment.