Workshop refactoring
This commit is contained in:
@@ -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.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}
|
|
||||||
map.update = Update Map
|
map.update = Update Map
|
||||||
map.load.error = Error fetching workshop details: {0}
|
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.
|
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):
|
map.changelog = Changelog (optional):
|
||||||
eula = Steam EULA
|
eula = Steam EULA
|
||||||
map.publish = Map published.
|
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.brush = Brush
|
||||||
editor.openin = Open In Editor
|
editor.openin = Open In Editor
|
||||||
editor.oregen = Ore Generation
|
editor.oregen = Ore Generation
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import io.anuke.mindustry.game.EventType.*;
|
|||||||
import io.anuke.mindustry.game.*;
|
import io.anuke.mindustry.game.*;
|
||||||
import io.anuke.mindustry.gen.*;
|
import io.anuke.mindustry.gen.*;
|
||||||
import io.anuke.mindustry.maps.*;
|
import io.anuke.mindustry.maps.*;
|
||||||
|
import io.anuke.mindustry.mod.Mods.*;
|
||||||
import io.anuke.mindustry.ui.dialogs.*;
|
import io.anuke.mindustry.ui.dialogs.*;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
@@ -20,11 +21,12 @@ 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;
|
//private Map lastMap;
|
||||||
private Array<FileHandle> mapFiles;
|
private Array<FileHandle> mapFiles;
|
||||||
private Array<FileHandle> modFiles;
|
private Array<FileHandle> modFiles;
|
||||||
private Array<FileHandle> schematicFiles;
|
private Array<FileHandle> schematicFiles;
|
||||||
private ObjectMap<SteamUGCQuery, BiConsumer<Array<SteamUGCDetails>, SteamResult>> detailHandlers = new ObjectMap<>();
|
private ObjectMap<SteamUGCQuery, BiConsumer<Array<SteamUGCDetails>, SteamResult>> detailHandlers = new ObjectMap<>();
|
||||||
|
private Array<Consumer<SteamPublishedFileID>> itemHandlers = new Array<>();
|
||||||
|
|
||||||
public SWorkshop(){
|
public SWorkshop(){
|
||||||
int items = ugc.getNumSubscribedItems();
|
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.editor.getTags().put("author", map.tags.get("author"));
|
||||||
ui.editor.save();
|
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");
|
FloatingDialog dialog = new FloatingDialog("$confirm");
|
||||||
dialog.setFillParent(false);
|
dialog.setFillParent(false);
|
||||||
dialog.cont.add("$map.publish.confirm").width(600f).wrap();
|
dialog.cont.add("$publish.confirm").width(600f).wrap();
|
||||||
dialog.addCloseButton();
|
dialog.addCloseButton();
|
||||||
dialog.buttons.addImageTextButton("$eula", Icon.linkSmall, () -> {
|
dialog.buttons.addImageTextButton("$eula", Icon.linkSmall, () -> {
|
||||||
SVars.net.friends.activateGameOverlayToWebPage("https://steamcommunity.com/sharedfiles/workshoplegalagreement");
|
SVars.net.friends.activateGameOverlayToWebPage("https://steamcommunity.com/sharedfiles/workshoplegalagreement");
|
||||||
}).size(210f, 64f);
|
}).size(210f, 64f);
|
||||||
|
|
||||||
dialog.buttons.addImageTextButton("$ok", Icon.checkSmall, () -> {
|
dialog.buttons.addImageTextButton("$ok", Icon.checkSmall, () -> {
|
||||||
this.lastMap = map;
|
|
||||||
ugc.createItem(SVars.steamID, WorkshopFileType.Community);
|
ugc.createItem(SVars.steamID, WorkshopFileType.Community);
|
||||||
ui.loadfrag.show("$map.publishing");
|
ui.loadfrag.show("$publishing");
|
||||||
Log.info("Publish map " + map.name());
|
|
||||||
dialog.hide();
|
dialog.hide();
|
||||||
|
itemHandlers.add(published);
|
||||||
}).size(170f, 64f);
|
}).size(170f, 64f);
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void publishSchematic(Schematic schematic){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void viewMapListingInfo(Map map){
|
public void viewMapListingInfo(Map map){
|
||||||
String id = map.tags.get("steamid");
|
String id = map.tags.get("steamid");
|
||||||
long handle = Strings.parseLong(id, -1);
|
long handle = Strings.parseLong(id, -1);
|
||||||
@@ -104,10 +116,7 @@ public class SWorkshop implements SteamUGCCallback{
|
|||||||
Log.info("Requesting map listing view; id = " + id);
|
Log.info("Requesting map listing view; id = " + id);
|
||||||
|
|
||||||
ui.loadfrag.show();
|
ui.loadfrag.show();
|
||||||
SteamUGCQuery query = ugc.createQueryUGCDetailsRequest(fid);
|
query(ugc.createQueryUGCDetailsRequest(fid), (detailsList, result) -> {
|
||||||
Log.info("POST " + query);
|
|
||||||
|
|
||||||
detailHandlers.put(query, (detailsList, result) -> {
|
|
||||||
ui.loadfrag.hide();
|
ui.loadfrag.hide();
|
||||||
|
|
||||||
Log.info("Map listing result: " + result + " " + detailsList);
|
Log.info("Map listing result: " + result + " " + detailsList);
|
||||||
@@ -136,8 +145,7 @@ public class SWorkshop implements SteamUGCCallback{
|
|||||||
field.setMaxLength(400);
|
field.setMaxLength(400);
|
||||||
buttons.defaults().size(120, 54).pad(4);
|
buttons.defaults().size(120, 54).pad(4);
|
||||||
buttons.addButton("$ok", () -> {
|
buttons.addButton("$ok", () -> {
|
||||||
ui.loadfrag.show("$map.publishing");
|
ui.loadfrag.show("publishing");
|
||||||
lastMap = map;
|
|
||||||
updateMap(map, details.getPublishedFileID(), field.getText().replace("\r", "\n"));
|
updateMap(map, details.getPublishedFileID(), field.getText().replace("\r", "\n"));
|
||||||
dialog.hide();
|
dialog.hide();
|
||||||
hide();
|
hide();
|
||||||
@@ -167,7 +175,11 @@ public class SWorkshop implements SteamUGCCallback{
|
|||||||
ui.showErrorMessage(Core.bundle.format("map.load.error", result.name()));
|
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);
|
ugc.sendQueryUGCRequest(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,23 +225,15 @@ 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){
|
||||||
if(lastMap == null){
|
if(!itemHandlers.isEmpty()){
|
||||||
Log.err("No map to publish?");
|
if(result == SteamResult.OK){
|
||||||
return;
|
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){
|
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;
|
Gamemode mode = Gamemode.attack.valid(map) ? Gamemode.attack : Gamemode.survival;
|
||||||
FileHandle mapFile = tmpDirectory.child("map_" + publishedFileID.toString()).child("map.msav");
|
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(mapFile.parent().absolutePath());
|
||||||
Log.info(map.previewFile().absolutePath());
|
Log.info(map.previewFile().absolutePath());
|
||||||
@@ -282,7 +286,7 @@ public class SWorkshop implements SteamUGCCallback{
|
|||||||
}
|
}
|
||||||
Events.fire(new MapPublishEvent());
|
Events.fire(new MapPublishEvent());
|
||||||
}else{
|
}else{
|
||||||
ui.showErrorMessage(Core.bundle.format("map.publish.error ", result.name()));
|
ui.showErrorMessage(Core.bundle.format("publish.error ", result.name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user