Search in sources :

Example 1 with ModList

use of mod.ModList in project ParadoxosModManager by ThibautSF.

the class TestModList method setUp.

@Before
public void setUp() {
    modList = new ModList("", "", Languages.ENGLISH, new ArrayList<>());
    MockitoAnnotations.initMocks(this);
    mod1 = Mockito.mock(Mod.class);
    Mockito.when(mod1.getName()).thenReturn("mod1");
    Mockito.when(mod1.getModifiedFiles()).thenReturn(getModifiedFiles(true, true));
    mod2 = Mockito.mock(Mod.class);
    Mockito.when(mod2.getName()).thenReturn("mod2");
    Mockito.when(mod2.getModifiedFiles()).thenReturn(getModifiedFiles(true, false));
    MockitoAnnotations.initMocks(this);
    mod3 = Mockito.mock(Mod.class);
    Mockito.when(mod3.getName()).thenReturn("mod3");
    Mockito.when(mod3.getModifiedFiles()).thenReturn(getModifiedFiles(false, true));
}
Also used : Mod(mod.Mod) ArrayList(java.util.ArrayList) ModList(mod.ModList) Before(org.junit.Before)

Example 2 with ModList

use of mod.ModList in project ParadoxosModManager by ThibautSF.

the class MyXML method getSavedList.

/**
 * @return
 */
public ArrayList<ModList> getSavedList(Map<String, Mod> availableMods) {
    ArrayList<ModList> userLists = new ArrayList<ModList>();
    List<Element> modLists = root.getChildren(LIST);
    Iterator<Element> i = modLists.iterator();
    while (i.hasNext()) {
        ArrayList<Mod> listMods = new ArrayList<Mod>();
        Element oneListElement = (Element) i.next();
        String listName = oneListElement.getAttribute(NAME).getValue();
        String listDescr = oneListElement.getChild(DESCR).getText();
        String listLang;
        try {
            listLang = oneListElement.getChild(LANG).getText();
        } catch (RuntimeException e) {
            listLang = null;
        }
        List<Element> modsElements = oneListElement.getChildren(MOD);
        for (Element modElement : modsElements) {
            List<Attribute> modElementAttr = modElement.getAttributes();
            String fileName = "", modName = "", remoteFileId = null;
            for (Attribute attribute : modElementAttr) {
                switch(attribute.getName()) {
                    case ID:
                    case FILE_NAME:
                        fileName = attribute.getValue();
                        break;
                    case MOD_NAME:
                        modName = attribute.getValue();
                        break;
                    case REMOTE_ID:
                        remoteFileId = attribute.getValue();
                        break;
                    default:
                        break;
                }
            }
            Mod oneMod = availableMods.get(fileName);
            if (oneMod == null) {
                oneMod = new Mod(modName, fileName, remoteFileId);
                if (remoteFileId != null && !"".equals(remoteFileId)) {
                    for (Mod mod : availableMods.values()) {
                        if (mod.getRemoteFileID().equals(remoteFileId)) {
                            oneMod = mod;
                        }
                    }
                }
            }
            if (!listMods.contains(oneMod)) {
                listMods.add(oneMod);
            }
        }
        ModList oneList = new ModList(listName, listDescr, Languages.getLanguage(listLang), listMods);
        userLists.add(oneList);
    }
    return userLists;
}
Also used : Mod(mod.Mod) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) ModList(mod.ModList)

Example 3 with ModList

use of mod.ModList in project ParadoxosModManager by ThibautSF.

the class MyXML method importList.

public String importList(String xml, Map<String, Mod> availableMods) throws Exception {
    SAXBuilder sxb = new SAXBuilder();
    Document importDocument = sxb.build(xml);
    Element importRoot = importDocument.getRootElement();
    if (importRoot.getAttribute(GAME_ID).getValue().equals(ModManager.STEAM_ID.toString())) {
        List<Element> modLists = importRoot.getChildren(LIST);
        Iterator<Element> i = modLists.iterator();
        while (i.hasNext()) {
            ArrayList<Mod> listMods = new ArrayList<Mod>();
            Element oneListElement = (Element) i.next();
            String listName = oneListElement.getAttribute(NAME).getValue();
            String listDescr = oneListElement.getChild(DESCR).getText();
            String listLang = oneListElement.getChild(LANG).getText();
            List<Element> modsElements = oneListElement.getChildren(MOD);
            for (Element modElement : modsElements) {
                List<Attribute> modElementAttr = modElement.getAttributes();
                String fileName = "", modName = "", remoteFileId = null;
                for (Attribute attribute : modElementAttr) {
                    switch(attribute.getName()) {
                        case ID:
                        case FILE_NAME:
                            fileName = attribute.getValue();
                            break;
                        case MOD_NAME:
                            modName = attribute.getValue();
                            break;
                        case REMOTE_ID:
                            remoteFileId = attribute.getValue();
                            break;
                        default:
                            break;
                    }
                }
                Mod oneMod = availableMods.get(fileName);
                if (oneMod == null) {
                    oneMod = new Mod(modName, fileName, remoteFileId);
                    if (remoteFileId != null && !"".equals(remoteFileId)) {
                        for (Mod mod : availableMods.values()) {
                            if (mod.getRemoteFileID().equals(remoteFileId)) {
                                oneMod = mod;
                            }
                        }
                    }
                }
                if (!listMods.contains(oneMod)) {
                    listMods.add(oneMod);
                }
            }
            ModList oneList = new ModList("[Imported]" + listName + "_" + System.currentTimeMillis(), listDescr, Languages.getLanguage(listLang), listMods);
            modifyList(oneList);
        }
        return "Import done.";
    }
    return "Import procedure aborted, this list is not for the current game !";
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Mod(mod.Mod) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Document(org.jdom2.Document) ModList(mod.ModList)

Aggregations

ArrayList (java.util.ArrayList)3 Mod (mod.Mod)3 ModList (mod.ModList)3 Attribute (org.jdom2.Attribute)2 Element (org.jdom2.Element)2 Document (org.jdom2.Document)1 SAXBuilder (org.jdom2.input.SAXBuilder)1 Before (org.junit.Before)1