Mod subtitles
This commit is contained in:
@@ -5,15 +5,7 @@ let modName = "none"
|
|||||||
|
|
||||||
const log = (context, obj) => Vars.mods.scripts.log(context, String(obj))
|
const log = (context, obj) => Vars.mods.scripts.log(context, String(obj))
|
||||||
const print = text => log(modName + "/" + scriptName, text)
|
const print = text => log(modName + "/" + scriptName, text)
|
||||||
const readString = path => Vars.mods.scripts.readString(path)
|
|
||||||
const readBytes = path => Vars.mods.scripts.readBytes(path)
|
|
||||||
const loadMusic = path => Vars.mods.scripts.loadMusic(path)
|
|
||||||
const loadSound = path => Vars.mods.scripts.loadSound(path)
|
|
||||||
|
|
||||||
const readFile = (purpose, ext, cons) => Vars.mods.scripts.readFile(purpose, ext, cons);
|
|
||||||
const readBinFile = (purpose, ext, cons) => Vars.mods.scripts.readBinFile(purpose, ext, cons);
|
|
||||||
const writeFile = (purpose, ext, str) => Vars.mods.scripts.writeFile(purpose, ext, str);
|
|
||||||
const writeBinFile = (purpose, ext, bytes) => Vars.mods.scripts.writeBinFile(purpose, ext, bytes);
|
|
||||||
const newFloats = cap => Vars.mods.getScripts().newFloats(cap);
|
const newFloats = cap => Vars.mods.getScripts().newFloats(cap);
|
||||||
|
|
||||||
//these are not strictly necessary, but are kept for edge cases
|
//these are not strictly necessary, but are kept for edge cases
|
||||||
|
|||||||
@@ -7,15 +7,7 @@ let modName = "none"
|
|||||||
|
|
||||||
const log = (context, obj) => Vars.mods.scripts.log(context, String(obj))
|
const log = (context, obj) => Vars.mods.scripts.log(context, String(obj))
|
||||||
const print = text => log(modName + "/" + scriptName, text)
|
const print = text => log(modName + "/" + scriptName, text)
|
||||||
const readString = path => Vars.mods.scripts.readString(path)
|
|
||||||
const readBytes = path => Vars.mods.scripts.readBytes(path)
|
|
||||||
const loadMusic = path => Vars.mods.scripts.loadMusic(path)
|
|
||||||
const loadSound = path => Vars.mods.scripts.loadSound(path)
|
|
||||||
|
|
||||||
const readFile = (purpose, ext, cons) => Vars.mods.scripts.readFile(purpose, ext, cons);
|
|
||||||
const readBinFile = (purpose, ext, cons) => Vars.mods.scripts.readBinFile(purpose, ext, cons);
|
|
||||||
const writeFile = (purpose, ext, str) => Vars.mods.scripts.writeFile(purpose, ext, str);
|
|
||||||
const writeBinFile = (purpose, ext, bytes) => Vars.mods.scripts.writeBinFile(purpose, ext, bytes);
|
|
||||||
const newFloats = cap => Vars.mods.getScripts().newFloats(cap);
|
const newFloats = cap => Vars.mods.getScripts().newFloats(cap);
|
||||||
|
|
||||||
//these are not strictly necessary, but are kept for edge cases
|
//these are not strictly necessary, but are kept for edge cases
|
||||||
@@ -49,6 +41,7 @@ function extend(/*Base, ..., def*/){
|
|||||||
return instance
|
return instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
importPackage(Packages.arc)
|
importPackage(Packages.arc)
|
||||||
importPackage(Packages.arc.audio)
|
importPackage(Packages.arc.audio)
|
||||||
importPackage(Packages.arc.func)
|
importPackage(Packages.arc.func)
|
||||||
|
|||||||
@@ -139,6 +139,8 @@ public class Vars implements Loadable{
|
|||||||
public static final int port = 6567;
|
public static final int port = 6567;
|
||||||
/** multicast discovery port.*/
|
/** multicast discovery port.*/
|
||||||
public static final int multicastPort = 20151;
|
public static final int multicastPort = 20151;
|
||||||
|
/** Maximum char length of mod subtitles in browser/viewer. */
|
||||||
|
public static final int maxModSubtitleLength = 40;
|
||||||
/** multicast group for discovery.*/
|
/** multicast group for discovery.*/
|
||||||
public static final String multicastGroup = "227.2.7.7";
|
public static final String multicastGroup = "227.2.7.7";
|
||||||
/** whether the graphical game client has loaded */
|
/** whether the graphical game client has loaded */
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package mindustry.mod;
|
|||||||
|
|
||||||
/** Mod listing as a data class. */
|
/** Mod listing as a data class. */
|
||||||
public class ModListing{
|
public class ModListing{
|
||||||
public String repo, name, author, lastUpdated, description, minGameVersion;
|
public String repo, name, subtitle, author, lastUpdated, description, minGameVersion;
|
||||||
public boolean hasScripts, hasJava;
|
public boolean hasScripts, hasJava;
|
||||||
public String[] contentTypes = {};
|
public String[] contentTypes = {};
|
||||||
public int stars;
|
public int stars;
|
||||||
|
|||||||
@@ -1136,7 +1136,7 @@ public class Mods implements Loadable{
|
|||||||
|
|
||||||
/** Mod metadata information.*/
|
/** Mod metadata information.*/
|
||||||
public static class ModMeta{
|
public static class ModMeta{
|
||||||
public String name, displayName, author, description, version, main, minGameVersion = "0", repo;
|
public String name, displayName, author, description, subtitle, version, main, minGameVersion = "0", repo;
|
||||||
public Seq<String> dependencies = Seq.with();
|
public Seq<String> dependencies = Seq.with();
|
||||||
/** Hidden mods are only server-side or client-side, and do not support adding new content. */
|
/** Hidden mods are only server-side or client-side, and do not support adding new content. */
|
||||||
public boolean hidden;
|
public boolean hidden;
|
||||||
@@ -1147,11 +1147,16 @@ public class Mods implements Loadable{
|
|||||||
return displayName == null ? name : displayName;
|
return displayName == null ? name : displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String shortDescription(){
|
||||||
|
return Strings.truncate(subtitle == null ? (description == null || description.length() > maxModSubtitleLength ? "" : description) : subtitle, maxModSubtitleLength, "...");
|
||||||
|
}
|
||||||
|
|
||||||
//removes all colors
|
//removes all colors
|
||||||
public void cleanup(){
|
public void cleanup(){
|
||||||
if(displayName != null) displayName = Strings.stripColors(displayName);
|
if(displayName != null) displayName = Strings.stripColors(displayName);
|
||||||
if(author != null) author = Strings.stripColors(author);
|
if(author != null) author = Strings.stripColors(author);
|
||||||
if(description != null) description = Strings.stripColors(description);
|
if(description != null) description = Strings.stripColors(description);
|
||||||
|
if(subtitle != null) subtitle = Strings.stripColors(subtitle).replace("\n", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMinMajor(){
|
public int getMinMajor(){
|
||||||
|
|||||||
@@ -2,10 +2,8 @@ package mindustry.mod;
|
|||||||
|
|
||||||
import arc.*;
|
import arc.*;
|
||||||
import arc.files.*;
|
import arc.files.*;
|
||||||
import arc.func.*;
|
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import arc.util.Log.*;
|
import arc.util.Log.*;
|
||||||
import arc.util.io.*;
|
|
||||||
import mindustry.*;
|
import mindustry.*;
|
||||||
import mindustry.mod.Mods.*;
|
import mindustry.mod.Mods.*;
|
||||||
import rhino.*;
|
import rhino.*;
|
||||||
@@ -67,60 +65,10 @@ public class Scripts implements Disposable{
|
|||||||
Log.log(level, "[@]: @", source, message);
|
Log.log(level, "[@]: @", source, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
//region utility mod functions
|
|
||||||
|
|
||||||
public float[] newFloats(int capacity){
|
public float[] newFloats(int capacity){
|
||||||
return new float[capacity];
|
return new float[capacity];
|
||||||
}
|
}
|
||||||
|
|
||||||
public String readString(String path){
|
|
||||||
return Vars.tree.get(path, true).readString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] readBytes(String path){
|
|
||||||
return Vars.tree.get(path, true).readBytes();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Ask the user to select a file to read for a certain purpose like "Please upload a sprite" */
|
|
||||||
public void readFile(String purpose, String ext, Cons<String> cons){
|
|
||||||
selectFile(true, purpose, ext, fi -> cons.get(fi.readString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** readFile but for a byte[] */
|
|
||||||
public void readBinFile(String purpose, String ext, Cons<byte[]> cons){
|
|
||||||
selectFile(true, purpose, ext, fi -> cons.get(fi.readBytes()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Ask the user to write a file. */
|
|
||||||
public void writeFile(String purpose, String ext, String contents){
|
|
||||||
if(contents == null) contents = "";
|
|
||||||
final String fContents = contents;
|
|
||||||
selectFile(false, purpose, ext, fi -> fi.writeString(fContents));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** writeFile but for a byte[] */
|
|
||||||
public void writeBinFile(String purpose, String ext, byte[] contents){
|
|
||||||
if(contents == null) contents = Streams.emptyBytes;
|
|
||||||
final byte[] fContents = contents;
|
|
||||||
selectFile(false, purpose, ext, fi -> fi.writeBytes(fContents));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void selectFile(boolean open, String purpose, String ext, Cons<Fi> cons){
|
|
||||||
purpose = purpose.startsWith("@") ? Core.bundle.get(purpose.substring(1)) : purpose;
|
|
||||||
//add purpose and extension at the top
|
|
||||||
String title = Core.bundle.get(open ? "open" : "save") + " - " + purpose + " (." + ext + ")";
|
|
||||||
Vars.platform.showFileChooser(open, title, ext, fi -> {
|
|
||||||
try{
|
|
||||||
cons.get(fi);
|
|
||||||
}catch(Exception e){
|
|
||||||
Log.err("Failed to select file '@' for a mod", fi);
|
|
||||||
Log.err(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//endregion
|
|
||||||
|
|
||||||
public void run(LoadedMod mod, Fi file){
|
public void run(LoadedMod mod, Fi file){
|
||||||
currentMod = mod;
|
currentMod = mod;
|
||||||
run(file.readString(), file.name(), true);
|
run(file.readString(), file.name(), true);
|
||||||
|
|||||||
@@ -242,8 +242,13 @@ public class ModsDialog extends BaseDialog{
|
|||||||
|
|
||||||
title1.table(text -> {
|
title1.table(text -> {
|
||||||
boolean hideDisabled = !item.isSupported() || item.hasUnmetDependencies() || item.hasContentErrors();
|
boolean hideDisabled = !item.isSupported() || item.hasUnmetDependencies() || item.hasContentErrors();
|
||||||
|
String shortDesc = item.meta.shortDescription();
|
||||||
|
|
||||||
|
text.add("[accent]" + Strings.stripColors(item.meta.displayName()) + "\n" +
|
||||||
|
(shortDesc.length() > 0 ? "[lightgray]" + shortDesc + "\n" : "")
|
||||||
|
+ "[gray]v" + Strings.stripColors(trimText(item.meta.version))
|
||||||
|
+ (item.enabled() || hideDisabled ? "" : "\n" + Core.bundle.get("mod.disabled") + ""))
|
||||||
|
|
||||||
text.add("[accent]" + Strings.stripColors(item.meta.displayName()) + "\n[lightgray]v" + Strings.stripColors(trimText(item.meta.version)) + (item.enabled() || hideDisabled ? "" : "\n" + Core.bundle.get("mod.disabled") + ""))
|
|
||||||
.wrap().top().width(300f).growX().left();
|
.wrap().top().width(300f).growX().left();
|
||||||
|
|
||||||
text.row();
|
text.row();
|
||||||
@@ -472,9 +477,9 @@ public class ModsDialog extends BaseDialog{
|
|||||||
con.add(
|
con.add(
|
||||||
"[accent]" + mod.name.replace("\n", "") +
|
"[accent]" + mod.name.replace("\n", "") +
|
||||||
(installed.contains(mod.repo) ? "\n[lightgray]" + Core.bundle.get("mod.installed") : "") +
|
(installed.contains(mod.repo) ? "\n[lightgray]" + Core.bundle.get("mod.installed") : "") +
|
||||||
//"[white]\n[lightgray]Author:[] " + trimText(mod.author) +
|
|
||||||
"\n[lightgray]\uE809 " + mod.stars +
|
"\n[lightgray]\uE809 " + mod.stars +
|
||||||
(Version.isAtLeast(mod.minGameVersion) ? "" : "\n" + Core.bundle.format("mod.requiresversion", mod.minGameVersion)))
|
(Version.isAtLeast(mod.minGameVersion) ? mod.subtitle == null ? "" : "\n[lightgray]" + Strings.truncate(mod.subtitle, maxModSubtitleLength) :
|
||||||
|
"\n" + Core.bundle.format("mod.requiresversion", mod.minGameVersion)))
|
||||||
.width(358f).wrap().grow().pad(4f, 2f, 4f, 6f).top().left().labelAlign(Align.topLeft);
|
.width(358f).wrap().grow().pad(4f, 2f, 4f, 6f).top().left().labelAlign(Align.topLeft);
|
||||||
|
|
||||||
}, Styles.clearPartialt, () -> {
|
}, Styles.clearPartialt, () -> {
|
||||||
|
|||||||
+1
-1
@@ -25,4 +25,4 @@ org.gradle.caching=true
|
|||||||
#used for slow jitpack builds; TODO see if this actually works
|
#used for slow jitpack builds; TODO see if this actually works
|
||||||
org.gradle.internal.http.socketTimeout=100000
|
org.gradle.internal.http.socketTimeout=100000
|
||||||
org.gradle.internal.http.connectionTimeout=100000
|
org.gradle.internal.http.connectionTimeout=100000
|
||||||
archash=a625ec1c93
|
archash=646d76bb50
|
||||||
|
|||||||
Reference in New Issue
Block a user