Skip to content

Commit

Permalink
GloomEd|Gloom: Send a "loadmap" command to the viewer app
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent b7c9dd6 commit 96eb7f3
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 40 deletions.
27 changes: 27 additions & 0 deletions doomsday/apps/gloom/src/gloomapp.cpp
Expand Up @@ -28,6 +28,7 @@
#include <de/Beacon>
#include <de/DisplayMode>
#include <de/FileSystem>
#include <de/Info>
#include <de/PackageLoader>
#include <de/ScriptSystem>

Expand Down Expand Up @@ -56,6 +57,8 @@ DE_PIMPL(GloomApp)
// GloomEd will tell us what to do via the command socket.
{
commandSocket.reset(new_Datagram());
setUserData_Object(commandSocket, this);
iConnect(Datagram, commandSocket, message, commandSocket, receivedRemoteCommand);
for (int attempt = 0; attempt < 12; ++attempt)
{
if (open_Datagram(commandSocket, duint16(COMMAND_PORT + 4 + attempt)))
Expand Down Expand Up @@ -87,6 +90,30 @@ DE_PIMPL(GloomApp)
self().glDeinit();
}

static void receivedRemoteCommand(iAny *, iDatagram *socket)
{
while (String msgData = Block::take(receive_Datagram(socket, nullptr)))
{
Loop::mainCall([msgData]() {
const Info msg(msgData);
for (const auto *elem : msg.root().contentsInOrder())
{
if (elem->isBlock())
{
const auto &block = elem->as<Info::BlockElement>();
if (block.blockType() == "command")
{
if (block.name() == "loadmap")
{
debug("load map: '%s'", block["package"].c_str());
}
}
}
}
});
}
}

void loadAllShaders()
{
// Load all the shader program definitions.
Expand Down
120 changes: 96 additions & 24 deletions doomsday/apps/gloomed/src/editor.cpp
Expand Up @@ -24,7 +24,9 @@
#include <doomsday/DataBundle>
#include <doomsday/LumpCatalog>
#include <de/FS>
#include <de/Info>
#include <de/Matrix>
#include <de/charsymbols.h>

#include <QAction>
#include <QCloseEvent>
Expand Down Expand Up @@ -88,6 +90,7 @@ DE_PIMPL(Editor)
Map map;
String mapId;
String filePath;
String packageName;
bool isModified = false;
List<Map> undoStack;

Expand Down Expand Up @@ -128,11 +131,14 @@ DE_PIMPL(Editor)
loadMap(persistentMapPath());
}

// Check for previous state.
// Check for previous editor state.
{
QSettings st;
viewScale = st.value("viewScale", 10).toFloat();
viewOrigin = toVec2d(st.value("viewOrigin").value<QVector2D>());

viewScale = st.value("viewScale", 10).toFloat();
viewOrigin = toVec2d(st.value("viewOrigin").value<QVector2D>());
mapId = convert(st.value("mapId").toString());
packageName = convert(st.value("packageName", "user.editorproject").toString());
}
}

Expand All @@ -142,12 +148,41 @@ DE_PIMPL(Editor)
{
QSettings st;
st.setValue("mapId", convert(mapId));
st.setValue("packageName", convert(packageName));
st.setValue("filePath", convert(filePath));
st.setValue("viewScale", viewScale);
st.setValue("viewOrigin", toQVector2D(viewOrigin));
}
}

void updateWindowTitle()
{
if (self().parentWidget())
{
const String path = filePath ? filePath : "(unsaved)";
const String id = mapId ? mapId : "(unnamed)";
const String pkg = packageName ? packageName : "(no package)";

self().parentWidget()->setWindowTitle(
convert(Stringf("%s (%s) " DE_CHAR_MDASH " %s " DE_CHAR_MDASH " GloomEd",
path.c_str(), id.c_str(), pkg.c_str())));
}
}

void resetState()
{
undoStack.clear();
isModified = false;
floorPoints.clear();
selection.clear();
hoverPoint = 0;
hoverLine = 0;
hoverSector = 0;
hoverEntity = 0;
hoverPlane = 0;
self().update();
}

QString persistentMapPath() const
{
return QSettings().value("filePath", "").toString();
Expand Down Expand Up @@ -995,7 +1030,7 @@ DE_PIMPL(Editor)
map = Map();
mapId.clear();
filePath.clear();
setWindowTitle("(unnamed)");
updateWindowTitle();
resetState();
}

Expand Down Expand Up @@ -1028,7 +1063,7 @@ DE_PIMPL(Editor)
const QByteArray mapData = f.readAll();
map.deserialize(Block(mapData.constData(), mapData.size()));
resetState();
setWindowTitle(convert(filePath.fileName()));
updateWindowTitle();
}

void saveAsFile()
Expand All @@ -1038,7 +1073,7 @@ DE_PIMPL(Editor)
if (!newPath.isEmpty())
{
filePath = convert(newPath);
setWindowTitle(convert(filePath.fileName()));
updateWindowTitle();
saveFile();
}
}
Expand Down Expand Up @@ -1123,15 +1158,15 @@ DE_PIMPL(Editor)
qDebug() << "Texture:" << n << img.size().asText();
img.toQImage().save(n + ".png");
}*/
importer.exportPackage("/home/user.editorproject.pack");
importer.exportPackage(packageRootPath());
}

// Update the editor's map.
map = importer.map();
mapId = importer.mapId();
filePath.clear();
resetState();
setWindowTitle(convert(mapId));
updateWindowTitle();
}
}
}
Expand All @@ -1140,26 +1175,48 @@ DE_PIMPL(Editor)
}
}

void setWindowTitle(const QString &text)
String packageRootPath() const
{
if (self().parentWidget())
{
self().parentWidget()->setWindowTitle(QString("%1 (%2)").arg(text, convert(mapId)));
}
return "/home/" + packageName + ".pack";
}

void resetState()
void exportPackage()
{
undoStack.clear();
isModified = false;
floorPoints.clear();
selection.clear();
hoverPoint = 0;
hoverLine = 0;
hoverSector = 0;
hoverEntity = 0;
hoverPlane = 0;
self().update();
if (!mapId)
{
mapId = convert(QInputDialog::getText(nullptr, "Export Package", "Map ID:"));
if (!mapId) return;
}
if (!packageName)
{
packageName = convert(QInputDialog::getText(nullptr, "Export Package", "Package ID:"));
if (!packageName) return;
}

updateWindowTitle();

DE_ASSERT(mapId);
DE_ASSERT(packageName);

Folder &root = FS::get().makeFolder(packageRootPath()); // or use existing folder...

// Rewrite the .gloommap file.
{
const auto mapData = map.serialize();
File &mapFile = root.replaceFile("maps" / mapId + ".gloommap");
mapFile << mapData;
mapFile.flush();
}

// Check that the maps.dei includes this map.
if (const auto *mapsInfoFile = root.tryLocate<const File>("maps.dei"))
{
Info mapsInfo(*mapsInfoFile);
if (mapsInfo.root().contains(mapId))
{

}
}
}
};

Expand Down Expand Up @@ -1219,6 +1276,21 @@ gloom::Map &Editor::map()
return d->map;
}

String Editor::packageName() const
{
return d->packageName;
}

void Editor::exportPackage() const
{
d->exportPackage();
}

void Editor::updateWindowTitle() const
{
d->updateWindowTitle();
}

bool Editor::maybeClose()
{
if (!d->askSaveFile())
Expand Down
3 changes: 3 additions & 0 deletions doomsday/apps/gloomed/src/editor.h
Expand Up @@ -42,7 +42,10 @@ class Editor : public QWidget

de::String mapId() const;
gloom::Map &map();
de::String packageName() const;

void exportPackage() const;
void updateWindowTitle() const;
bool maybeClose();
QSet<gloom::ID> selection() const;
void markAsChanged();
Expand Down
7 changes: 4 additions & 3 deletions doomsday/apps/gloomed/src/editorwindow.cpp
Expand Up @@ -41,6 +41,7 @@ EditorWindow::EditorWindow()
{
d->editor = new Editor;
setCentralWidget(d->editor);
d->editor->updateWindowTitle();

const QStringList allMaterials({"",
"world.stone",
Expand All @@ -56,7 +57,7 @@ EditorWindow::EditorWindow()
QToolBar *matr = new QToolBar(tr("Line Material"));
addToolBar(Qt::BottomToolBarArea, matr);

connect(d->editor, &Editor::modeChanged, [matr] (int mode) {
connect(d->editor, &Editor::modeChanged, matr, [matr] (int mode) {
matr->setVisible(mode == Editor::EditLines);
});

Expand Down Expand Up @@ -138,7 +139,7 @@ EditorWindow::EditorWindow()
QToolBar *matr = new QToolBar(tr("Plane Material"));
addToolBar(Qt::BottomToolBarArea, matr);

connect(d->editor, &Editor::modeChanged, [matr] (int mode) {
connect(d->editor, &Editor::modeChanged, matr, [matr] (int mode) {
matr->setVisible(mode == Editor::EditPlanes);
});

Expand All @@ -159,7 +160,7 @@ EditorWindow::EditorWindow()
Map &map = d->editor->map();

// Change line materials.
for (ID id : d->editor->selection())
foreach (ID id, d->editor->selection())
{
if (map.isPlane(id))
{
Expand Down

0 comments on commit 96eb7f3

Please sign in to comment.