|
|
@@ -5,12 +5,21 @@ import javax.swing.JPanel;
|
|
|
import org.leumasjaffe.charsheet.model.DDCharacter;
|
|
|
import org.leumasjaffe.charsheet.model.DDCharacterClass;
|
|
|
|
|
|
+import com.fasterxml.jackson.core.JsonParseException;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.JsonMappingException;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
|
|
+
|
|
|
+import lombok.SneakyThrows;
|
|
|
+
|
|
|
import java.awt.GridBagLayout;
|
|
|
|
|
|
import javax.swing.JComboBox;
|
|
|
import java.awt.GridBagConstraints;
|
|
|
import javax.swing.JLabel;
|
|
|
import java.awt.Insets;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
import javax.swing.JButton;
|
|
|
@@ -69,9 +78,21 @@ class ChooseClassLevelUpDialog extends JPanel {
|
|
|
final String name = (String) comboBox.getSelectedItem();
|
|
|
final LevelUpClassInfo info = chara.getClasses().stream()
|
|
|
.filter(c -> c.getName().equals(name)).findFirst()
|
|
|
- .map(dch -> new LevelUpClassInfo(chara, dch.clone(), dch.getLevel().value() + 1))
|
|
|
+ .map(dch -> new LevelUpClassInfo(chara, clone(dch), dch.getLevel().value() + 1))
|
|
|
.orElseGet(() -> new LevelUpClassInfo(chara, new DDCharacterClass(name)));
|
|
|
nexter.accept(info);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ static ObjectMapper mapper = new ObjectMapper();
|
|
|
+ static {
|
|
|
+ mapper.registerModule(new Jdk8Module());
|
|
|
+ }
|
|
|
+
|
|
|
+ @SneakyThrows({JsonParseException.class, JsonMappingException.class, JsonProcessingException.class, IOException.class})
|
|
|
+ private DDCharacterClass clone(DDCharacterClass dch) {
|
|
|
+ final String data = mapper.writeValueAsString(dch);
|
|
|
+// System.out.println(data);
|
|
|
+ return mapper.readValue(data, DDCharacterClass.class);
|
|
|
+ }
|
|
|
}
|