Steam workshop publishing

This commit is contained in:
Anuken
2019-09-10 14:25:34 -04:00
parent 6fe55661ed
commit 7aa71a7201
5 changed files with 67 additions and 11 deletions

View File

@@ -58,7 +58,7 @@ public class AssetsAnnotationProcessor extends AbstractProcessor{
MethodSpec.Builder icload = MethodSpec.methodBuilder("load").addModifiers(Modifier.PUBLIC, Modifier.STATIC); MethodSpec.Builder icload = MethodSpec.methodBuilder("load").addModifiers(Modifier.PUBLIC, Modifier.STATIC);
String resources = path + "/assets-raw/sprites/ui"; String resources = path + "/assets-raw/sprites/ui";
Files.walk(Paths.get(resources)).forEach(p -> { Files.walk(Paths.get(resources)).forEach(p -> {
if(Files.isDirectory(p)) return; if(Files.isDirectory(p) || p.getFileName().toString().equals(".DS_Store")) return;
String filename = p.getFileName().toString(); String filename = p.getFileName().toString();
filename = filename.substring(0, filename.indexOf(".")); filename = filename.substring(0, filename.indexOf("."));

View File

@@ -199,6 +199,7 @@ map.nospawn = This map does not have any cores for the player to spawn in! Add a
map.nospawn.pvp = This map does not have any enemy cores for player to spawn into! Add[SCARLET] non-orange[] cores to this map in the editor. map.nospawn.pvp = This map does not have any enemy cores for player to spawn into! Add[SCARLET] non-orange[] cores to this map in the editor.
map.nospawn.attack = This map does not have any enemy cores for player to attack! Add[SCARLET] red[] cores to this map in the editor. map.nospawn.attack = This map does not have any enemy cores for player to attack! Add[SCARLET] red[] cores to this map in the editor.
map.invalid = Error loading map: corrupted or invalid map file. map.invalid = Error loading map: corrupted or invalid map file.
map.publish.error = Error publishing map: {0}
editor.brush = Brush editor.brush = Brush
editor.openin = Open In Editor editor.openin = Open In Editor
editor.oregen = Ore Generation editor.oregen = Ore Generation
@@ -210,6 +211,7 @@ editor.waves = Waves:
editor.rules = Rules: editor.rules = Rules:
editor.generation = Generation: editor.generation = Generation:
editor.ingame = Edit In-Game editor.ingame = Edit In-Game
editor.publish.workshop = Publish On Workshop
editor.newmap = New Map editor.newmap = New Map
waves.title = Waves waves.title = Waves
waves.remove = Remove waves.remove = Remove

View File

@@ -151,7 +151,18 @@ public class MapEditorDialog extends Dialog implements Disposable{
menu.cont.row(); menu.cont.row();
menu.cont.addImageTextButton("$editor.ingame", Icon.arrowSmall, this::playtest).padTop(-5).size(swidth * 2f + 10, 60f); if(steam){
menu.cont.addImageTextButton("$editor.publish.workshop", Icon.arrowSmall, () -> {
Map map = save();
if(map != null){
platform.publishMap(map);
}
}).padTop(-3).size(swidth * 2f + 10, 60f);
menu.cont.row();
}
menu.cont.addImageTextButton("$editor.ingame", Icon.arrowSmall, this::playtest).padTop(-3).size(swidth * 2f + 10, 60f);
menu.cont.row(); menu.cont.row();
@@ -265,13 +276,15 @@ public class MapEditorDialog extends Dialog implements Disposable{
}); });
} }
private void save(){ private Map save(){
String name = editor.getTags().get("name", "").trim(); String name = editor.getTags().get("name", "").trim();
editor.getTags().put("rules", JsonIO.write(state.rules)); editor.getTags().put("rules", JsonIO.write(state.rules));
editor.getTags().remove("width"); editor.getTags().remove("width");
editor.getTags().remove("height"); editor.getTags().remove("height");
player.dead = true; player.dead = true;
Map returned = null;
if(name.isEmpty()){ if(name.isEmpty()){
infoDialog.show(); infoDialog.show();
Core.app.post(() -> ui.showErrorMessage("$editor.save.noname")); Core.app.post(() -> ui.showErrorMessage("$editor.save.noname"));
@@ -282,11 +295,13 @@ public class MapEditorDialog extends Dialog implements Disposable{
}else{ }else{
maps.saveMap(editor.getTags()); maps.saveMap(editor.getTags());
ui.showInfoFade("$editor.saved"); ui.showInfoFade("$editor.saved");
returned = map;
} }
} }
menu.hide(); menu.hide();
saved = true; saved = true;
return returned;
} }
/** Called when a built-in map save is attempted.*/ /** Called when a built-in map save is attempted.*/

View File

@@ -74,4 +74,9 @@ public class Rules{
public Rules copy(){ public Rules copy(){
return JsonIO.copy(this); return JsonIO.copy(this);
} }
/** Returns the gamemode that best fits these rules.*/
public Gamemode mode(){
return Gamemode.bestFit(this);
}
} }

View File

@@ -2,12 +2,21 @@ package io.anuke.mindustry.desktop.steam;
import com.codedisaster.steamworks.*; import com.codedisaster.steamworks.*;
import com.codedisaster.steamworks.SteamRemoteStorage.*; import com.codedisaster.steamworks.SteamRemoteStorage.*;
import io.anuke.arc.*;
import io.anuke.arc.files.*;
import io.anuke.arc.util.*;
import io.anuke.mindustry.game.*;
import io.anuke.mindustry.maps.*; import io.anuke.mindustry.maps.*;
import static io.anuke.mindustry.Vars.*;
public class SWorkshop implements SteamUGCCallback{ public class SWorkshop implements SteamUGCCallback{
public final SteamUGC ugc = new SteamUGC(this); public final SteamUGC ugc = new SteamUGC(this);
private Map lastMap;
public void publishMap(Map map){ public void publishMap(Map map){
this.lastMap = map;
ugc.createItem(SVars.steamID, WorkshopFileType.GameManagedItem); ugc.createItem(SVars.steamID, WorkshopFileType.GameManagedItem);
} }
@@ -33,18 +42,43 @@ public class SWorkshop implements SteamUGCCallback{
@Override @Override
public void onCreateItem(SteamPublishedFileID publishedFileID, boolean needsToAcceptWLA, SteamResult result){ public void onCreateItem(SteamPublishedFileID publishedFileID, boolean needsToAcceptWLA, SteamResult result){
//TODO if(lastMap == null){
if(result == SteamResult.OK){ Log.err("No map to publish?");
return;
}else{
//TODO show "failed to create" dialog
//ui.showError("");
} }
Map map = lastMap;
if(result == SteamResult.OK){
SteamUGCUpdateHandle h = ugc.startItemUpdate(SVars.steamID, publishedFileID);
Gamemode mode = Gamemode.attack.valid(map) ? Gamemode.attack : Gamemode.survival;
FileHandle mapFile = tmpDirectory.child("map_" + publishedFileID.toString()).child("preview.png");
lastMap.file.copyTo(mapFile);
ugc.setItemTitle(h, map.name());
ugc.setItemDescription(h, map.description());
ugc.setItemTags(h, new String[]{"map", mode.name()});
ugc.setItemVisibility(h, PublishedFileVisibility.Public);
ugc.setItemPreview(h, map.previewFile().absolutePath());
ugc.setItemContent(h, mapFile.parent().absolutePath());
ugc.addItemKeyValueTag(h, "mode", mode.name());
ugc.submitItemUpdate(h, "Map created");
}else{
ui.showErrorMessage(Core.bundle.format("map.publish.error ", result.name()));
}
lastMap = null;
} }
@Override @Override
public void onSubmitItemUpdate(SteamPublishedFileID publishedFileID, boolean needsToAcceptWLA, SteamResult result){ public void onSubmitItemUpdate(SteamPublishedFileID publishedFileID, boolean needsToAcceptWLA, SteamResult result){
if(result == SteamResult.OK){
//redirect user to page for further updates
SVars.net.friends.activateGameOverlayToWebPage("steam://url/CommunityFilePage/" + publishedFileID.toString());
}else{
ui.showErrorMessage(Core.bundle.format("map.publish.error ", result.name()));
}
} }
@Override @Override