Skip to content

Commit

Permalink
7.15 updates and loader improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
xpdota committed Dec 21, 2024
1 parent dafc481 commit 2fdde66
Show file tree
Hide file tree
Showing 15 changed files with 179 additions and 20,715 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ else if (hit.eighthsTo(nextHit) == -1) {
private final ModifiableCallout<?> polarizingMoveBack = new ModifiableCallout<>("Polarizing Strikes: Move Back to Stacks", "Stacks")
.extendedDescription("""
The variable `i` ranges from 1 to 4 and indicates which hit just happened.
e.g. If you want to take the third hit, set the callout to {i == 2 ? 'Front' 'Back'}""");
e.g. If you want to take the third hit, set the callout to {i == 2 ? 'Front' : 'Back'}""");


@AutoFeed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,12 @@ public static void main(String[] args) {

// CSV FILES
{
Process command = maker.runScCmd("rawexd Action Map Status NpcYell");
Process command = maker.runScCmd("rawexd Action Map Status");
waitForCommand(command);
maker.copyFileToDir(List.of("rawexd", "Action.csv"), List.of("xiv", "actions"));
maker.copyFileToDir(List.of("rawexd", "Map.csv"), List.of("xiv", "maps"));
maker.copyFileToDir(List.of("rawexd", "Status.csv"), List.of("xiv", "statuseffect"));
maker.copyFileToDir(List.of("rawexd", "NpcYell.csv"), List.of("xiv", "npcyell"));
// maker.copyFileToDir(List.of("rawexd", "NpcYell.csv"), List.of("xiv", "npcyell"));
}
{
// Inactive - migrated to xivapi-java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import gg.xp.xivapi.clienttypes.XivApiObject;
import gg.xp.xivapi.pagination.XivApiPaginator;
import gg.xp.xivdata.builders.models.ContentFinderCondition;
import gg.xp.xivdata.builders.models.NpcYell;
import gg.xp.xivdata.builders.models.PlaceName;
import gg.xp.xivdata.builders.models.TerritoryType;
import gg.xp.xivdata.data.*;
Expand Down Expand Up @@ -40,7 +41,7 @@ public MakeEverythingXivapi(Path outputPathBase, XivApiClient client) {
public static void main(String[] args) throws Throwable {
Path outputPathBase = Path.of("src", "main", "resources", "xiv");
// Strongly recommended to use a local BM install rather than the live server
String server = System.getProperty("xivapi-server", "https://beta.xivapi.com/api/1");
String server = System.getProperty("xivapi-server", "https://bm.xivgear.app/api/1");
XivApiClient client = new XivApiClient(builder -> {
try {
builder.setBaseUri(new URI(server));
Expand All @@ -57,18 +58,23 @@ public static void main(String[] args) throws Throwable {

return new ZoneInfo(entry.getRowId(), cfc == null ? null : cfc.getName(), place == null ? null : place.getName());
}, List.of("territory", "TerritoryType.oos.gz"));
maker.writeList(NpcYell.class, entry -> {
return new NpcYellInfo(entry.getRowId(), entry.getText());
}, List.of("npcyell", "NpcYell.oos.gz"));
// TODO: remove after bug fixed
System.exit(0);
}

private <In extends XivApiObject, Out extends Serializable> void writeList(Class<In> xivApiClass, Function<In, Out> mapper, List<String> path) {
log.info("Loading {}...", xivApiClass.getSimpleName());
XivApiPaginator<In> pager = client.getListIterator(xivApiClass);
List<Out> out = pager.toBufferedStream(10).map(mapper).toList();
List<Out> out = pager.toBufferedStream(10).parallel().map(mapper).toList();
log.info("Found {} entries of {}", out.size(), xivApiClass.getSimpleName());
Path outputPath = outputPathBase;
for (String pathPart : path) {
outputPath = outputPath.resolve(pathPart);
}
try (var faos = new FileOutputStream(outputPathBase.resolve("territory").resolve("TerritoryType.oos.gz").toFile());
try (var faos = new FileOutputStream(outputPath.toFile());
var gzos = new GZIPOutputStream(faos);
var oos = new ObjectOutputStream(gzos)) {
oos.writeObject(out);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package gg.xp.xivdata.builders.models;

import gg.xp.xivapi.clienttypes.XivApiObject;

public interface NpcYell extends XivApiObject {
String getText();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ private CompressedObjectStreamLoader() {
}

public static <X> Map<Integer, X> loadFrom(InputStream inputStream, Function<X, Integer> keyExtractor) {
List<X> zoneInfos;
List<X> datum;
try (ObjectInputStream ois = new ObjectInputStream(new GZIPInputStream(inputStream))) {
zoneInfos = (List<X>) ois.readObject();
datum = (List<X>) ois.readObject();
}
catch (ClassNotFoundException | IOException e) {
throw new RuntimeException(e);
}
Map<Integer, X> tmp = zoneInfos.stream()
Map<Integer, X> tmp = datum.stream()
.collect(Collectors.toMap(keyExtractor, Function.identity(), (a, b) -> b));
return new ArrayBackedMap<>(tmp);
}
Expand Down
28 changes: 8 additions & 20 deletions xivdata/src/main/java/gg/xp/xivdata/data/NpcYellLibrary.java
Original file line number Diff line number Diff line change
@@ -1,41 +1,29 @@
package gg.xp.xivdata.data;

import gg.xp.xivdata.util.ArrayBackedMap;
import org.jetbrains.annotations.Nullable;

import java.io.InputStream;
import java.util.Collections;
import java.util.Map;

public class NpcYellLibrary {

public static final NpcYellLibrary INSTANCE = new NpcYellLibrary();
private final CsvMapLoader<Integer, NpcYellInfo> loader;
public static final NpcYellLibrary INSTANCE = new NpcYellLibrary(NpcYellLibrary.class.getResourceAsStream("/xiv/npcyell/NpcYell.oos.gz"));

public NpcYellLibrary() {
loader = CsvMapLoader.builder(() -> ReadCsv.cellsFromResource("/xiv/npcyell/NpcYell.csv"), NpcYellLibrary::parseRow,
(row, item) -> item.id())
.setMapFinisher(ArrayBackedMap::new)
.preFilterNullIds()
.build();
}
private final Map<Integer, NpcYellInfo> values;

private static NpcYellInfo parseRow(CsvRowHelper row) {
int id = row.getIntId();
String value = row.getStringOrNull(11);
if (value == null) {
return null;
}
return new NpcYellInfo(id, value);
public NpcYellLibrary(InputStream input) {
values = CompressedObjectStreamLoader.loadFrom(input, NpcYellInfo::id);
}

public Map<Integer, NpcYellInfo> getAll() {
return loader.read();
return Collections.unmodifiableMap(values);
}

public @Nullable NpcYellInfo forId(int id) {
NpcYellInfo npcYellInfo = getAll().get(id);
if (npcYellInfo != null) {

return npcYellInfo;
return npcYellInfo;
}
else {
return new NpcYellInfo(id, "Unknown %s (0x%X)".formatted(id, id));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gg.xp.xivdata.data;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -36,7 +37,7 @@ public Map<Integer, ZoneInfo> getAll() {
return value == null ? null : value.getCapitalizedName();
}

public ZoneInfo infoForZoneOrUnknown(int id) {
public @NotNull ZoneInfo infoForZoneOrUnknown(int id) {
ZoneInfo zoneInfo = infoForZone(id);
if (zoneInfo == null) {
return new ZoneInfo(id, "Unknown", null);
Expand Down
Loading

0 comments on commit 2fdde66

Please sign in to comment.