mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-12-03 17:57:48 +00:00
feat: add bind for loading fastfiles to ModMan
This commit is contained in:
@@ -47,10 +47,16 @@ function ModMan:project()
|
|||||||
|
|
||||||
self:include(includes)
|
self:include(includes)
|
||||||
Utils:include(includes)
|
Utils:include(includes)
|
||||||
|
ZoneLoading:include(includes)
|
||||||
|
ObjLoading:include(includes)
|
||||||
|
ObjWriting:include(includes)
|
||||||
json:include(includes)
|
json:include(includes)
|
||||||
webview:include(includes)
|
webview:include(includes)
|
||||||
|
|
||||||
links:linkto(Utils)
|
links:linkto(Utils)
|
||||||
|
links:linkto(ZoneLoading)
|
||||||
|
links:linkto(ObjLoading)
|
||||||
|
links:linkto(ObjWriting)
|
||||||
links:linkto(webview)
|
links:linkto(webview)
|
||||||
links:linkall()
|
links:linkall()
|
||||||
end
|
end
|
||||||
|
|||||||
9
src/ModMan/Context/FastFileContext.cpp
Normal file
9
src/ModMan/Context/FastFileContext.cpp
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include "FastFileContext.h"
|
||||||
|
|
||||||
|
#include "ZoneLoading.h"
|
||||||
|
|
||||||
|
bool FastFileContext::LoadFastFile(const std::string& path)
|
||||||
|
{
|
||||||
|
m_loaded_zones.emplace_back(ZoneLoading::LoadZone(path));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
13
src/ModMan/Context/FastFileContext.h
Normal file
13
src/ModMan/Context/FastFileContext.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Zone/Zone.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class FastFileContext
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool LoadFastFile(const std::string& path);
|
||||||
|
|
||||||
|
std::vector<std::unique_ptr<Zone>> m_loaded_zones;
|
||||||
|
};
|
||||||
@@ -5,3 +5,13 @@ ModManContext& ModManContext::Get()
|
|||||||
static ModManContext context;
|
static ModManContext context;
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModManContext::Startup()
|
||||||
|
{
|
||||||
|
m_db_thread.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModManContext::Destroy()
|
||||||
|
{
|
||||||
|
m_db_thread.Terminate();
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "FastFileContext.h"
|
||||||
|
#include "Utils/DispatchableThread.h"
|
||||||
#include "Web/WebViewLib.h"
|
#include "Web/WebViewLib.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -9,6 +11,12 @@ class ModManContext
|
|||||||
public:
|
public:
|
||||||
static ModManContext& Get();
|
static ModManContext& Get();
|
||||||
|
|
||||||
|
void Startup();
|
||||||
|
void Destroy();
|
||||||
|
|
||||||
std::unique_ptr<webview::webview> m_main_webview;
|
std::unique_ptr<webview::webview> m_main_webview;
|
||||||
std::unique_ptr<webview::webview> m_dev_tools_webview;
|
std::unique_ptr<webview::webview> m_dev_tools_webview;
|
||||||
|
FastFileContext m_fast_file;
|
||||||
|
|
||||||
|
DispatchableThread m_db_thread;
|
||||||
};
|
};
|
||||||
|
|||||||
77
src/ModMan/Utils/DispatchableThread.cpp
Normal file
77
src/ModMan/Utils/DispatchableThread.cpp
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
#include "DispatchableThread.h"
|
||||||
|
|
||||||
|
DispatchableThread::DispatchableThread()
|
||||||
|
: m_terminate(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DispatchableThread::~DispatchableThread()
|
||||||
|
{
|
||||||
|
Terminate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DispatchableThread::Start()
|
||||||
|
{
|
||||||
|
m_terminate = false;
|
||||||
|
m_thread = std::thread(
|
||||||
|
[&]
|
||||||
|
{
|
||||||
|
ThreadLoop();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void DispatchableThread::Terminate()
|
||||||
|
{
|
||||||
|
std::unique_lock lock(m_cb_mutex);
|
||||||
|
|
||||||
|
if (!m_terminate)
|
||||||
|
{
|
||||||
|
m_terminate = true;
|
||||||
|
m_cv.notify_all();
|
||||||
|
lock.unlock();
|
||||||
|
m_thread.join();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DispatchableThread::Dispatch(cb_t cb)
|
||||||
|
{
|
||||||
|
std::lock_guard lock(m_cb_mutex);
|
||||||
|
|
||||||
|
m_cb_list.emplace_back(std::move(cb));
|
||||||
|
m_cv.notify_one();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<DispatchableThread::cb_t> DispatchableThread::NextCallback()
|
||||||
|
{
|
||||||
|
if (m_terminate || m_cb_list.empty())
|
||||||
|
return std::nullopt;
|
||||||
|
|
||||||
|
auto cb = std::move(m_cb_list.front());
|
||||||
|
m_cb_list.pop_front();
|
||||||
|
|
||||||
|
return cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DispatchableThread::ThreadLoop()
|
||||||
|
{
|
||||||
|
while (!m_terminate)
|
||||||
|
{
|
||||||
|
std::unique_lock lock(m_cb_mutex);
|
||||||
|
m_cv.wait(lock,
|
||||||
|
[&]
|
||||||
|
{
|
||||||
|
return !m_cb_list.empty() || m_terminate;
|
||||||
|
});
|
||||||
|
|
||||||
|
auto maybeCb = NextCallback();
|
||||||
|
|
||||||
|
lock.unlock();
|
||||||
|
|
||||||
|
if (maybeCb)
|
||||||
|
(*maybeCb)();
|
||||||
|
}
|
||||||
|
}
|
||||||
37
src/ModMan/Utils/DispatchableThread.h
Normal file
37
src/ModMan/Utils/DispatchableThread.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <condition_variable>
|
||||||
|
#include <deque>
|
||||||
|
#include <functional>
|
||||||
|
#include <mutex>
|
||||||
|
#include <optional>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
class DispatchableThread
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using cb_t = std::function<void()>;
|
||||||
|
|
||||||
|
DispatchableThread();
|
||||||
|
~DispatchableThread();
|
||||||
|
DispatchableThread(const DispatchableThread& other) = delete;
|
||||||
|
DispatchableThread(DispatchableThread&& other) noexcept = default;
|
||||||
|
DispatchableThread& operator=(const DispatchableThread& other) = delete;
|
||||||
|
DispatchableThread& operator=(DispatchableThread&& other) noexcept = default;
|
||||||
|
|
||||||
|
void Start();
|
||||||
|
void Terminate();
|
||||||
|
|
||||||
|
void Dispatch(cb_t cb);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::optional<cb_t> NextCallback();
|
||||||
|
void ThreadLoop();
|
||||||
|
|
||||||
|
std::mutex m_cb_mutex;
|
||||||
|
std::deque<cb_t> m_cb_list;
|
||||||
|
|
||||||
|
std::condition_variable m_cv;
|
||||||
|
std::thread m_thread;
|
||||||
|
bool m_terminate;
|
||||||
|
};
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "Binds.h"
|
#include "Binds.h"
|
||||||
|
|
||||||
|
#include "FastFileBinds.h"
|
||||||
#include "Web/Binds/DialogBinds.h"
|
#include "Web/Binds/DialogBinds.h"
|
||||||
|
|
||||||
namespace ui
|
namespace ui
|
||||||
@@ -7,5 +8,6 @@ namespace ui
|
|||||||
void RegisterAllBinds(webview::webview& wv)
|
void RegisterAllBinds(webview::webview& wv)
|
||||||
{
|
{
|
||||||
RegisterDialogHandlerBinds(wv);
|
RegisterDialogHandlerBinds(wv);
|
||||||
|
RegisterFastFileBinds(wv);
|
||||||
}
|
}
|
||||||
} // namespace ui
|
} // namespace ui
|
||||||
|
|||||||
28
src/ModMan/Web/Binds/FastFileBinds.cpp
Normal file
28
src/ModMan/Web/Binds/FastFileBinds.cpp
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#include "FastFileBinds.h"
|
||||||
|
|
||||||
|
#include "Context/ModManContext.h"
|
||||||
|
#include "Web/UiCommunication.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace ui
|
||||||
|
{
|
||||||
|
void RegisterFastFileBinds(webview::webview& wv)
|
||||||
|
{
|
||||||
|
BindAsync<std::string>(wv,
|
||||||
|
"loadFastFile",
|
||||||
|
[&wv](const std::string& id, std::string path)
|
||||||
|
{
|
||||||
|
std::string idMove(id);
|
||||||
|
ModManContext::Get().m_db_thread.Dispatch(
|
||||||
|
[&wv, idMove, path]
|
||||||
|
{
|
||||||
|
ModManContext::Get().m_fast_file.LoadFastFile(path);
|
||||||
|
PromiseResolve(wv, idMove, true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} // namespace ui
|
||||||
8
src/ModMan/Web/Binds/FastFileBinds.h
Normal file
8
src/ModMan/Web/Binds/FastFileBinds.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Web/WebViewLib.h"
|
||||||
|
|
||||||
|
namespace ui
|
||||||
|
{
|
||||||
|
void RegisterFastFileBinds(webview::webview& wv);
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#define NOMINMAX
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning(push, 0)
|
#pragma warning(push, 0)
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -116,7 +116,11 @@ int main()
|
|||||||
|
|
||||||
con::info("Starting ModMan " GIT_VERSION);
|
con::info("Starting ModMan " GIT_VERSION);
|
||||||
|
|
||||||
|
ModManContext::Get().Startup();
|
||||||
|
|
||||||
const auto result = SpawnMainWindow();
|
const auto result = SpawnMainWindow();
|
||||||
|
|
||||||
|
ModManContext::Get().Destroy();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,15 @@ import { ref } from "vue";
|
|||||||
import { webviewBinds } from "./native";
|
import { webviewBinds } from "./native";
|
||||||
|
|
||||||
const lastPath = ref("");
|
const lastPath = ref("");
|
||||||
|
const loadingFastFile = ref(false);
|
||||||
|
|
||||||
async function onOpenFastfileClick() {
|
async function onOpenFastfileClick() {
|
||||||
lastPath.value =
|
lastPath.value =
|
||||||
(await webviewBinds.openFileDialog({ filters: [{ name: "Fastfiles", filter: "*.ff" }] })) ?? "";
|
(await webviewBinds.openFileDialog({ filters: [{ name: "Fastfiles", filter: "*.ff" }] })) ?? "";
|
||||||
|
|
||||||
|
loadingFastFile.value = true;
|
||||||
|
await webviewBinds.loadFastFile(lastPath.value);
|
||||||
|
loadingFastFile.value = false;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -18,6 +23,7 @@ async function onOpenFastfileClick() {
|
|||||||
<p>
|
<p>
|
||||||
<button @click="onOpenFastfileClick">Open fastfile</button>
|
<button @click="onOpenFastfileClick">Open fastfile</button>
|
||||||
<span>The last path: {{ lastPath }}</span>
|
<span>The last path: {{ lastPath }}</span>
|
||||||
|
<span>Loading: {{ loadingFastFile }}</span>
|
||||||
</p>
|
</p>
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
3
src/ModManUi/src/native/FastFileBinds.ts
Normal file
3
src/ModManUi/src/native/FastFileBinds.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export interface FastFileBinds {
|
||||||
|
loadFastFile(path: string): Promise<void>;
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import type { DialogBinds } from "./DialogBinds";
|
import type { DialogBinds } from "./DialogBinds";
|
||||||
|
import type { FastFileBinds } from "./FastFileBinds";
|
||||||
|
|
||||||
|
|
||||||
export type NativeMethods = DialogBinds;
|
export type NativeMethods = DialogBinds & FastFileBinds;
|
||||||
|
|
||||||
interface NativeEventMap {
|
interface NativeEventMap {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user