diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index d9d254383e..1fe7c25975 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -41,16 +41,17 @@ jobs: git commit -m "Automatic bundle update" git push fi - - name: Update scripts and class mappings + - name: Update scripts, class mappings and map names if: ${{ github.repository == 'Anuken/Mindustry' }} run: | - ./gradlew updateScripts + ./gradlew updateScripts fixMaps if [ -n "$(git status --porcelain)" ]; then git config --global user.name "Github Actions" git config --global user.email "actions@github.com" git add core/assets/scripts/* core/src/mindustry/mod/ClassMap.java - git commit -m "Automatic class mapping update" + git add core/assets/maps/* + git commit -m "Automatic class mapping and map name update" git push fi - name: Update JITpack repo diff --git a/core/src/mindustry/editor/EditorTile.java b/core/src/mindustry/editor/EditorTile.java index 1fe749b991..330e879dcd 100644 --- a/core/src/mindustry/editor/EditorTile.java +++ b/core/src/mindustry/editor/EditorTile.java @@ -188,7 +188,7 @@ public class EditorTile extends Tile{ } private void updateStatic(){ - editor.renderer.updateStatic(x, y); + if(!headless) editor.renderer.updateStatic(x, y); } private boolean skip(){ diff --git a/core/src/mindustry/editor/MapEditor.java b/core/src/mindustry/editor/MapEditor.java index c2529b8c38..2187b57045 100644 --- a/core/src/mindustry/editor/MapEditor.java +++ b/core/src/mindustry/editor/MapEditor.java @@ -56,7 +56,7 @@ public class MapEditor{ tags.put("steamid", map.file.parent().name()); } load(() -> MapIO.loadMap(map, context)); - renderer.resize(width(), height()); + if(!headless) renderer.resize(width(), height()); loading = false; } @@ -65,7 +65,7 @@ public class MapEditor{ createTiles(pixmap.width, pixmap.height); load(() -> MapIO.readImage(pixmap, tiles())); - renderer.resize(width(), height()); + if(!headless) renderer.resize(width(), height()); } public void updateRenderer(){ diff --git a/core/src/mindustry/maps/Map.java b/core/src/mindustry/maps/Map.java index fd607af2ff..de996eb8ad 100644 --- a/core/src/mindustry/maps/Map.java +++ b/core/src/mindustry/maps/Map.java @@ -246,8 +246,6 @@ public class Map implements Comparable, Publishable{ public String toString(){ return "Map{" + "file='" + file + '\'' + - ", custom=" + custom + - ", tags=" + tags + '}'; } } diff --git a/tools/build.gradle b/tools/build.gradle index c2b15be338..0ce2c734c7 100644 --- a/tools/build.gradle +++ b/tools/build.gradle @@ -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 -> diff --git a/tools/src/mindustry/tools/MapFixer.java b/tools/src/mindustry/tools/MapFixer.java new file mode 100644 index 0000000000..2726e172c0 --- /dev/null +++ b/tools/src/mindustry/tools/MapFixer.java @@ -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); + } +}