Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/sprites/blocks/storage/trading-post.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/betamindy/BetaMindy.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ public void init(){
}
});

new JsonShopPackageLoader().loadPackages();

hardmode.init();
Events.run(Trigger.update, () -> {
if(state.isPlaying()) hardmode.update();
Expand Down
2 changes: 1 addition & 1 deletion src/betamindy/content/MindyBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ public boolean isHidden(){
requirements(Category.effect, uwu ? BuildVisibility.shown : BuildVisibility.sandboxOnly, with(Items.copper, 1));
size = 3;
defaultAnucoins = 1000;
purchases = new PurchaseItem[]{package1, new ItemItem(MindyItems.source, 420, 69), new LiquidItem(Liquids.cryofluid, 5, 50f), new LiquidItem(Liquids.slag, 5, 50f), milk, coffee, herbTea, flowerTea, cocktail, holyRouter, new PurchaseInvBlock(starPen, 1, 1), new PurchaseInvBlock(Blocks.arc, 1699, 3)};
purchases = new PurchaseItem[]{package1, new ItemItem(MindyItems.source, 420, 69), new LiquidItem(Liquids.cryofluid, 5, 50f), new LiquidItem(Liquids.slag, 5, 50f), milk, coffee, herbTea, flowerTea, cocktail, holyRouter, new PurchaseInvBlock(starPen, 1, 1)};
sellAllItems = sellAllUnits = sellAllBlocks = navigationBar = true;
alwaysUnlocked = uwu;
}};
Expand Down
10 changes: 10 additions & 0 deletions src/betamindy/type/shop/ItemType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package betamindy.type.shop;


public enum ItemType {
Package,
Runnable,
Block,
BlockInv,
Liquid;
}
52 changes: 52 additions & 0 deletions src/betamindy/type/shop/JsonShopPackage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package betamindy.type.shop;

import arc.func.*;
import arc.util.Log;
import betamindy.type.*;
import mindustry.ctype.UnlockableContent;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.world.Block;
//import rhino.*;

public class JsonShopPackage {
public Boolf<Building> purchased, unlocked;

public void invoke(Boolf<Building> purchased, Boolf<Building> unlocked){
this.purchased = purchased;
this.unlocked = unlocked;
}

public PurchaseItem NewJsonShopPackage(String name, ItemType itemType, ItemStack[] items, Integer cost, String code, UnlockableContent cItem, Integer amount, boolean iAbort){
PurchaseItem item;

//For later fixing and usage at stable v7
/*if(code == null) return null;

Context ctx = Context.enter();
Scriptable scope = ctx.initStandardObjects();

Object wrappedStock = Context.javaToJS(this, scope);
ScriptableObject.putProperty(scope, "pkg", wrappedStock);

ctx.evaluateString(scope, code.replace("\n", ""), "PackageScript", 1, null);

Context.exit();

item = new PurchaseRunnable(name, cost){{
purchased = e -> this.purchased.get(e);

unlocked = e -> this.unlocked.get(e);
}};*/

item = switch (itemType) {
case Package -> new PackageShopItem(name, items){{abort = iAbort;}};
case Runnable -> new PurchaseRunnable(null, 0){{abort = iAbort;}};
case Block -> new BlockItem((Block) cItem, cost){{abort = iAbort;}};
case BlockInv -> new PurchaseInvBlock((Block) cItem, cost, amount){{abort = iAbort;}};
case Liquid -> new LiquidItem((Liquid) cItem, cost, amount){{abort = iAbort;}};
};

return item;
}
}
26 changes: 26 additions & 0 deletions src/betamindy/type/shop/ShopPackageType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package betamindy.type.shop;

import mindustry.type.*;

import java.util.*;

public class ShopPackageType {
public String itemType, shop, item, codePath;
public Integer cost, amount;
public Boolean abort;
public ItemStack[] items = {};

@Override
public String toString(){
return "ShopPackageType{" +
"itemType=" + itemType +
"item=" + item +
"codePath=" + codePath +
", cost=" + cost +
", amount=" + amount +
", abort=" + abort +
", shop=" + shop +
", items=" + Arrays.toString(items) +
'}';
}
}
87 changes: 87 additions & 0 deletions src/betamindy/util/JsonShopPackageLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package betamindy.util;

import arc.files.*;
import arc.util.*;
import arc.util.serialization.*;
import betamindy.content.*;
import betamindy.type.*;
import betamindy.type.shop.*;
import betamindy.world.blocks.storage.*;
import mindustry.ctype.*;
import mindustry.io.*;
import mindustry.type.*;

import static mindustry.Vars.*;

public class JsonShopPackageLoader {
public void loadPackages() {
mods.list().each(e -> {
if(!e.isJava()) {
Fi path = e.root.child("content");
if(path != null) path = path.child("shopItems");
final Fi finalPath = path;

if(path != null){
path.walk(c -> {
if(c.extEquals("json")/* ||c.extEquals("hjson")*/){
ShopPackageType pack;

/*idk how does this work so i'll just ignore hjson
if(c.extEquals("hjson")){
pack = JsonIO.json.fromJson(ShopPackageType.class, String.valueOf(Jval.read(c.readString()).toString(Jval.Jformat.plain)));
} else {*/
pack = JsonIO.json.fromJson(ShopPackageType.class, c.readString());
//}

String name = e.meta.name + "." + c.nameWithoutExtension();

if(pack != null){
String itemType = pack.itemType;
Shop shop = (Shop) MindyBlocks.extraShop;
ItemStack[] items = pack.items;

if(pack.shop != null) {
try {
shop = (Shop) content.block("betamindy-" + pack.shop);
} catch(Exception ex){
Log.err(e.meta.name + ": Shop \"" + pack.shop + "\" doesn't exist or can't be found. Defaulted to Extra Shop.");
}
}

Fi codeFile = finalPath.child(pack.codePath + ".js");
String code = null;

if(codeFile.exists()){
code = codeFile.readString();
Log.info(code);
}

ItemType type = ItemType.valueOf(itemType);
UnlockableContent cItem = switch (type){
case Block, BlockInv -> content.block(pack.item);
case Liquid -> content.getByName(ContentType.liquid, pack.item);
default -> null;
};

boolean abort = false;
if(pack.abort != null) abort = pack.abort;

PurchaseItem item = new JsonShopPackage().NewJsonShopPackage(name, type, items, pack.cost == null ? 69 : pack.cost, code, cItem, pack.amount, abort);

if(item instanceof PurchaseRunnable){
Log.info("Runnables in json are not supported yet. Please wait until v7.");
} else {
if (item != null && shop != null) {
shop.jsonItems.add(item);
} else {
Log.err("Package error for package " + name);
}
}
}
}
});
}
}
});
}
}
17 changes: 15 additions & 2 deletions src/betamindy/world/blocks/storage/Shop.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import static arc.Core.atlas;
import static mindustry.Vars.*;

@SuppressWarnings("al")
@SuppressWarnings("all")
public class Shop extends PayloadAcceptor {
public int defaultAnucoins = 0;
public TextureRegion spinRegion;
Expand All @@ -45,14 +45,15 @@ public class Shop extends PayloadAcceptor {
public float spinShadowRadius = 15f;
public boolean drawSpinSprite = false;

public Seq<PurchaseItem> jsonItems = new Seq<>();
public @Nullable PurchaseItem[] purchases;
public @Nullable Block[] soldBlocks;
public boolean sellAllItems = false;
public boolean sellAllUnits = false;
public boolean sellAllBlocks = false;
public boolean navigationBar = false;

BaseDialog shopDialog;
BaseDialog shopDialog = null;
String searchString = "";
Cell<ScrollPane> itemCell;

Expand Down Expand Up @@ -130,6 +131,13 @@ public void init(){
unitScores = BetaMindy.unitScores;

if(purchases != null) {
if(jsonItems.size > 0) {
Seq<PurchaseItem> temp = new Seq();
temp.addAll(purchases);
temp.addAll(jsonItems);
purchases = temp.toArray();
}

for (PurchaseItem purchase : purchases) {
if (purchase instanceof PackageShopItem p && p.cost == 0) {
p.definePrice();
Expand Down Expand Up @@ -570,6 +578,11 @@ public void buildConfiguration(Table table) {
shopDialog.addCloseButton();
}

if(shopDialog == null) {
shopDialog = new BaseDialog(Core.bundle.get("ui.shop.title"));
shopDialog.addCloseButton();
}

float width = Math.min(Core.graphics.getWidth(), Core.graphics.getHeight());
//float height = Math.max(Core.graphics.getWidth(), Core.graphics.getHeight());

Expand Down