Browse Source

'apis/versions/latest-card

Light Beacon 2 years ago
parent
commit
883f1da649

+ 5 - 0
Libraries/Homepage/VersionLatestListCard.xaml

@@ -0,0 +1,5 @@
+<local:MyCard Title="最新版本" CanSwap="${card-can-swap|False}" IsSwaped="${card-is-swaped|False}" ${@IF|${enable-card-style}|Style="{StaticResource Card}"}>
+<StackPanel Margin="${content-margin|8,35,8,15}">
+${@VersionLatestList}
+</StackPanel>
+</local:MyCard>

+ 14 - 3
Modules/APIs.py

@@ -31,8 +31,8 @@ class LatestVersionAPI(PageBase):
     def __init__(self, project):
         super().__init__(project)
         self.latest_release = self.project.base_library.get_card(mcv.get_latest('release'),False)
-        if mcv.get_version_type(latest_version) == 'snapshot':
-            self.latest_snapshot = self.project.base_library.get_card(mcv.get_latest(),False)
+        if latest_snap_shot_id := mcv.get_latest('snapshot'):
+            self.latest_snapshot = self.project.base_library.get_card(latest_snap_shot_id,False)
         else:
             self.latest_snapshot = None
         self.respond = None
@@ -74,4 +74,15 @@ class LatestVersionAPI(PageBase):
         return json.dumps(self.respond,ensure_ascii=ensure_ascii)
     
     def get_content_type(self, setter):
-        return 'application/json'
+        return 'application/json'
+    
+@page_class_handles('apis/versions/latest-card')
+class LatestVersionCardAPI(PageBase):
+    def generate(self, *args, **kwargs):
+        setter = kwargs.get('setter')
+        card = self.project.base_library.get_card('VersionLatestListCard', False)
+        card = setter.decorate(card)
+        return self.project.template_manager.build(card)
+
+    def get_content_type(self, setter):
+        return 'text/plain'

+ 10 - 3
Modules/MinecraftVersions.py

@@ -35,15 +35,22 @@ def init_version_dict():
     FULL_VERSIONS = manifset.get('versions')
     for version in FULL_VERSIONS:
         VERSIONS_DICT[version['id']] = version
+    if get_version_type(LATEST_VERSIONS["snapshot"]) == 'release':
+        LATEST_VERSIONS["snapshot"] = None
     logger.info(f'最新快照版:{LATEST_VERSIONS["snapshot"]}; 最新正式版:{LATEST_VERSIONS["release"]}')
 
-def get_latest(version_type = 'snapshot',version_rank = 1):
+def get_latest(version_type = 'all',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]
+    if version_rank <= 0:
+        if(version_type == 'all'):
+            if latest_snapshot := LATEST_VERSIONS['snapshot']:
+                return latest_snapshot
+            else:
+                return LATEST_VERSIONS['relese']
+        return LATEST_VERSIONS.get(version_type)
     count = version_rank
     for version in FULL_VERSIONS:
         if version['type'] == version_type:

+ 12 - 1
Modules/VersionAchiveList.py → Modules/VersionLists.py

@@ -6,7 +6,7 @@ MANIFSET = mcv.get_manifset()
 FULL_VERSIONS = MANIFSET.get('versions')
 ID_LIST = [version.get('id') for version in FULL_VERSIONS]
 
-@script('VersionAchiveList')
+@script('VersionArchiveList')
 def version_achive_list(cat_name,proj:Project,card,**_):
     cat_name = format_code(code = cat_name,card=card,project=proj)
     cards = list(filter(lambda card:isinstance(card.get('cats'),list)
@@ -26,3 +26,14 @@ def version_achive_list(cat_name,proj:Project,card,**_):
                             card=vercard,project=proj)
     code += '</StackPanel>'
     return code
+
+@script('VersionLatestList')
+def version_latest_list(proj:Project,card,**_):
+    res = proj.resources
+    code = ''
+    for version_type in ['release','snapshot']:
+        if latest_version := mcv.get_latest(version_type):
+            vercard = proj.base_library.get_card(latest_version,False)
+            code += format_code(code = res.components['VersionLinks/Latest'],
+                            card=vercard,project=proj)
+    return code

+ 3 - 0
Resources/Components/VersionLinks/Latest.xaml

@@ -0,0 +1,3 @@
+<local:MyListItem Margin="10,1,10,1" ToolTip="最新${version-type} 点击查看该版本更新日志"
+	Logo="${list-icon}" Title="最新${version-type} - ${version-id}" Info="${@IF|${intro}|${intro}|${version-type}}"
+	EventType="打开帮助" EventData="https://news.bugjump.net/VersionDetail.json?ver=${version-id}" Type="Clickable" />

+ 1 - 1
Resources/Templates/VersionAchiveList.yml → Resources/Templates/VersionArchiveList.yml

@@ -1,5 +1,5 @@
 components:
- - $VersionAchiveList|${cat}
+ - $VersionArchiveList|${cat}
 base: Card
 fill:
    title: 版本列表