MCPcopy Create free account
hub / github.com/PCGen/pcgen / CharacterManager

Class CharacterManager

code/src/java/pcgen/system/CharacterManager.java:59–533  ·  view source on GitHub ↗

This class stores the characters that are currently opened by PCGen. It also handles creating new characters and opening characters from files. The getCharacters method returns a listenable list that allows users of this class to not only see what characters are open but to easily track any changes

Source from the content-addressed store, hash-verified

57 * changes to the list of available characters.
58 */
59public final class CharacterManager
60{
61
62 private static final PartyFacadeImpl CHARACTERS;
63 private static final RecentFileList RECENT_CHARACTERS;
64 private static final RecentFileList RECENT_PARTIES;
65 private static final PCGenMessageHandler MESSAGE_HANDLER;
66
67 static
68 {
69 CHARACTERS = new PartyFacadeImpl();
70 RECENT_CHARACTERS = new RecentFileList(PCGenSettings.RECENT_CHARACTERS);
71 RECENT_PARTIES = new RecentFileList(PCGenSettings.RECENT_PARTIES);
72 MESSAGE_HANDLER = PluginManager.getInstance().getPostbox();
73 }
74
75 private CharacterManager()
76 {
77 }
78
79 /**
80 * Create a new character using the supplied data sets.
81 * @param delegate the UIDelegate that this character will use.
82 * @param dataset the dataset that this will be loaded with.
83 * @return The character that was created.
84 */
85 public static CharacterFacade createNewCharacter(UIDelegate delegate, DataSetFacade dataset)
86 {
87 @SuppressWarnings("rawtypes")
88 List campaigns = ListFacades.wrap(dataset.getCampaigns());
89 try
90 {
91 @SuppressWarnings("unchecked")
92 PlayerCharacter pc = new PlayerCharacter(campaigns);
93 Globals.getPCList().add(pc);
94 CharacterFacade character = new CharacterFacadeImpl(pc, delegate, dataset);
95 String name = createNewCharacterName();
96 character.setName(name);
97 CHARACTERS.addElement(character);
98 Logging.log(Logging.INFO, "Created new character " + name + '.'); //$NON-NLS-1$
99 MESSAGE_HANDLER.handleMessage(new PlayerCharacterWasLoadedMessage(delegate, pc));
100 return character;
101 }
102 catch (final Exception e)
103 {
104 Logging.errorPrint("Unable to create character with data " //$NON-NLS-1$
105 + dataset, e);
106 delegate.showErrorMessage(LanguageBundle.getString("in_cmCreateErrorTitle"), //$NON-NLS-1$
107 LanguageBundle.getFormattedString("in_cmCreateErrorMessage", //$NON-NLS-1$
108 e.getMessage()));
109 return null;
110 }
111
112 }
113
114 public static ListFacade<File> getRecentCharacters()
115 {
116 return RECENT_CHARACTERS;

Callers

nothing calls this directly

Calls 2

getInstanceMethod · 0.95
getPostboxMethod · 0.45

Tested by

no test coverage detected