|
|
|
|
|
using Model.Classes;
|
|
|
using Microsoft.VisualBasic;
|
|
|
using Model.Serializer;
|
|
|
using Model.Stub;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Resources;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace Model.Managers
|
|
|
|
|
|
{
|
|
|
public class Manager
|
|
|
{
|
|
|
public IDataManager DataManager { get; set; }
|
|
|
public ObservableCollection<Bateau> Bateaux { get; set; }
|
|
|
public ObservableCollection<Personnage> Personnages { get; set; }
|
|
|
public ObservableCollection<FruitDuDemon> Fruits { get; set; }
|
|
|
public ObservableCollection<Ile> Iles { get; set; }
|
|
|
public ObservableCollection<Bestiaire> Bestiaire { get; set; }
|
|
|
public ObservableCollection<Equipage> Equipages { get; set; }
|
|
|
|
|
|
public ObjetOhara? SelectedItem { get; set; } = null;
|
|
|
|
|
|
public Manager(IDataManager dataManager) {
|
|
|
DataManager = dataManager;
|
|
|
Bateaux = new ObservableCollection<Bateau>(DataManager.GetBateaux());
|
|
|
Personnages = new ObservableCollection<Personnage>(DataManager.GetPersonnages());
|
|
|
Fruits = new ObservableCollection<FruitDuDemon>(DataManager.GetFruits());
|
|
|
Iles = new ObservableCollection<Ile>(DataManager.GetIles());
|
|
|
Bestiaire = new ObservableCollection<Bestiaire>(DataManager.GetBestiaires());
|
|
|
Equipages = new ObservableCollection<Equipage>(DataManager.GetEquipages());
|
|
|
}
|
|
|
|
|
|
public List<Personnage> GetPersonnages()
|
|
|
{
|
|
|
return DataManager.GetPersonnages().ToList();
|
|
|
}
|
|
|
public List<FruitDuDemon> GetFruits()
|
|
|
{
|
|
|
return DataManager.GetFruits().ToList();
|
|
|
}
|
|
|
public List<Equipage> GetEquipages()
|
|
|
{
|
|
|
return DataManager.GetEquipages().ToList();
|
|
|
}
|
|
|
public List<Bateau> GetBateaux()
|
|
|
{
|
|
|
return DataManager.GetBateaux().ToList();
|
|
|
}
|
|
|
public List<Bestiaire> GetBestiaires()
|
|
|
{
|
|
|
return DataManager.GetBestiaires().ToList();
|
|
|
}
|
|
|
public List<Ile> GetIles()
|
|
|
{
|
|
|
return DataManager.GetIles().ToList();
|
|
|
}
|
|
|
|
|
|
public List<FruitDuDemon> FiltrerFDD(string type)
|
|
|
{
|
|
|
List<FruitDuDemon> fdd = new List<FruitDuDemon>(Fruits);
|
|
|
foreach (FruitDuDemon f in fdd.ToList())
|
|
|
{
|
|
|
if (f.Type != type)
|
|
|
{
|
|
|
fdd.Remove(f);
|
|
|
}
|
|
|
}
|
|
|
return fdd;
|
|
|
}
|
|
|
|
|
|
public List<ObjetOhara> FiltrerFavs(string type)
|
|
|
{
|
|
|
List<ObjetOhara> favs = GetFavoris();
|
|
|
return favs;
|
|
|
}
|
|
|
|
|
|
public List<FruitDuDemon> RechercheFDD(string text, List<FruitDuDemon> listeFDD)
|
|
|
{
|
|
|
if (text == "")
|
|
|
{
|
|
|
return listeFDD;
|
|
|
}
|
|
|
foreach (FruitDuDemon f in listeFDD.ToList())
|
|
|
{
|
|
|
bool correspondance = false;
|
|
|
int textPos = 0;
|
|
|
for (int i = 0; i < f.Nom.Length; i++)
|
|
|
{
|
|
|
if (string.Equals(text[textPos].ToString(), f.Nom[i].ToString(), StringComparison.OrdinalIgnoreCase))
|
|
|
{
|
|
|
textPos++;
|
|
|
}
|
|
|
if (textPos == text.Length)
|
|
|
{
|
|
|
correspondance = true;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (!correspondance)
|
|
|
{
|
|
|
listeFDD.Remove(f);
|
|
|
}
|
|
|
}
|
|
|
return listeFDD;
|
|
|
}
|
|
|
public List<ObjetOhara> RechercheObjetOhara(string text, List<ObjetOhara> liste)
|
|
|
{
|
|
|
if (text == "")
|
|
|
{
|
|
|
return liste;
|
|
|
}
|
|
|
foreach (ObjetOhara f in liste.ToList())
|
|
|
{
|
|
|
bool correspondance = false;
|
|
|
int textPos = 0;
|
|
|
for (int i = 0; i < (f.Nom.Length); i++)
|
|
|
{
|
|
|
if (string.Equals(text[textPos].ToString(), f.Nom[i].ToString(), StringComparison.OrdinalIgnoreCase))
|
|
|
{
|
|
|
textPos++;
|
|
|
}
|
|
|
if (textPos == text.Length)
|
|
|
{
|
|
|
correspondance = true;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (!correspondance)
|
|
|
{
|
|
|
liste.Remove(f);
|
|
|
}
|
|
|
}
|
|
|
return liste;
|
|
|
}
|
|
|
public List<ObjetOhara> GetFavoris()
|
|
|
{
|
|
|
List<ObjetOhara> listeFavoris = new List<ObjetOhara>();
|
|
|
listeFavoris.AddRange(Bateaux);
|
|
|
listeFavoris.AddRange(Equipages);
|
|
|
listeFavoris.AddRange(Bestiaire);
|
|
|
listeFavoris.AddRange(Fruits);
|
|
|
listeFavoris.AddRange(Iles);
|
|
|
listeFavoris.AddRange(Personnages);
|
|
|
foreach(ObjetOhara obj in listeFavoris.ToList())
|
|
|
{
|
|
|
if (obj.EstFavori == false)
|
|
|
{
|
|
|
listeFavoris.Remove(obj);
|
|
|
}
|
|
|
}
|
|
|
return listeFavoris;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ModifierFavoris(ObjetOhara obj,bool value)
|
|
|
{
|
|
|
Type t = obj.GetType();
|
|
|
|
|
|
if (t.Equals(typeof(Bateau)))
|
|
|
foreach(Bateau b in Bateaux)
|
|
|
{
|
|
|
if (b.Equals(obj))
|
|
|
{
|
|
|
b.EstFavori = value;
|
|
|
DataManager.SetBateau(Bateaux.ToList());
|
|
|
}
|
|
|
}
|
|
|
else if (t.Equals(typeof(Equipage)))
|
|
|
foreach (Equipage b in Equipages)
|
|
|
{
|
|
|
if (b.Equals(obj))
|
|
|
{
|
|
|
b.EstFavori = value;
|
|
|
DataManager.SetEquipage(Equipages.ToList());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
else if (t.Equals(typeof(Personnage)))
|
|
|
foreach (Personnage b in Personnages)
|
|
|
{
|
|
|
if (b.Equals(obj))
|
|
|
{
|
|
|
b.EstFavori = value;
|
|
|
DataManager.SetPersonnage(Personnages.ToList());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
else if (t.Equals(typeof(Ile)))
|
|
|
foreach (Ile b in Iles)
|
|
|
{
|
|
|
if (b.Equals(obj))
|
|
|
{
|
|
|
b.EstFavori = value;
|
|
|
DataManager.SetIle(Iles.ToList());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
else if (t.Equals(typeof(FruitDuDemon)))
|
|
|
foreach (FruitDuDemon b in Fruits)
|
|
|
{
|
|
|
if (b.Equals(obj))
|
|
|
{
|
|
|
b.EstFavori = true;
|
|
|
DataManager.SetFDD(Fruits.ToList());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
else if (t.Equals(typeof(Bestiaire)))
|
|
|
foreach (Bestiaire b in Bestiaire)
|
|
|
{
|
|
|
if (b.Equals(obj))
|
|
|
{
|
|
|
b.EstFavori = value;
|
|
|
DataManager.SetBestiaire(Bestiaire.ToList());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|