5050
5151public class CreateProjectUI implements Controller {
5252
53- private static final String ILLEGAL_CHARACTERS = "/\\ []{}" ;
54-
5553 private static final String WARNING_UNIQUE_TAG_EMPTY = "Unique tag cannot be empty" ;
5654 private static final String WARNING_MOD_NAME_EMPTY = "Mod name cannot be empty" ;
5755 private static final String WARNING_PROJECT_NAME_EMPTY = "Package project name cannot be empty" ;
5856 private static final String WARNING_MOD_NAME_REPEATED = "A mod with this name already exists" ;
5957 private static final String WARNING_PROJECT_NAME_REPEATED = "A package project with this name already exists" ;
60- private static final String WARNING_MOD_NAME_INVALID = "Mod name cannot contain any character from " + ILLEGAL_CHARACTERS ;
61- private static final String WARNING_PROJECT_NAME_INVALID = "Package project name cannot contain any character from " + ILLEGAL_CHARACTERS ;
58+ private static final String WARNING_MOD_NAME_INVALID = "Mod name cannot contain any character from " + ModBundle . NAME_ILLEGAL_CHARACTERS ;
59+ private static final String WARNING_PROJECT_NAME_INVALID = "Package project name cannot contain any character from " + ModBundle . NAME_ILLEGAL_CHARACTERS ;
6260
6361 private Dialog <ButtonType > dialog ;
6462
@@ -103,42 +101,26 @@ public Pane getMainNode() {
103101 }
104102
105103 public void createMod () throws IOException , InterruptedException , ParserConfigurationException , TransformerException {
106- ProjectManager projectManager = ProjectManager .get ();
107-
108- // Create base mod
109- ModBundle modBundle ;
110- if (newModButton .isSelected ()) {
111- modBundle = new ModBundle (modNameField .getText ());
112- modBundle .setDescription (descriptionTextField .getText ());
113- modBundle .setUniqueTag (uniqueTagTextField .getText ());
114- projectManager .initializeModBundle (modBundle );
115- } else {
116- modBundle = projectManager .getModBundle (existingModChoiceBox .getValue ());
117- assert modBundle != null ;
118- }
119-
120- // Create package project
121- Project project = new Project (projectNameField .getText (), modBundle );
122- modBundle .addProject (project );
123-
124- // Add project references
125- project .getReferences ().addAll (presetBoxes .stream ()
104+ List <ProjectPreset > presets = presetBoxes .stream ()
126105 .filter (CheckBox ::isSelected )
127- .map (box -> projectManager . getProject ((( ProjectPreset )box .getUserData ()). getName ()))
106+ .map (box -> (( ProjectPreset )box .getUserData ()))
128107 .filter (Objects ::nonNull )
129- .collect (Collectors .toList ()));
130-
131- // Initialize package project folder
132- projectManager .initializeProject (project );
133-
134- // Save ModInfo
135- if (!modBundle .hasCustomModInfo ()) {
136- modBundle .saveModInfo ();
137- }
108+ .collect (Collectors .toList ());
138109
139- // Initialize git repository, but don't try if git is not installed
140- if (newModButton .isSelected () && GitHubManager .get ().hasGitInstalled ()) {
141- projectManager .initializeModBundleGit (modBundle );
110+ if (newModButton .isSelected ()) {
111+ ProjectManager .get ().createNewMod (
112+ modNameField .getText (),
113+ uniqueTagTextField .getText (),
114+ descriptionTextField .getText (),
115+ projectNameField .getText (),
116+ presets
117+ );
118+ } else {
119+ ProjectManager .get ().createNewProjectInMod (
120+ ProjectManager .get ().getModBundle (existingModChoiceBox .getValue ()),
121+ projectNameField .getText (),
122+ presets
123+ );
142124 }
143125 }
144126
@@ -162,7 +144,7 @@ public static void show() {
162144 }
163145
164146 private static boolean hasIllegalChar (String text ) {
165- return ILLEGAL_CHARACTERS .chars ().anyMatch (c -> text .indexOf (c ) != -1 );
147+ return ModBundle . NAME_ILLEGAL_CHARACTERS .chars ().anyMatch (c -> text .indexOf (c ) != -1 );
166148 }
167149
168150 private boolean isValid () {
@@ -224,15 +206,15 @@ private void initialize() {
224206 // Ban illegal characters
225207 modNameField .setTextFormatter (new TextFormatter <>(change -> {
226208 String text = change .getControlNewText ();
227- if (ILLEGAL_CHARACTERS .chars ().anyMatch (c -> text .indexOf (c ) != -1 )) {
209+ if (ModBundle . NAME_ILLEGAL_CHARACTERS .chars ().anyMatch (c -> text .indexOf (c ) != -1 )) {
228210 return null ;
229211 } else {
230212 return change ;
231213 }
232214 }));
233215 projectNameField .setTextFormatter (new TextFormatter <>(change -> {
234216 String text = change .getControlNewText ();
235- if (ILLEGAL_CHARACTERS .chars ().anyMatch (c -> text .indexOf (c ) != -1 )) {
217+ if (ModBundle . NAME_ILLEGAL_CHARACTERS .chars ().anyMatch (c -> text .indexOf (c ) != -1 )) {
236218 return null ;
237219 } else {
238220 return change ;
0 commit comments