Преглед на файлове

improved version display and #154

Nattiden преди 2 години
родител
ревизия
8872159aac

+ 2 - 3
Pages/News.yml

@@ -5,11 +5,10 @@ alias:
  - 主界面
 cards:
  - animated_noticebar
+ - ${@MainPageVersions|new}
  - 15th_anniversary | s = false
- - ${@LatestVersion|snapshot|1} | s = false 
  - T:Separator | content = 历史版本
- - ${@LatestVersion|snapshot|2}
- - ${@LatestVersion|release}
+ - ${@MainPageVersions|history}
  - jumpCard
  - T:Separator | content = 周边新闻
  - feedback_hint

+ 0 - 13
Resources/Scripts/FetchMainfest.py

@@ -1,13 +0,0 @@
-from Core.Debug import LogWarning
-import requests
-import json
-
-LAUNCHER_MANIFSET_URL = 'https://piston-meta.mojang.com/mc/game/version_manifest.json'
-
-def fetch():
-    try:
-        response = requests.get(LAUNCHER_MANIFSET_URL)
-        return json.loads(response.content)
-    except Exception as e:
-        LogWarning(f'获取版本列表失败:{e.with_traceback()}')
-        return {}

+ 0 - 23
Resources/Scripts/LatestVersion.py

@@ -1,23 +0,0 @@
-from Core.Debug import LogWarning, LogInfo
-from Core.ModuleManager import invokeModule, untilLoaded
-import requests
-import json
-
-untilLoaded('FetchMainfest')
-MANIFSET = invokeModule('FetchMainfest','fetch')()
-LATEST_VERSIONS = {'snapshot':'','release':''}
-LATEST_VERSIONS.update(MANIFSET['latest'])
-FULL_VERSIONS = MANIFSET.get('versions')
-LogInfo(f'[VersionScript] 最新快照版:{LATEST_VERSIONS["snapshot"]}; 最新正式版:{LATEST_VERSIONS["release"]}')
-
-def script(version_type,version_rank = '1',**kwagrs):
-    version_rank = int(version_rank)
-    if version_rank <= 1:
-        return f"{LATEST_VERSIONS[version_type]} | latest = true"
-    count = version_rank
-    for version in FULL_VERSIONS:
-        if version['type'] == version_type:
-            count -= 1
-            if count == 0:
-                return version['id']
-    return ''

+ 27 - 0
Resources/Scripts/MainPageVersions.py

@@ -0,0 +1,27 @@
+from Core.Debug import LogWarning, LogInfo
+from Core.ModuleManager import invokeModule, untilLoaded
+
+untilLoaded('MinecraftVersions') # 需求前置 MinecraftVersions
+get_latest = invokeModule('MinecraftVersions','get_latest')
+get_type = invokeModule('MinecraftVersions','get_version_type')
+
+latest_version = get_latest()
+latest_type = get_type(latest_version)
+
+def script(page_area,**kwagrs):
+    if page_area == 'new':
+        result = f"{latest_version} | latest = true | s = false"
+        if latest_type == 'snapshot':
+            iversion = latest_version
+            index = 1
+            while(True): # 循环添加该周发布的所有版本
+                if (get_type(iversion) != 'snapshot') or (iversion[5] == 'a'):
+                    break
+                index += 1
+                iversion = get_latest('snapshot',index)
+                result += f';{iversion} | s = false'
+        return result
+    else:
+        if latest_type == 'release':
+            return ''
+        return f"{get_latest('release')} | latest = true"

+ 63 - 0
Resources/Scripts/MinecraftVersions.py

@@ -0,0 +1,63 @@
+from Core.Debug import LogWarning, LogInfo
+import requests
+import json
+import re
+
+LAUNCHER_MANIFSET_URL = 'https://piston-meta.mojang.com/mc/game/version_manifest.json'
+MANIFSET = None
+FULL_VERSIONS = None
+LATEST_VERSIONS = None
+
+def fetch_manifset():
+    try:
+        response = requests.get(LAUNCHER_MANIFSET_URL)
+        return json.loads(response.content)
+    except Exception as e:
+        LogWarning(f'获取版本列表失败:{e.with_traceback()}')
+        return {}
+    
+def get_manifset():
+    global MANIFSET
+    if not MANIFSET:
+        MANIFSET = fetch_manifset()
+    return MANIFSET
+
+def init_version_dict():
+    global LATEST_VERSIONS,FULL_VERSIONS
+    LATEST_VERSIONS = {'snapshot':None,'release':None}
+    manifset = get_manifset()
+    LATEST_VERSIONS.update(manifset['latest'])
+    FULL_VERSIONS = manifset.get('versions')
+    LogInfo(f'[VersionScript] 最新快照版:{LATEST_VERSIONS["snapshot"]}; 最新正式版:{LATEST_VERSIONS["release"]}')
+    
+def get_latest(version_type = 'snapshot',version_rank = 1):
+    global LATEST_VERSIONS
+    if not LATEST_VERSIONS:
+        init_version_dict()
+    version_rank = int(version_rank)
+    if version_rank <= 1:
+        return LATEST_VERSIONS[version_type]
+    count = version_rank
+    for version in FULL_VERSIONS:
+        if version['type'] == version_type:
+            count -= 1
+            if count == 0:
+                return version['id']
+    return ''
+
+SNAPSHOT_PATTERN = re.compile(r'^[0-9]{2}[w|W][0-9]{2}[A-Fa-f]$')
+PRE_RELEASE_PATTERN = re.compile(r'^.*-pre[0-9]+$')
+RELEASE_CANDIDATE_PATTERN = re.compile(r'^.*-rc[0-9]+$')
+RELEASE_PATTERN = re.compile(r'^1\.[0-9]+(\.[0-9]+)?$')
+
+def get_version_type(version_id):
+    '''获取版本类型'''
+    if re.match(SNAPSHOT_PATTERN,version_id):
+        return 'snapshot'
+    if re.match(PRE_RELEASE_PATTERN,version_id):
+        return 'pre_release'
+    if re.match(RELEASE_CANDIDATE_PATTERN,version_id):
+        return 'release_candidate'
+    if re.match(RELEASE_PATTERN,version_id):
+        return 'release'
+    return 'other'

+ 2 - 2
Resources/Scripts/VersionCategory.py

@@ -4,8 +4,8 @@ from Core.ModuleManager import invokeModule, untilLoaded
 import requests
 import json
 
-untilLoaded('FetchMainfest')
-MANIFSET = invokeModule('FetchMainfest','fetch')()
+untilLoaded('MinecraftVersions') # 需求前置 MinecraftVersions
+MANIFSET = invokeModule('MinecraftVersions','get_manifset')()
 FULL_VERSIONS = MANIFSET.get('versions')
 ID_LIST = [version.get('id') for version in FULL_VERSIONS]