Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
Add source
Browse files Browse the repository at this point in the history
  • Loading branch information
kphrx committed Aug 2, 2018
1 parent 4ea543c commit 0803d1c
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package logbook.plugin.kanmusulist.gui;

import java.util.AbstractMap.SimpleEntry;
import java.util.HashMap;
import java.util.Map;
import java.util.StringJoiner;
import java.util.stream.Collectors;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;

import logbook.bean.Ship;
import logbook.bean.ShipCollection;
import logbook.bean.ShipMst;
import logbook.bean.ShipMstCollection;
import logbook.internal.gui.WindowController;

public class KanmusuListGeneratorController extends WindowController {

@FXML
private TextField kanmusuList;

@FXML
void create(ActionEvent event) {
Map<Integer, String> format = new HashMap<Integer, String>();
for (Ship ship : ShipCollection.get().getShipMap().values()) {
int lv = ship.getLv();
int shipId = ship.getShipId();

// 初期のShip IDと改造数を取得する
SimpleEntry<Integer, Integer> charIdAndLvSuffix = this.getCharIdAndLvSuffix(shipId);
int charId = charIdAndLvSuffix.getKey();
int lvSuffix = charIdAndLvSuffix.getValue();

if (format.containsKey(charId)) {
format.put(charId, String.format("%s,%d.%d", format.get(charId), lv, lvSuffix));
} else {
format.put(charId, String.format("%d.%d", lv, lvSuffix));
}
}
StringJoiner result = new StringJoiner("|");
// 艦隊晒しのprefix
result.add(".2");
format.forEach((id, value) -> {
result.add(String.format("%d:%s", id, value));
});
this.kanmusuList.setText(result.toString());
}

private Map<Integer, Integer> getShipIdAndBeforeId() {
Map<Integer, Integer> shipIdAndAfterId = new HashMap<Integer, Integer>();
// マスターデータからShipIDと改造先のMapを作成する
for (ShipMst ship : ShipMstCollection.get().getShipMap().values()) {
// 改造先がないか、すでに追加されているならスキップ(コンバートが該当するはず)
Integer afterShipId = ship.getAftershipid();
if (afterShipId == null || shipIdAndAfterId.containsValue(afterShipId)) {
continue;
}
// 改造元と改造先を追加
shipIdAndAfterId.put(ship.getId(), afterShipId);
}
// 入れ替えて改造後ではなく改造前を取得するMapにする
Map<Integer, Integer> shipIdAndBeforeId = shipIdAndAfterId.entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey));

return shipIdAndBeforeId;
}

private SimpleEntry<Integer, Integer> charIdAndLvSuffix(Map<Integer, Integer> shipIdAndBeforeId, int shipId, int count) {
count++;
if (shipIdAndBeforeId.containsKey(shipId)) {
// 改造前の値がある場合は再帰処理
int beforeShipId = shipIdAndBeforeId.get(shipId);
return this.charIdAndLvSuffix(shipIdAndBeforeId, beforeShipId, count);
}

// 改造前の値がない場合はSimpleEntryを返す
return new SimpleEntry<Integer, Integer>(shipId, count);
}

private SimpleEntry<Integer, Integer> getCharIdAndLvSuffix(int shipId) {
Map<Integer, Integer> shipIdAndBeforeId = this.getShipIdAndBeforeId();
return this.charIdAndLvSuffix(shipIdAndBeforeId, shipId, 0);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package logbook.plugin.kanmusulist.gui;

import java.net.URL;

import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.MenuItem;
import javafx.stage.Stage;
import logbook.internal.LoggerHolder;
import logbook.internal.gui.Tools;
import logbook.internal.gui.WindowController;
import logbook.plugin.PluginContainer;
import logbook.plugin.gui.MainExtMenu;

public class KanmusuListGeneratorMenu implements MainExtMenu {

@Override
public MenuItem getContent() {
MenuItem menu = new MenuItem("艦隊晒しフォーマット");
menu.setOnAction(e -> {
try {
Stage stage = new Stage();
URL url = KanmusuListGeneratorMenu.class.getClassLoader()
.getResource("kanmusulist/gui/KanmusuListGenerator.fxml");
FXMLLoader loader = new FXMLLoader(url);
loader.setClassLoader(PluginContainer.getInstance().getClassLoader());
Parent root = loader.load();
stage.setScene(new Scene(root));
WindowController controller = loader.getController();
controller.setWindow(stage);

stage.initOwner(menu.getParentPopup().getOwnerWindow());
stage.setTitle("艦隊晒しフォーマット");
Tools.Windows.setIcon(stage);
Tools.Windows.defaultCloseAction(controller);
Tools.Windows.defaultOpenAction(controller);
stage.show();
} catch (Exception ex) {
LoggerHolder.get().warn("艦隊晒しフォーマットを開けませんでした", ex);
}
});
return menu;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
logbook.plugin.kanmusulist.gui.KanmusuListGeneratorMenu
21 changes: 21 additions & 0 deletions src/main/resources/kanmusulist/gui/KanmusuListGenerator.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextField?>
<?import javafx.geometry.Insets?>

<?import javafx.scene.layout.HBox?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="30.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8.0.131" xmlns:fx="http://javafx.com/fxml/1" fx:controller="logbook.plugin.kanmusulist.gui.KanmusuListGeneratorController">
<padding>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
</padding>
<children>
<Label text="艦隊晒しページのフォーマットを生成します" />
<HBox alignment="BASELINE_LEFT" prefWidth="394.0" spacing="3.0">
<Button mnemonicParsing=" false" onAction="#create" text="生成" minWidth="50.0" prefWidth="50.0" />
<TextField fx:id="kanmusuList" HBox.hgrow="ALWAYS" />
</HBox>
</children>
</VBox>

0 comments on commit 0803d1c

Please sign in to comment.