mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-10-03 03:31:28 +03:00
Script for updating map names
This commit is contained in:
@@ -261,6 +261,14 @@ tasks.register('updateScripts', JavaExec){
|
||||
workingDir = "../"
|
||||
}
|
||||
|
||||
tasks.register('fixMaps', JavaExec){
|
||||
dependsOn classes
|
||||
mainClass = "mindustry.tools.MapFixer"
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
standardInput = System.in
|
||||
workingDir = "../core/assets"
|
||||
}
|
||||
|
||||
tasks.register('updateBundles'){
|
||||
doLast{
|
||||
def uniEscape = { String string ->
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package mindustry.tools;
|
||||
|
||||
import arc.*;
|
||||
import arc.backend.headless.*;
|
||||
import arc.files.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.core.*;
|
||||
import mindustry.editor.*;
|
||||
import mindustry.io.*;
|
||||
import mindustry.maps.*;
|
||||
import mindustry.maps.Map;
|
||||
import mindustry.net.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class MapFixer{
|
||||
|
||||
public static void main(String[] args){
|
||||
Log.useColors = false;
|
||||
|
||||
Reflect.set(Maps.class, "useDefaultFolder", false);
|
||||
Reflect.set(Maps.class, "defaultMapNames", new Fi("maps")
|
||||
.findAll(f -> f.extEquals("msav"))
|
||||
.map(f -> f.path().replace(".msav", "").replace("maps/", "")).toArray(String.class));
|
||||
|
||||
ApplicationCore core = new ApplicationCore(){
|
||||
@Override
|
||||
public void setup(){
|
||||
Core.settings.setDataDirectory(new Fi("../../tools/build/test_data"));
|
||||
Core.bundle = I18NBundle.createBundle(Core.files.internal("bundles/bundle"), Locale.ENGLISH);
|
||||
headless = true;
|
||||
net = new Net(null);
|
||||
tree = new FileTree();
|
||||
Vars.init();
|
||||
world = new World();
|
||||
content.createBaseContent();
|
||||
mods.loadScripts();
|
||||
content.createModContent();
|
||||
|
||||
add(logic = new Logic());
|
||||
add(netServer = new NetServer());
|
||||
|
||||
content.init();
|
||||
editor = new MapEditor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
super.init();
|
||||
|
||||
fixMapNames();
|
||||
}
|
||||
};
|
||||
|
||||
new HeadlessApplication(core);
|
||||
}
|
||||
|
||||
static void fixMapNames(){
|
||||
if(!Locale.getDefault().toString().contains("en")){
|
||||
throw new IllegalArgumentException("Language must be English!!! " + Locale.getDefault());
|
||||
}
|
||||
|
||||
Fi root = Core.files.local("maps");
|
||||
root.walk(f -> {
|
||||
try{
|
||||
Map map = maps.all().find(m -> m.file.absolutePath().equals(f.absolutePath()));
|
||||
if(map == null) return;
|
||||
|
||||
SectorPreset preset = content.sectors().find(s -> s.generator.map.file.absolutePath().equals(f.absolutePath()));
|
||||
if(preset == null) return;
|
||||
|
||||
String targetName = preset.requireUnlock ? preset.localizedName : f.nameWithoutExtension();
|
||||
|
||||
editor.beginEdit(map);
|
||||
|
||||
if(!map.name().equals(targetName)){
|
||||
Log.info("Changed name: '@' -> '@'", map.name(), targetName);
|
||||
map.tags.put("name", targetName);
|
||||
|
||||
MapIO.writeMap(f, map);
|
||||
}
|
||||
}catch(Throwable t){
|
||||
Log.err(t);
|
||||
System.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user