Petrichor
Loading...
Searching...
No Matches
petrichor.h
1/*
2 * Petrichor public API
3 * Copyright (C) 2026 Linifadomra Org.
4 *
5 * This file is part of Petrichor.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (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, see <https://www.gnu.org/licenses/>.
19 */
20#pragma once
21#include <stdint.h>
22#include <string>
23#include <vector>
24
34 char id[64];
35
37 char name[128];
38
40 char kind[16];
41
43 char type[32];
44
46 char entry[128];
47
49 char author[128];
50
52 char version[32];
53
55 char hostVersion[32];
56
58 char engineVersion[32];
59
61 std::string desc;
62
64 std::vector<std::string> conflicts;
65
67 std::string dir;
68};
69
73enum class PetrichorLogLevel : uint8_t { Info = 0, Warn, Error, Debug };
74
90 virtual void log(PetrichorLogLevel level, const char* tag, const char* msg) const = 0;
91
93 virtual const char* mods_dir() const = 0;
94
96 virtual const char* temp_dir() const = 0;
97
103 virtual const char* store_dir() const { return nullptr; }
104
113 virtual const char* version() const { return "unversioned"; }
114
127 virtual void mod_ctx_enter(const char* dir, const char* id) {}
128
135 virtual void mod_ctx_exit() {}
136
144 virtual const char* project_name() const { return "unnamed"; }
145
146
148 virtual ~IPetrichorHost() = default;
149};
150
160void petrichor_run(IPetrichorHost& host, std::vector<std::string> formats = {"prm","zip"});
161
170void petrichor_tick(IPetrichorHost& host, float delta);
171
179void petrichor_stop(IPetrichorHost& host);
180
186void petrichor_unload_mod(const char* id);
187
195void petrichor_reload_mod(const char* id);
196
204std::vector<std::string> petrichor_poll_changes();
205
212void petrichor_rescan_dir(IPetrichorHost& host, std::vector<std::string> formats = {"prm","zip"});
213
219std::vector<PetrichorManifest> petrichor_get_mods();
220
221#ifdef __cplusplus
222struct lua_State;
223namespace petrichor {
224
231 using ModuleFactory = int(*)(lua_State*);
232
242 void luau_register_module(const char* name, ModuleFactory factory);
243
250 lua_State* lua_state();
251
252}
253#endif
Petrichor consumer-level interface.
Definition petrichor.h:83
virtual const char * temp_dir() const =0
Returns the host's temporary working directory.
virtual const char * mods_dir() const =0
Returns the root directory containing installed packages.
virtual const char * version() const
Returns the current project version.
Definition petrichor.h:113
virtual const char * store_dir() const
Returns the directory used for persistent package storage.
Definition petrichor.h:103
virtual const char * project_name() const
Returns the current project name.
Definition petrichor.h:144
virtual void mod_ctx_exit()
Notifies the host that the current mod context is ending.
Definition petrichor.h:135
virtual void log(PetrichorLogLevel level, const char *tag, const char *msg) const =0
Writes a log message through the host.
virtual ~IPetrichorHost()=default
Virtual destructor.
virtual void mod_ctx_enter(const char *dir, const char *id)
Notifies the host that a mod's context is becoming active.
Definition petrichor.h:127
Manifest describing a Petrichor package.
Definition petrichor.h:32
char name[128]
Human-readable package name.
Definition petrichor.h:37
char entry[128]
Relative path to the package entry point.
Definition petrichor.h:46
char version[32]
Package version string.
Definition petrichor.h:52
std::vector< std::string > conflicts
List of incompatible package IDs.
Definition petrichor.h:64
std::string dir
Absolute path to the package's root directory.
Definition petrichor.h:67
char hostVersion[32]
Host-project version string.
Definition petrichor.h:55
char engineVersion[32]
Petrichor engine version string.
Definition petrichor.h:58
char kind[16]
Package kind: "code", "asset", or "mixed".
Definition petrichor.h:40
char author[128]
Package author.
Definition petrichor.h:49
char type[32]
Package type or category.
Definition petrichor.h:43
std::string desc
Package description.
Definition petrichor.h:61