Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
NewsList.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.IO;
3
4public class NewsList : EClass
5{
6 public class Item : EClass
7 {
8 public string title;
9
10 public string content;
11
12 public List<string> listImageId = new List<string>();
13 }
14
15 public static Dictionary<string, List<Item>> dict;
16
17 public static List<Item> listAll = new List<Item>();
18
19 public static void Init()
20 {
21 if (dict == null)
22 {
23 dict = new Dictionary<string, List<Item>>();
24 listAll.Clear();
26 }
27 static void AddDir(string path)
28 {
29 DirectoryInfo directoryInfo = new DirectoryInfo(path);
30 Item item = null;
31 FileInfo[] files = directoryInfo.GetFiles();
32 foreach (FileInfo fileInfo in files)
33 {
34 if (!(fileInfo.Extension != ".txt"))
35 {
36 string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.Name);
37 List<Item> list = dict.TryGetValue(fileNameWithoutExtension);
38 StreamReader streamReader = new StreamReader(fileInfo.FullName);
39 string text = null;
40 while (!streamReader.EndOfStream)
41 {
42 string text2 = streamReader.ReadLine();
43 if (!string.IsNullOrEmpty(text2))
44 {
45 if (text2.StartsWith('@') && item != null)
46 {
47 string[] array = text2.TrimStart('@').Split(',');
48 foreach (string item2 in array)
49 {
50 item.listImageId.Add(item2);
51 }
52 }
53 else if (text == null)
54 {
55 text = text2;
56 }
57 else
58 {
59 item = new Item
60 {
61 title = text,
62 content = text2
63 };
64 if (list == null)
65 {
66 list = new List<Item>();
67 dict.Add(fileNameWithoutExtension, list);
68 }
69 list.Add(item);
70 listAll.Add(item);
71 text = null;
72 }
73 }
74 }
75 }
76 }
77 }
78 }
79
80 public static List<Item> GetNews(int seed)
81 {
82 Init();
84 List<Item> list = new List<Item>();
85 for (int i = 0; i < 1000; i++)
86 {
87 Item item = listAll.RandomItem();
88 if (!list.Contains(item))
89 {
90 list.Add(item);
91 if (list.Count >= 3)
92 {
93 break;
94 }
95 }
96 }
97 Rand.SetSeed();
98 return list;
99 }
100}
@ seed
item3. title
Definition: UIBook.cs:616
static string News
Definition: CorePath.cs:79
Definition: EClass.cs:5
string title
Definition: NewsList.cs:8
string content
Definition: NewsList.cs:10
List< string > listImageId
Definition: NewsList.cs:12
static List< Item > GetNews(int seed)
Definition: NewsList.cs:80
static void Init()
Definition: NewsList.cs:19
static Dictionary< string, List< Item > > dict
Definition: NewsList.cs:15
static List< Item > listAll
Definition: NewsList.cs:17
Definition: Rand.cs:4
static void SetSeed(int a=-1)
Definition: Rand.cs:37