Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
Make official instances editable if boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldieeins committed Jul 3, 2024
1 parent 742cce0 commit c5c9d5e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.zyneonstudios.application;

import com.formdev.flatlaf.FlatDarkLaf;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.zyneonstudios.Main;
import com.zyneonstudios.application.auth.MicrosoftAuth;
import com.zyneonstudios.application.installer.java.OperatingSystem;
Expand All @@ -12,6 +14,7 @@
import com.zyneonstudios.application.utils.frame.web.ZyneonWebFrame;
import live.nerotv.shademebaby.ShadeMeBaby;
import live.nerotv.shademebaby.file.Config;
import live.nerotv.shademebaby.utils.GsonUtil;
import me.friwi.jcefmaven.CefInitializationException;
import me.friwi.jcefmaven.UnsupportedPlatformException;

Expand Down Expand Up @@ -209,6 +212,16 @@ private static boolean saveInstance(List<Map<String, Object>> instanceList, File
modloader = "Fabric " + instance.getFabricVersion();
}
instance_.put("id", instance.getId());

boolean isEditable = true;
try {
if(!new Gson().fromJson(GsonUtil.getFromFile(instance.getFile()), JsonObject.class).getAsJsonObject("instance").getAsJsonObject("meta").get("isEditable").getAsBoolean()) {
isEditable = false;
}
} catch (Exception ignore) {}

instance_.put("isEditable", isEditable);

instance_.put("name", instance.getName());
instance_.put("version", instance.getVersion());
instance_.put("minecraft", instance.getMinecraftVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import live.nerotv.shademebaby.file.Config;
import live.nerotv.shademebaby.file.OnlineConfig;
import live.nerotv.shademebaby.utils.FileUtil;
import live.nerotv.shademebaby.utils.GsonUtil;
import live.nerotv.shademebaby.utils.StringUtil;

import javax.swing.*;
Expand Down Expand Up @@ -278,12 +279,12 @@ public void resolveRequest(String request) {
JsonObject instance = element.getAsJsonObject();
String png = "assets/zyneon/images/instances/" + instance.get("id").toString().replace("\"", "") + ".png";
if (new File(Application.getURLBase() + png).exists()) {
frame.executeJavaScript("addInstanceToList(" + instance.get("id") + "," + instance.get("name") + ",'" + png + "');");
frame.executeJavaScript("addInstanceToList(" + instance.get("id") + "," + instance.get("name") + ",'" + png + "',true);");
} else if (instance.get("icon") != null) {
png = instance.get("icon").toString().replace("\"", "");
frame.executeJavaScript("addInstanceToList(" + instance.get("id") + "," + instance.get("name") + ",'" + png + "');");
frame.executeJavaScript("addInstanceToList(" + instance.get("id") + "," + instance.get("name") + ",'" + png + "',true);");
} else {
frame.executeJavaScript("addInstanceToList(" + instance.get("id") + "," + instance.get("name") + ");");
frame.executeJavaScript("addInstanceToList(" + instance.get("id") + "," + instance.get("name") + ",true);");
}
}
} catch (IOException e) {
Expand Down Expand Up @@ -382,6 +383,13 @@ public void resolveRequest(String request) {
} else {
mlversion = "No mods";
}

try {
if(new Gson().fromJson(GsonUtil.getFromFile(instance.getFile()),JsonObject.class).getAsJsonObject("instance").getAsJsonObject("meta").get("isEditable").getAsBoolean()) {
frame.executeJavaScript("makeEditable(\""+id+"\");");
}
} catch (Exception ignore) {}

File icon = new File(Application.getURLBase() + "assets/zyneon/images/instances/" + id + ".png");
File logo = new File(Application.getURLBase() + "assets/zyneon/images/instances/" + id + "-logo.png");
File background = new File(Application.getURLBase() + "assets/zyneon/images/instances/" + id + ".webp");
Expand Down
Binary file modified application-main/src/main/resources/content.zip
Binary file not shown.
39 changes: 25 additions & 14 deletions application-ui/content/assets/zyneon/js/instances.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function syncInstanceList() {
callJavaMethod("sync.instances.list");
}

function loadTab(tab) {
function loadTab(tab,editable) {
const urlParams = new URLSearchParams(window.location.search);
let tab_ = "zyneon::overview";
if(urlParams.get("tab")!=null) {
Expand All @@ -41,19 +41,19 @@ function loadTab(tab) {
}
}
if(document.getElementById(tab)!==null) {
syncInstance(tab_);
syncInstance(tab_,editable);
}
}

function addInstanceToList(id,name,png) {
function addInstanceToList(id,name,png,editable) {
const base = document.getElementById("list-template");
const instance = base.cloneNode(true);
instance.id = id;
base.parentNode.insertBefore(instance, base);
const a = instance.querySelector("a");
if (a) {
a.onclick = function () {
syncInstance(id);
syncInstance(id,editable);
}
}
const i = instance.querySelector("i");
Expand All @@ -76,7 +76,14 @@ function addInstanceToList(id,name,png) {
}
}

function syncInstance(id) {
function syncInstance(id,editableBool) {
let editable = false;
if(editableBool) {
if (editableBool === true||editableBool === "true") {
editable = true;
}
}

closeSettings();
document.getElementById("instance-adder").style.display = "none";
document.getElementById("instance-view").style.display = "inherit";
Expand All @@ -87,22 +94,17 @@ function syncInstance(id) {
document.getElementById("open-instance").onclick = function () { callJavaMethod("button.folder."+id); };
document.getElementById("open-mods").onclick = function () { callJavaMethod("button.mods."+id); };

if(id.includes("official/")) {
if(!id.includes("official/")||editable) {
makeEditable(id);
} else {
document.getElementById("check").style.display = "inherit";
document.getElementById("open-instance").style.display = "none";
document.getElementById("content").style.display = "none";
document.getElementById("open-mods").style.display = "none";
document.getElementById("local-settings").style.display = "none";
document.getElementById("local-appearance").style.display = "none";
document.getElementById("check").style.display = "inherit";
document.getElementById("folder").onclick = function () {};
} else {
document.getElementById("check").style.display = "none";
document.getElementById("content").style.display = "inherit";
document.getElementById("open-instance").style.display = "inherit";
document.getElementById("open-mods").style.display = "inherit";
document.getElementById("local-settings").style.display = "inherit";
document.getElementById("local-appearance").style.display = "inherit";
document.getElementById("folder").onclick = function () { callJavaMethod("button.folder."+id); };
}

document.getElementById("configure-memory").onclick = function () { callJavaMethod("button.settings."+id); };
Expand All @@ -112,6 +114,15 @@ function syncInstance(id) {
callJavaMethod("button.instance." + id);
}

function makeEditable(id) {
document.getElementById("content").style.display = "inherit";
document.getElementById("open-instance").style.display = "inherit";
document.getElementById("open-mods").style.display = "inherit";
document.getElementById("local-settings").style.display = "inherit";
document.getElementById("local-appearance").style.display = "inherit";
document.getElementById("folder").onclick = function () { callJavaMethod("button.folder."+id); };
}

function syncTitle(name,png) {
document.getElementById("title").innerText = name;
if(png !== undefined) {
Expand Down

0 comments on commit c5c9d5e

Please sign in to comment.