Workshop refactoring

This commit is contained in:
Anuken
2019-10-19 02:00:43 -04:00
parent f7be953bb5
commit d0dc21a52c
2 changed files with 41 additions and 35 deletions

View File

@ -255,7 +255,6 @@ 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.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.publish.error = Error publishing map: {0}
map.update = Update Map
map.load.error = Error fetching workshop details: {0}
map.missing = This map has been deleted or moved.\n[lightgray]The workshop listing has now been automatically un-linked from the map.
@ -264,7 +263,10 @@ map.menu = Select what you would like to do with this map.
map.changelog = Changelog (optional):
eula = Steam EULA
map.publish = Map published.
map.publishing = [accent]Publishing map...
publishing = [accent]Publishing...
publish.confirm = Are you sure you want to publish this?\n\n[lightgray]Make sure you agree to the Workshop EULA first, or your items will not show up!
publish.error = Error publishing item: {0}
editor.brush = Brush
editor.openin = Open In Editor
editor.oregen = Ore Generation

View File

@ -13,6 +13,7 @@ import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.game.*;
import io.anuke.mindustry.gen.*;
import io.anuke.mindustry.maps.*;
import io.anuke.mindustry.mod.Mods.*;
import io.anuke.mindustry.ui.dialogs.*;
import static io.anuke.mindustry.Vars.*;
@ -20,11 +21,12 @@ import static io.anuke.mindustry.Vars.*;
public class SWorkshop implements SteamUGCCallback{
public final SteamUGC ugc = new SteamUGC(this);
private Map lastMap;
//private Map lastMap;
private Array<FileHandle> mapFiles;
private Array<FileHandle> modFiles;
private Array<FileHandle> schematicFiles;
private ObjectMap<SteamUGCQuery, BiConsumer<Array<SteamUGCDetails>, SteamResult>> detailHandlers = new ObjectMap<>();
private Array<Consumer<SteamPublishedFileID>> itemHandlers = new Array<>();
public SWorkshop(){
int items = ugc.getNumSubscribedItems();
@ -74,28 +76,38 @@ public class SWorkshop implements SteamUGCCallback{
ui.editor.editor.getTags().put("author", map.tags.get("author"));
ui.editor.save();
showPublish(id -> updateMap(map, id, "<Map Created>"));
}
public void publishSchematic(Schematic schematic){
showPublish(id -> {
});
}
public void publishMod(LoadedMod mod){
}
private void showPublish(Consumer<SteamPublishedFileID> published){
FloatingDialog dialog = new FloatingDialog("$confirm");
dialog.setFillParent(false);
dialog.cont.add("$map.publish.confirm").width(600f).wrap();
dialog.cont.add("$publish.confirm").width(600f).wrap();
dialog.addCloseButton();
dialog.buttons.addImageTextButton("$eula", Icon.linkSmall, () -> {
SVars.net.friends.activateGameOverlayToWebPage("https://steamcommunity.com/sharedfiles/workshoplegalagreement");
}).size(210f, 64f);
dialog.buttons.addImageTextButton("$ok", Icon.checkSmall, () -> {
this.lastMap = map;
ugc.createItem(SVars.steamID, WorkshopFileType.Community);
ui.loadfrag.show("$map.publishing");
Log.info("Publish map " + map.name());
ui.loadfrag.show("$publishing");
dialog.hide();
itemHandlers.add(published);
}).size(170f, 64f);
dialog.show();
}
public void publishSchematic(Schematic schematic){
}
public void viewMapListingInfo(Map map){
String id = map.tags.get("steamid");
long handle = Strings.parseLong(id, -1);
@ -104,10 +116,7 @@ public class SWorkshop implements SteamUGCCallback{
Log.info("Requesting map listing view; id = " + id);
ui.loadfrag.show();
SteamUGCQuery query = ugc.createQueryUGCDetailsRequest(fid);
Log.info("POST " + query);
detailHandlers.put(query, (detailsList, result) -> {
query(ugc.createQueryUGCDetailsRequest(fid), (detailsList, result) -> {
ui.loadfrag.hide();
Log.info("Map listing result: " + result + " " + detailsList);
@ -136,8 +145,7 @@ public class SWorkshop implements SteamUGCCallback{
field.setMaxLength(400);
buttons.defaults().size(120, 54).pad(4);
buttons.addButton("$ok", () -> {
ui.loadfrag.show("$map.publishing");
lastMap = map;
ui.loadfrag.show("publishing");
updateMap(map, details.getPublishedFileID(), field.getText().replace("\r", "\n"));
dialog.hide();
hide();
@ -167,7 +175,11 @@ public class SWorkshop implements SteamUGCCallback{
ui.showErrorMessage(Core.bundle.format("map.load.error", result.name()));
}
});
}
public void query(SteamUGCQuery query, BiConsumer<Array<SteamUGCDetails>, SteamResult> handler){
Log.info("POST " + query);
detailHandlers.put(query, handler);
ugc.sendQueryUGCRequest(query);
}
@ -213,23 +225,15 @@ public class SWorkshop implements SteamUGCCallback{
@Override
public void onCreateItem(SteamPublishedFileID publishedFileID, boolean needsToAcceptWLA, SteamResult result){
if(lastMap == null){
Log.err("No map to publish?");
return;
if(!itemHandlers.isEmpty()){
if(result == SteamResult.OK){
itemHandlers.first().accept(publishedFileID);
}else{
ui.showErrorMessage(Core.bundle.format("publish.error ", result.name()));
}
itemHandlers.remove(0);
}
//SVars.net.friends.activateGameOverlayToWebPage("steam://url/CommunityFilePage/" + publishedFileID.toString());
Map map = lastMap;
Log.info("Create item {0} result {1} {2}", SteamNativeHandle.getNativeHandle(publishedFileID), result, needsToAcceptWLA);
if(result == SteamResult.OK){
updateMap(map, publishedFileID, "<Map Created>");
}else{
ui.showErrorMessage(Core.bundle.format("map.publish.error ", result.name()));
}
lastMap = null;
}
void updateMap(Map map, SteamPublishedFileID publishedFileID, String changelog){
@ -237,7 +241,7 @@ public class SWorkshop implements SteamUGCCallback{
Gamemode mode = Gamemode.attack.valid(map) ? Gamemode.attack : Gamemode.survival;
FileHandle mapFile = tmpDirectory.child("map_" + publishedFileID.toString()).child("map.msav");
lastMap.file.copyTo(mapFile);
map.file.copyTo(mapFile);
Log.info(mapFile.parent().absolutePath());
Log.info(map.previewFile().absolutePath());
@ -282,7 +286,7 @@ public class SWorkshop implements SteamUGCCallback{
}
Events.fire(new MapPublishEvent());
}else{
ui.showErrorMessage(Core.bundle.format("map.publish.error ", result.name()));
ui.showErrorMessage(Core.bundle.format("publish.error ", result.name()));
}
}