-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
340 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,38 @@ | ||
package online.vonarx.components; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import online.vonarx.constants.Mode; | ||
import online.vonarx.formatter.Formatter; | ||
import online.vonarx.models.AppParameters; | ||
import online.vonarx.models.Actor; | ||
import online.vonarx.save.SaveFactory; | ||
|
||
import javax.inject.Inject; | ||
import java.io.PrintStream; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class App { | ||
|
||
private final AppParameters appParameters; | ||
private final BinaryLoader binaryLoader; | ||
private final SaveFactory saveFactory; | ||
private final Formatter formatter; | ||
private final BinaryProvider binaryProvider; | ||
private final PrintStream out; | ||
private final Map<Mode, SaveFactory> saveFactoryMap; | ||
private final Map<Mode, Formatter> formatterMap; | ||
|
||
@Inject | ||
public App(final AppParameters appParameters, | ||
final BinaryLoader binaryLoader, final SaveFactory saveFactory, | ||
final Formatter formatter) { | ||
this.appParameters = appParameters; | ||
this.binaryLoader = binaryLoader; | ||
this.saveFactory = saveFactory; | ||
this.formatter = formatter; | ||
public App(final BinaryProvider binaryProvider, final PrintStream out, | ||
final Map<Mode, SaveFactory> saveFactoryMap, | ||
final Map<Mode, Formatter> formatterMap) { | ||
this.binaryProvider = binaryProvider; | ||
this.out = out; | ||
this.saveFactoryMap = saveFactoryMap; | ||
this.formatterMap = formatterMap; | ||
} | ||
|
||
public void run() { | ||
final var saveBinary = binaryLoader.readBinary(appParameters.saveFilepath()); | ||
final var save = saveFactory.create(saveBinary); | ||
final var formattedSave = formatter.format(save); | ||
final var saveBinary = binaryProvider.provideBinary(); | ||
final var actorsByModeMapBuilder = ImmutableMap.<Mode, List<Actor>>builder(); | ||
saveFactoryMap.forEach((mode, saveFactory) -> actorsByModeMapBuilder.put(mode, saveFactory.create(saveBinary))); | ||
final var actorsByMode = actorsByModeMapBuilder.build(); | ||
formatterMap.forEach((mode, formatter) -> out.println(formatter.format(actorsByMode.get(mode)))); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
src/main/java/online/vonarx/components/BinaryProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package online.vonarx.components; | ||
|
||
import lombok.SneakyThrows; | ||
import online.vonarx.models.AppParameters; | ||
import org.apache.commons.io.IOUtils; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class BinaryProvider { | ||
|
||
private final AppParameters parameters; | ||
|
||
@Inject | ||
public BinaryProvider(final AppParameters parameters) {this.parameters = parameters;} | ||
|
||
@SneakyThrows | ||
public byte[] provideBinary() { | ||
return IOUtils.toByteArray(parameters.saveFilepath()); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/online/vonarx/components/save/AdventureSaveFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package online.vonarx.components.save; | ||
|
||
import online.vonarx.components.ActorFactory; | ||
import online.vonarx.components.dictionaries.ZoneDictionary; | ||
import online.vonarx.save.SaveFactory; | ||
|
||
import javax.inject.Inject; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
|
||
public class AdventureSaveFactory extends SaveFactory { | ||
|
||
private static final Pattern START_ADVENTURE_MODE_PATTERN = Pattern.compile("^/Game/World_.+/Quests/Quest_AdventureMode/Quest_AdventureMode_[a-zA-Z]+_\\d{2}\\.Quest_AdventureMode_[a-zA-Z]+_\\d{2}$"); | ||
private static final Pattern END_ADVENTURE_MODE_PATTERN = Pattern.compile("^/Game/World_.+/Quests/Quest_AdventureMode/Quest_AdventureMode_.+\\.Quest_AdventureMode_.+_C$"); | ||
|
||
@Inject | ||
public AdventureSaveFactory(final ActorFactory actorFactory, final ZoneDictionary zoneDictionary) { | ||
super(actorFactory, zoneDictionary); | ||
} | ||
|
||
@Override | ||
protected List<String> extractIdentifiers(final List<String> identifiers) { | ||
final var startIndexName = identifiers.stream() | ||
.filter(name -> START_ADVENTURE_MODE_PATTERN.matcher(name).matches()) | ||
.reduce((first, second) -> second); | ||
final var endIndexName = identifiers.stream() | ||
.filter(name -> END_ADVENTURE_MODE_PATTERN.matcher(name).matches()) | ||
.findFirst(); | ||
if (startIndexName.isEmpty() || endIndexName.isEmpty()) { | ||
System.out.println("No adventure mode found."); | ||
return Collections.emptyList(); | ||
} | ||
final var startIndex = identifiers.indexOf(startIndexName.get()); | ||
final var endIndex = identifiers.indexOf(endIndexName.get()); | ||
return identifiers.subList(startIndex, endIndex); | ||
} | ||
} |
Oops, something went wrong.