forked from ddnet/ddnet
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First working version of "set_gametile"
Console command to place gametiles in the current map. Ground work for the server sending map patches to the client. The current implementation is horrible. It is spawning a thread which runs a python script that the user has to place in the maps folder So this needs some work to be polished and portable.
- Loading branch information
1 parent
cc6ead0
commit 3399718
Showing
9 changed files
with
219 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
import twmap | ||
|
||
if len(sys.argv) != 6: | ||
print("usage: set_gametile.py IN_MAP OUT_MAP x y index") | ||
sys.exit(0) | ||
|
||
arg_map_in = sys.argv[1] | ||
arg_map_out = sys.argv[2] | ||
arg_x = int(sys.argv[3]) | ||
arg_y = int(sys.argv[4]) | ||
arg_index = int(sys.argv[5]) | ||
|
||
m = twmap.Map(arg_map_in) | ||
|
||
tiles = m.game_layer().tiles | ||
tiles[arg_y][arg_x][0] = arg_index | ||
m.game_layer().tiles = tiles | ||
|
||
m.save(arg_map_out) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// ChillerDragon 2022 - chillerbot ux | ||
|
||
#include "engine/shared/protocol.h" | ||
#include <engine/client/notifications.h> | ||
#include <engine/config.h> | ||
#include <engine/console.h> | ||
#include <engine/graphics.h> | ||
#include <engine/keys.h> | ||
#include <engine/textrender.h> | ||
#include <game/client/animstate.h> | ||
#include <game/client/components/camera.h> | ||
#include <game/client/components/chat.h> | ||
#include <game/client/components/chillerbot/chathelper.h> | ||
#include <game/client/components/chillerbot/version.h> | ||
#include <game/client/components/controls.h> | ||
#include <game/client/components/menus.h> | ||
#include <game/client/components/voting.h> | ||
#include <game/client/gameclient.h> | ||
#include <game/client/prediction/entities/character.h> | ||
#include <game/client/race.h> | ||
#include <game/client/render.h> | ||
#include <game/generated/client_data.h> | ||
#include <game/generated/protocol.h> | ||
#include <game/version.h> | ||
|
||
#include "edit_map.h" | ||
|
||
/* | ||
needed setup | ||
mkdir -p ~/.teeworlds/maps/tmp | ||
cd scripts/ | ||
ln -s "$(pwd)/set_gametile.py" ~/.teeworlds/maps/tmp/ | ||
*/ | ||
|
||
void CEditMapJob::Run() | ||
{ | ||
char aBuf[512]; | ||
str_format(aBuf, sizeof(aBuf), "cd $HOME/.teeworlds/ && /usr/bin/python3 ./maps/tmp/set_gametile.py %s %s %d %d %d", | ||
m_aSource, m_aDestination, m_X, m_Y, m_Index); | ||
if(system(aBuf)) | ||
{ | ||
dbg_msg("edit_map", "process failed: %s", aBuf); | ||
} | ||
m_State = STATE_DONE; | ||
} | ||
|
||
CEditMap::CEditMap() | ||
{ | ||
m_pSetGameTileJob = nullptr; | ||
} | ||
|
||
void CEditMap::OnInit() | ||
{ | ||
char aDest[IO_MAX_PATH_LENGTH]; | ||
GetEditedMapPath(aDest, sizeof(aDest)); | ||
Storage()->RemoveFile(aDest, IStorage::TYPE_SAVE); | ||
} | ||
|
||
void CEditMap::OnShutdown() | ||
{ | ||
char aDest[IO_MAX_PATH_LENGTH]; | ||
GetEditedMapPath(aDest, sizeof(aDest)); | ||
Storage()->RemoveFile(aDest, IStorage::TYPE_SAVE); | ||
} | ||
|
||
void CEditMap::OnConsoleInit() | ||
{ | ||
Console()->Register("set_gametile", "i[x]i[y]i[index]", CFGFLAG_CLIENT, ConSetGametile, this, "Some ugly wip map edit hack"); | ||
} | ||
|
||
void CEditMap::OnRender() | ||
{ | ||
if(m_pSetGameTileJob) | ||
{ | ||
if(m_pSetGameTileJob->State() == CEditMapJob::STATE_DONE) | ||
{ | ||
char aDest[IO_MAX_PATH_LENGTH]; | ||
GetEditedMapPath(aDest, sizeof(aDest)); | ||
dbg_msg("edit_map", "thread finished load map: %s", aDest); | ||
m_pClient->Client()->ChillerBotLoadMap(aDest); | ||
m_pSetGameTileJob = nullptr; | ||
} | ||
} | ||
} | ||
|
||
void CEditMap::GetEditedMapPath(char *pPath, int Size) | ||
{ | ||
str_format(pPath, Size, "maps/tmp/chillerbot-ux-%d.map.tmp", pid()); | ||
} | ||
|
||
void CEditMap::GetSourceMapPath(char *pPath, int Size) | ||
{ | ||
GetEditedMapPath(pPath, Size); | ||
char aBuf[IO_MAX_PATH_LENGTH]; | ||
if(Storage()->FindFile(pPath + 9, "maps", IStorage::TYPE_SAVE, aBuf, sizeof(aBuf))) | ||
{ | ||
if(!str_comp(pPath, aBuf)) | ||
{ | ||
dbg_msg("edit_map", "edit map found add to it '%s'", aBuf); | ||
str_copy(pPath, aBuf, Size); | ||
return; | ||
} | ||
else | ||
{ | ||
dbg_msg("edit_map", "found map does not match '%s' != '%s'", pPath, aBuf); | ||
} | ||
} | ||
dbg_msg("edit_map", "'%s' not found in maps/ use current map", pPath + 9); | ||
str_copy(pPath, m_pClient->Client()->GetCurrentMapPath(), Size); | ||
} | ||
|
||
void CEditMap::ConSetGametile(IConsole::IResult *pResult, void *pUserData) | ||
{ | ||
CEditMap *pSelf = (CEditMap *)pUserData; | ||
char aDest[IO_MAX_PATH_LENGTH]; | ||
pSelf->GetEditedMapPath(aDest, sizeof(aDest)); | ||
char aSrc[IO_MAX_PATH_LENGTH]; | ||
pSelf->GetSourceMapPath(aSrc, sizeof(aSrc)); | ||
dbg_msg("edit_map", "load map from %s", aSrc); | ||
dbg_msg("edit_map", "save to %s", aDest); | ||
int x = pResult->GetInteger(0); | ||
int y = pResult->GetInteger(1); | ||
int Index = pResult->GetInteger(2); | ||
pSelf->m_pSetGameTileJob = std::make_shared<CEditMapJob>(aSrc, aDest, x, y, Index); | ||
pSelf->m_pClient->Engine()->AddJob(pSelf->m_pSetGameTileJob); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#ifndef GAME_CLIENT_COMPONENTS_CHILLERBOT_EDIT_MAP_H | ||
#define GAME_CLIENT_COMPONENTS_CHILLERBOT_EDIT_MAP_H | ||
|
||
#include <engine/console.h> | ||
#include <game/client/component.h> | ||
|
||
#include <engine/shared/jobs.h> | ||
|
||
class CEditMapJob : public IJob | ||
{ | ||
char m_aSource[IO_MAX_PATH_LENGTH]; | ||
char m_aDestination[IO_MAX_PATH_LENGTH]; | ||
int m_X; | ||
int m_Y; | ||
int m_Index; | ||
|
||
public: | ||
CEditMapJob(const char *pSource, const char *pDestination, int x, int y, int Index) | ||
{ | ||
str_copy(m_aSource, pSource, sizeof(m_aSource)); | ||
str_copy(m_aDestination, pDestination, sizeof(m_aDestination)); | ||
m_X = x; | ||
m_Y = y; | ||
m_Index = Index; | ||
m_State = STATE_RUNNING; | ||
} | ||
void Run() override; | ||
|
||
enum | ||
{ | ||
STATE_DONE, | ||
STATE_RUNNING, | ||
}; | ||
|
||
int m_State; | ||
|
||
int State() { return m_State; } | ||
}; | ||
|
||
class CEditMap : public CComponent | ||
{ | ||
virtual void OnRender() override; | ||
virtual void OnInit() override; | ||
virtual void OnShutdown() override; | ||
virtual void OnConsoleInit() override; | ||
|
||
static void ConSetGametile(IConsole::IResult *pResult, void *pUserData); | ||
|
||
std::shared_ptr<CEditMapJob> m_pSetGameTileJob; | ||
|
||
void GetEditedMapPath(char *pPath, int Size); | ||
void GetSourceMapPath(char *pPath, int Size); | ||
|
||
public: | ||
virtual int Sizeof() const override { return sizeof(*this); } | ||
|
||
CEditMap(); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters