Merge branch 'main' of https://github.com/OpenStarbound/OpenStarbound
This commit is contained in:
commit
c999e2f4f5
@ -151,7 +151,7 @@ Assets::Assets(Settings settings, StringList assetSources) {
|
||||
// re-add the assets callbacks with more functions
|
||||
context.remove("assets");
|
||||
auto callbacks = makeBaseAssetCallbacks();
|
||||
callbacks.registerCallback("add", [&newFiles](LuaEngine& engine, String const& path, LuaValue const& data) {
|
||||
callbacks.registerCallback("add", [newFiles](LuaEngine& engine, String const& path, LuaValue const& data) {
|
||||
ByteArray bytes;
|
||||
if (auto str = engine.luaMaybeTo<String>(data))
|
||||
bytes = ByteArray(str->utf8Ptr(), str->utf8Size());
|
||||
@ -165,7 +165,7 @@ Assets::Assets(Settings settings, StringList assetSources) {
|
||||
newFiles->set(path, bytes);
|
||||
});
|
||||
|
||||
callbacks.registerCallback("patch", [this, &newFiles](String const& path, String const& patchPath) -> bool {
|
||||
callbacks.registerCallback("patch", [this, newFiles](String const& path, String const& patchPath) -> bool {
|
||||
if (auto file = m_files.ptr(path)) {
|
||||
if (newFiles->contains(patchPath)) {
|
||||
file->patchSources.append(make_pair(patchPath, newFiles));
|
||||
|
@ -39,7 +39,7 @@ template <typename InputIterator>
|
||||
class JsonParser {
|
||||
public:
|
||||
JsonParser(JsonStream& stream)
|
||||
: m_line(0), m_column(0), m_stream(stream), m_error(nullptr) {}
|
||||
: m_line(0), m_column(0), m_error(nullptr), m_stream(stream) {}
|
||||
virtual ~JsonParser() {}
|
||||
|
||||
// Does not throw. On error, returned iterator will not be equal to end, and
|
||||
|
@ -375,7 +375,7 @@ ItemRecipe ItemDatabase::parseRecipe(Json const& config) const {
|
||||
return res;
|
||||
}
|
||||
|
||||
HashSet<ItemRecipe> ItemDatabase::allRecipes() const {
|
||||
HashSet<ItemRecipe> const& ItemDatabase::allRecipes() const {
|
||||
return m_recipes;
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,7 @@ public:
|
||||
|
||||
ItemRecipe parseRecipe(Json const& config) const;
|
||||
|
||||
HashSet<ItemRecipe> allRecipes() const;
|
||||
HashSet<ItemRecipe> const& allRecipes() const;
|
||||
HashSet<ItemRecipe> allRecipes(StringSet const& types) const;
|
||||
|
||||
ItemPtr applyAugment(ItemPtr const item, AugmentItem* augment) const;
|
||||
|
@ -5,9 +5,10 @@
|
||||
|
||||
namespace Star {
|
||||
|
||||
Json ItemRecipe::toJson() {
|
||||
Json ItemRecipe::toJson() const {
|
||||
JsonArray inputList;
|
||||
for (auto input : inputs)
|
||||
inputList.reserve(inputList.size());
|
||||
for (auto& input : inputs)
|
||||
inputList.append(input.toJson());
|
||||
|
||||
return JsonObject{
|
||||
@ -21,7 +22,7 @@ Json ItemRecipe::toJson() {
|
||||
};
|
||||
}
|
||||
|
||||
bool ItemRecipe::isNull() {
|
||||
bool ItemRecipe::isNull() const {
|
||||
return currencyInputs.size() == 0 && inputs.size() == 0 && output.isNull();
|
||||
}
|
||||
|
||||
|
@ -8,9 +8,9 @@ namespace Star {
|
||||
STAR_EXCEPTION(RecipeException, StarException);
|
||||
|
||||
struct ItemRecipe {
|
||||
Json toJson();
|
||||
Json toJson() const;
|
||||
|
||||
bool isNull();
|
||||
bool isNull() const;
|
||||
|
||||
bool operator==(ItemRecipe const& rhs) const;
|
||||
bool operator!=(ItemRecipe const& rhs) const;
|
||||
|
@ -100,9 +100,11 @@ bool TileDrawer::produceTerrainDrawables(Drawables& drawables,
|
||||
return false;
|
||||
|
||||
auto getPieceImage = [](MaterialRenderPieceConstPtr const& piece, Box<float, 2> const& box, MaterialHue hue, Directives const* directives) -> AssetPath {
|
||||
AssetPath image = hue == 0
|
||||
String path = (hue == 0)
|
||||
? strf("{}?crop={};{};{};{}", piece->texture, box.xMin(), box.yMin(), box.xMax(), box.yMax())
|
||||
: strf("{}?crop={};{};{};{}?hueshift={}", piece->texture, box.xMin(), box.yMin(), box.xMax(), box.yMax(), materialHueToDegrees(hue));
|
||||
|
||||
AssetPath image(path);
|
||||
if (directives)
|
||||
image.directives += *directives;
|
||||
|
||||
|
@ -247,6 +247,17 @@ LuaCallbacks LuaBindings::makePlayerCallbacks(Player* player) {
|
||||
|
||||
callbacks.registerCallback("blueprintKnown", [player](Json const& item) { return player->blueprintKnown(ItemDescriptor(item)); });
|
||||
|
||||
callbacks.registerCallback("availableRecipes", [player](Maybe<StringSet> const& filter) {
|
||||
auto itemDatabase = Root::singleton().itemDatabase();
|
||||
auto inventory = player->inventory();
|
||||
auto recipes = itemDatabase->recipesFromBagContents(inventory->availableItems(), inventory->availableCurrencies(), filter.value());
|
||||
JsonArray result;
|
||||
result.reserve(recipes.size());
|
||||
for (auto& recipe : recipes)
|
||||
result.append(recipe.toJson());
|
||||
return result;
|
||||
});
|
||||
|
||||
callbacks.registerCallback("makeTechAvailable", [player](String const& tech) {
|
||||
player->techs()->makeAvailable(tech);
|
||||
});
|
||||
|
@ -44,7 +44,8 @@ LuaCallbacks LuaBindings::makeRootCallbacks() {
|
||||
callbacks.registerCallbackWithSignature<Json, String>("npcConfig", bind(RootCallbacks::npcConfig, root, _1));
|
||||
callbacks.registerCallbackWithSignature<float, String>("projectileGravityMultiplier", bind(RootCallbacks::projectileGravityMultiplier, root, _1));
|
||||
callbacks.registerCallbackWithSignature<Json, String>("projectileConfig", bind(RootCallbacks::projectileConfig, root, _1));
|
||||
callbacks.registerCallbackWithSignature<Json, String>("recipesForItem", bind(RootCallbacks::recipesForItem, root, _1));
|
||||
callbacks.registerCallbackWithSignature<JsonArray, String>("recipesForItem", bind(RootCallbacks::recipesForItem, root, _1));
|
||||
callbacks.registerCallbackWithSignature<JsonArray>("allRecipes", bind(RootCallbacks::allRecipes, root));
|
||||
callbacks.registerCallbackWithSignature<String, String>("itemType", bind(RootCallbacks::itemType, root, _1));
|
||||
callbacks.registerCallbackWithSignature<Json, String>("itemTags", bind(RootCallbacks::itemTags, root, _1));
|
||||
callbacks.registerCallbackWithSignature<bool, String, String>("itemHasTag", bind(RootCallbacks::itemHasTag, root, _1, _2));
|
||||
@ -308,10 +309,20 @@ Json LuaBindings::RootCallbacks::projectileConfig(Root* root, String const& arg1
|
||||
return projectileDatabase->projectileConfig(arg1);
|
||||
}
|
||||
|
||||
Json LuaBindings::RootCallbacks::recipesForItem(Root* root, String const& arg1) {
|
||||
JsonArray LuaBindings::RootCallbacks::recipesForItem(Root* root, String const& arg1) {
|
||||
auto recipes = root->itemDatabase()->recipesForOutputItem(arg1);
|
||||
JsonArray result;
|
||||
for (auto recipe : recipes)
|
||||
result.reserve(recipes.size());
|
||||
for (auto& recipe : recipes)
|
||||
result.append(recipe.toJson());
|
||||
return result;
|
||||
}
|
||||
|
||||
JsonArray LuaBindings::RootCallbacks::allRecipes(Root* root) {
|
||||
auto& recipes = root->itemDatabase()->allRecipes();
|
||||
JsonArray result;
|
||||
result.reserve(recipes.size());
|
||||
for (auto& recipe : recipes)
|
||||
result.append(recipe.toJson());
|
||||
return result;
|
||||
}
|
||||
|
@ -26,7 +26,8 @@ namespace LuaBindings {
|
||||
Json npcConfig(Root* root, String const& arg1);
|
||||
float projectileGravityMultiplier(Root* root, String const& arg1);
|
||||
Json projectileConfig(Root* root, String const& arg1);
|
||||
Json recipesForItem(Root* root, String const& arg1);
|
||||
JsonArray recipesForItem(Root* root, String const& arg1);
|
||||
JsonArray allRecipes(Root* root);
|
||||
String itemType(Root* root, String const& itemName);
|
||||
Json itemTags(Root* root, String const& itemName);
|
||||
bool itemHasTag(Root* root, String const& itemName, String const& itemTag);
|
||||
|
Loading…
Reference in New Issue
Block a user