22using Limekuma . Render . ExpressionEngine ;
33using Limekuma . Render . Nodes ;
44using SixLabors . ImageSharp ;
5+ using System . Collections ;
56
67namespace Limekuma . Render ;
78
89public sealed class Drawer
910{
10- public async Task < Image > DrawBestsAsync ( CommonUser user , IEnumerable < CommonRecord > ever ,
11- IEnumerable < CommonRecord > current , int everTotal , int currentTotal , string typename , string prober ) =>
11+ public async Task < Image > DrawBestsAsync ( CommonUser user , IList < CommonRecord > ever ,
12+ IList < CommonRecord > current , int everTotal , int currentTotal , string typename , string prober ) =>
1213 await DrawBestsAsync ( user , ever , current , everTotal , currentTotal , typename , prober , false , false ) ;
1314
14- public async Task < Image > DrawBestsAsync ( CommonUser user , IEnumerable < CommonRecord > ever ,
15- IEnumerable < CommonRecord > current , int everTotal , int currentTotal , string typename , string prober ,
15+ public async Task < Image > DrawBestsAsync ( CommonUser user , IList < CommonRecord > ever ,
16+ IList < CommonRecord > current , int everTotal , int currentTotal , string typename , string prober ,
1617 bool isAnime ) =>
1718 await DrawBestsAsync ( user , ever , current , everTotal , currentTotal , typename , prober , isAnime , false ) ;
1819
19- public async Task < Image > DrawBestsAsync ( CommonUser user , IEnumerable < CommonRecord > ever ,
20- IEnumerable < CommonRecord > current , int everTotal , int currentTotal , string typename , string prober ,
20+ public async Task < Image > DrawBestsAsync ( CommonUser user , IList < CommonRecord > ever ,
21+ IList < CommonRecord > current , int everTotal , int currentTotal , string typename , string prober ,
2122 bool isAnime , bool drawLevelSeg ) => await DrawBestsAsync ( user , ever , current , everTotal , currentTotal , typename ,
2223 prober , isAnime , drawLevelSeg , "./Resources/Layouts/bests.xml" ) ;
2324
24- public async Task < Image > DrawBestsAsync ( CommonUser user , IEnumerable < CommonRecord > ever ,
25- IEnumerable < CommonRecord > current , int everTotal , int currentTotal , string typename , string prober ,
25+ public async Task < Image > DrawBestsAsync ( CommonUser user , IList < CommonRecord > ever ,
26+ IList < CommonRecord > current , int everTotal , int currentTotal , string typename , string prober ,
2627 bool isAnime , bool drawLevelSeg , string xmlPath )
2728 {
28- List < CommonRecord > everList = [ .. ever ] ;
29- List < CommonRecord > currentList = [ .. current ] ;
30- List < object > everCards = [ .. everList . Select ( ( record , idx ) => new { Record = record , Index = idx + 1 } ) ] ;
31- List < object > currentCards =
32- [ .. currentList . Select ( ( record , idx ) => new { Record = record , Index = idx + everList . Count + 1 } ) ] ;
33- int everDelta = everList . Count > 34 ? everList [ 0 ] . DXRating - everList [ ^ 1 ] . DXRating : everList . Count > 0 ? everList [ 0 ] . DXRating : 0 ;
34- int currentDelta = currentList . Count > 14 ? currentList [ 0 ] . DXRating - currentList [ ^ 1 ] . DXRating : currentList . Count > 0 ? currentList [ 0 ] . DXRating : 0 ;
35- int everMax = everList . Count > 0 ? everList [ 0 ] . DXRating : 0 ;
36- int everMin = everList . Count > 0 ? everList [ ^ 1 ] . DXRating : 0 ;
37- int currentMax = currentList . Count > 0 ? currentList [ 0 ] . DXRating : 0 ;
38- int currentMin = currentList . Count > 0 ? currentList [ ^ 1 ] . DXRating : 0 ;
39- int realRating = everTotal + currentTotal ;
40- string proberState = "on" ;
41- if ( user . Rating != realRating )
29+ int everMax = ever . Count > 0 ? ever [ 0 ] . DXRating : 0 ;
30+ int everMin = ever . Count > 0 ? ever [ ^ 1 ] . DXRating : 0 ;
31+ int currentMax = current . Count > 0 ? current [ 0 ] . DXRating : 0 ;
32+ int currentMin = current . Count > 0 ? current [ ^ 1 ] . DXRating : 0 ;
33+ bool mayMask = ever . Any ( r => r . DXScore is 0 && ( r . DXStar > 0 || r . Rank > Ranks . A ) ) || current . Any ( r => r . DXScore is 0 && ( r . DXStar > 0 || r . Rank > Ranks . A ) ) ;
34+ Dictionary < string , object > scope = new ( StringComparer . OrdinalIgnoreCase )
4235 {
43- proberState = "off" ;
44- }
45- else if ( everList . Any ( r => r . DXScore is 0 && ( r . DXStar > 0 || r . Rank < Ranks . C ) ) ||
46- currentList . Any ( r => r . DXScore is 0 && ( r . DXStar > 0 || r . Rank < Ranks . C ) ) )
47- {
48- proberState = "warning" ;
49- }
50-
51- Dictionary < string , object ? > scope = new ( StringComparer . OrdinalIgnoreCase )
52- {
53- [ "user" ] = user ,
54- [ "everCards" ] = everCards ,
55- [ "currentCards" ] = currentCards ,
56- [ "everDelta" ] = everDelta ,
57- [ "currentDelta" ] = currentDelta ,
58- [ "everTotal" ] = everTotal ,
59- [ "currentTotal" ] = currentTotal ,
60- [ "realRating" ] = realRating ,
61- [ "typename" ] = typename ,
62- [ "prober" ] = prober ,
63- [ "isAnime" ] = isAnime ,
64- [ "drawLevelSeg" ] = drawLevelSeg ,
65- [ "proberState" ] = proberState ,
36+ [ "userInfo" ] = user ,
37+ [ "everRecords" ] = ever ,
38+ [ "currentRecords" ] = current ,
39+ [ "everRating" ] = everTotal ,
40+ [ "currentRating" ] = currentTotal ,
41+ [ "typeName" ] = typename ,
42+ [ "proberName" ] = prober ,
43+ [ "animeMode" ] = isAnime ,
44+ [ "needSuggestion" ] = drawLevelSeg ,
45+ [ "mayMask" ] = mayMask ,
6646 [ "everMax" ] = everMax ,
6747 [ "everMin" ] = everMin ,
6848 [ "currentMax" ] = currentMax ,
@@ -71,35 +51,33 @@ public async Task<Image> DrawBestsAsync(CommonUser user, IEnumerable<CommonRecor
7151 return await DrawAsync ( scope , xmlPath ) ;
7252 }
7353
74- public async Task < Image > DrawListAsync ( CommonUser user , IEnumerable < CommonRecord > records , int page , int total ,
75- IEnumerable < int > counts , string level , string prober ) => await DrawListAsync ( user , records , page , total , counts ,
76- level , prober , "./Resources/Layouts/list.xml" ) ;
54+ public async Task < Image > DrawListAsync ( CommonUser user , IList < CommonRecord > records , int page , int total ,
55+ IList < int > counts , int startIndex , string level , string prober ) => await DrawListAsync ( user , records , page , total , counts ,
56+ startIndex , level , prober , "./Resources/Layouts/list.xml" ) ;
7757
78- public async Task < Image > DrawListAsync ( CommonUser user , IEnumerable < CommonRecord > records , int page , int total ,
79- IEnumerable < int > counts , string level , string prober , string xmlPath )
58+ public async Task < Image > DrawListAsync ( CommonUser user , IList < CommonRecord > records , int page , int total ,
59+ IList < int > counts , int startIndex , string level , string prober , string xmlPath )
8060 {
81- List < CommonRecord > list = [ .. records ] ;
82- List < object > recordCards = [ .. list . Select ( ( record , idx ) => new { Record = record , Index = idx + 1 } ) ] ;
83- List < int > countList = counts . ToList ( ) ;
84- int totalCount = countList . Count > 0 ? countList [ ^ 1 ] : 0 ;
85- bool warning = list . Any ( r => r . DXScore is 0 && ( r . DXStar > 0 || r . Rank < Ranks . C ) ) ;
86- Dictionary < string , object ? > scope = new ( StringComparer . OrdinalIgnoreCase )
61+ int totalCount = counts . Count > 0 ? counts [ ^ 1 ] : 0 ;
62+ bool mayMask = records . Any ( r => r . DXScore is 0 && ( r . DXStar > 0 || r . Rank > Ranks . A ) ) ;
63+ Dictionary < string , object > scope = new ( StringComparer . OrdinalIgnoreCase )
8764 {
88- [ "user" ] = user ,
89- [ "recordCards" ] = recordCards ,
90- [ "page" ] = page ,
91- [ "total" ] = total ,
92- [ "counts" ] = countList [ ..^ 1 ] ,
93- [ "statsTotalCount" ] = totalCount ,
65+ [ "userInfo" ] = user ,
66+ [ "pageRecords" ] = records ,
67+ [ "pageNumber" ] = page ,
68+ [ "totalPages" ] = total ,
69+ [ "statCounts" ] = counts . ToList ( ) [ ..^ 1 ] ,
70+ [ "totalCount" ] = totalCount ,
71+ [ "startIndex" ] = startIndex ,
9472 [ "level" ] = level ,
95- [ "prober " ] = prober ,
96- [ "proberState " ] = warning ? "warning" : "on" ,
97- [ "isAnime " ] = false ,
73+ [ "proberName " ] = prober ,
74+ [ "mayMask " ] = mayMask ,
75+ [ "animeMode " ] = false ,
9876 } ;
9977 return await DrawAsync ( scope , xmlPath ) ;
10078 }
10179
102- private async Task < Image > DrawAsync ( Dictionary < string , object ? > scope , string xmlPath )
80+ private async Task < Image > DrawAsync ( IDictionary < string , object > scope , string xmlPath )
10381 {
10482 AsyncNCalcEngine expr = new ( ) ;
10583 RegisterFunctions ( expr ) ;
@@ -112,5 +90,6 @@ private async Task<Image> DrawAsync(Dictionary<string, object?> scope, string xm
11290 private void RegisterFunctions ( AsyncNCalcEngine expr )
11391 {
11492 expr . RegisterFunction ( "ToString" , ( object x ) => Convert . ToString ( x ) ) ;
93+ expr . RegisterFunction ( "Count" , ( IList x ) => x . Count ) ;
11594 }
11695}
0 commit comments