44
55use Microwin7 \PHPUtils \Utils \Path ;
66use Microwin7 \PHPUtils \Rules \Regex ;
7- use Microwin7 \PHPUtils \Configs \TextureConfig ;
87use function Microwin7 \PHPUtils \convertToBytes ;
98use function Microwin7 \PHPUtils \ar_slash_string ;
109use function Microwin7 \PHPUtils \str_ends_with_slash ;
1413use Microwin7 \PHPUtils \Contracts \Texture \Enum \ResponseTypeEnum ;
1514use Microwin7 \PHPUtils \Contracts \Texture \Enum \TextureStorageTypeEnum ;
1615
17- class Texture extends TextureConfig
16+ class Texture
1817{
1918 /**
2019 * Для вызова, сохранения, проверок
@@ -49,6 +48,33 @@ class Texture extends TextureConfig
4948 ZgAAAAxJREFUeAFjGAV4AQABIAABL3HDQQAAAABJRU5ErkJggg== " ;
5049 private const string SKIN_DEFAULT_SHA256 = '98805f6ab41575b7ff4af11b70c074773c5bcc210f2429f6b5513150d746e4cd ' ;
5150 private const string CAPE_DEFAULT_SHA256 = 'f2072fdfff5302b7c13672e54fdc8895dc75b3f675be3a43245de6894f971e38 ' ;
51+ /** list<array{0: int, 1: int}> */
52+ private const array SKIN_SIZE = [
53+ [64 , 64 ],
54+ [64 , 32 ]
55+ ];
56+ /** list<array{0: int, 1: int}> */
57+ private const array CAPE_SIZE = [
58+ [64 , 32 ]
59+ ];
60+ /** list<array{0: int, 1: int}> */
61+ private const array SKIN_SIZE_HD = [
62+ [128 , 64 ],
63+ [128 , 128 ],
64+ [256 , 128 ],
65+ [256 , 256 ],
66+ [512 , 256 ],
67+ [512 , 512 ],
68+ [1024 , 512 ],
69+ [1024 , 1024 ]
70+ ];
71+ /** list<array{0: int, 1: int}> */
72+ private const array CAPE_SIZE_HD = [
73+ [128 , 64 ],
74+ [256 , 128 ],
75+ [512 , 256 ],
76+ [1024 , 512 ]
77+ ];
5278
5379 /** BASE DIR */
5480 public static function STORAGE_DIR (): string
@@ -98,30 +124,52 @@ public static function PATH(ResponseTypeEnum|TextureStorageTypeEnum $type, strin
98124 $ extension ??= self ::EXTENSTION ();
99125 return self ::TEXTURE_STORAGE_FULL_PATH ($ type , $ size ) . $ login . $ extension ;
100126 }
101- /** @return array<array{w : int, h : int}> */
127+ /** @return array<array-key, object{width : int, height : int}> */
102128 public static function SIZE (ResponseTypeEnum $ type = ResponseTypeEnum::SKIN ): array
103129 {
104130 return match ($ type ) {
105- ResponseTypeEnum::SKIN => parent :: SKIN_SIZE ,
106- ResponseTypeEnum::CAPE => parent :: CAPE_SIZE ,
131+ ResponseTypeEnum::SKIN => self :: parseSizeEnvArray ( ' SKIN_SIZE ' ) ,
132+ ResponseTypeEnum::CAPE => self :: parseSizeEnvArray ( ' CAPE_SIZE ' ) ,
107133 default => throw new \InvalidArgumentException (sprintf ('Un-supported texture size type: %s ' , $ type ->name ))
108134 };
109135 }
110- /** @return array<array{w : int, h : int}> */
136+ /** @return array<array-key, object{width : int, height : int}> */
111137 public static function SIZE_WITH_HD (ResponseTypeEnum $ type = ResponseTypeEnum::SKIN ): array
112138 {
113139 return match ($ type ) {
114- ResponseTypeEnum::SKIN => parent :: SKIN_SIZE_HD ,
115- ResponseTypeEnum::CAPE => parent :: CAPE_SIZE_HD ,
140+ ResponseTypeEnum::SKIN => self :: parseSizeEnvArray ( ' SKIN_SIZE_HD ' ) ,
141+ ResponseTypeEnum::CAPE => self :: parseSizeEnvArray ( ' CAPE_SIZE_HD ' ) ,
116142 default => throw new \InvalidArgumentException (sprintf ('Un-supported texture size type: %s ' , $ type ->name ))
117143 };
118144 }
145+ /**
146+ * @param "SKIN_SIZE"|"CAPE_SIZE"|"SKIN_SIZE_HD"|"CAPE_SIZE_HD"
147+ * @return array<array-key, object{width: int, height: int}>
148+ */
149+ public static function parseSizeEnvArray (string $ env_name ): array
150+ {
151+ // putenv('SKIN_SIZE=128,64|128,128|256,128|256');
152+ try {
153+ $ ENV = getenv ($ env_name );
154+ if ($ ENV === false || empty ($ ENV )) new \RuntimeException ("ENV $ env_name empty " );
155+ return array_map (
156+ fn (string $ pair ) =>
157+ (object )array_combine (
158+ ['width ' , 'height ' ],
159+ array_map ('intval ' , explode (', ' , $ pair ))
160+ ),
161+ explode ('| ' , $ ENV )
162+ );
163+ } catch (\ValueError | \RuntimeException ) {
164+ return array_map (fn (array $ item ) => (object ) ['width ' => $ item [0 ], 'height ' => $ item [1 ]], self ::{$ env_name });
165+ }
166+ }
119167 /** @throws TextureSizeException */
120168 public static function validateSize (int $ width , int $ height , ResponseTypeEnum $ type = ResponseTypeEnum::SKIN ): true
121169 {
122170 $ valid_size = false ;
123171 foreach (self ::SIZE ($ type ) as $ value ) {
124- if ($ value[ ' w ' ] == $ width && $ value[ ' h ' ] == $ height ) {
172+ if ($ value-> width == $ width && $ value-> height == $ height ) {
125173 $ valid_size = true ;
126174 }
127175 }
@@ -132,7 +180,7 @@ public static function validateHDSize(int $width, int $height, ResponseTypeEnum
132180 {
133181 $ valid_size = false ;
134182 foreach (self ::SIZE_WITH_HD ($ type ) as $ value ) {
135- if ($ value[ ' w ' ] == $ width && $ value[ ' h ' ] == $ height ) {
183+ if ($ value-> width == $ width && $ value-> height == $ height ) {
136184 $ valid_size = true ;
137185 }
138186 }
0 commit comments