Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro-deck-encode
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
ygopro-deck-encode
Commits
ee8b98be
Commit
ee8b98be
authored
Jul 09, 2025
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add noCompact mode
parent
770e2a87
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
16 deletions
+45
-16
index.ts
index.ts
+15
-15
src/utils.ts
src/utils.ts
+30
-1
No files found.
index.ts
View file @
ee8b98be
import
{
fromBase64Url
,
toBase64Url
}
from
'
./src/base64
'
;
import
{
BufferReader
,
BufferWriter
,
countItems
}
from
'
./src/utils
'
;
import
{
BufferReader
,
BufferWriter
,
count
ConsecutiveItems
,
count
Items
}
from
'
./src/utils
'
;
import
{
fromYdkeURL
,
toYdkeURL
}
from
'
./src/ydke
'
;
import
{
fromYGOMobileDeckURL
,
toYGOMobileDeckURL
}
from
'
./src/ygom
'
;
...
...
@@ -9,23 +9,23 @@ export default class YGOProDeck {
side
:
number
[]
=
[];
name
?:
string
;
bufferLength
()
{
const
counted
=
[
this
.
main
,
this
.
extra
,
this
.
side
].
map
(
countItems
);
return
counted
.
reduce
((
a
,
b
)
=>
a
+
b
.
size
*
4
,
0
);
bufferLength
(
noCompact
=
false
)
{
const
counted
=
[
this
.
main
,
this
.
extra
,
this
.
side
].
map
(
noCompact
?
countConsecutiveItems
:
countItems
);
return
counted
.
reduce
((
a
,
b
)
=>
a
+
b
.
length
*
4
,
0
);
}
toUint8Array
()
{
const
counted
=
[
this
.
main
,
this
.
extra
,
this
.
side
].
map
(
countItems
);
toUint8Array
(
noCompact
=
false
)
{
const
counted
=
[
this
.
main
,
this
.
extra
,
this
.
side
].
map
(
noCompact
?
countConsecutiveItems
:
countItems
);
const
writer
=
new
BufferWriter
(
counted
.
reduce
((
a
,
b
)
=>
a
+
b
.
size
*
4
,
0
),
counted
.
reduce
((
a
,
b
)
=>
a
+
b
.
length
*
4
,
0
),
);
const
writeCards
=
(
countMap
:
Map
<
number
,
number
>
,
type
:
number
)
=>
{
const
writeCards
=
(
countMap
:
{
item
:
number
,
count
:
number
}[]
,
type
:
number
)
=>
{
// each card: 28 bits for id, 2 bits(0, 1, 2, 3) for type(0: main, 1: extra, 2: side, 3: unknown), 2 bits for count (0: 1, 1: 2, 2: 3, 3: 4)
for
(
const
[
id
,
count
]
of
countMap
.
entries
()
)
{
for
(
const
{
item
,
count
}
of
countMap
)
{
if
(
count
>
4
)
{
throw
new
Error
(
`Too many cards:
${
i
d
}
`
);
throw
new
Error
(
`Too many cards:
${
i
tem
}
`
);
}
const
value
=
(
i
d
&
0xfffffff
)
|
(
type
<<
28
)
|
((
count
-
1
)
<<
30
);
const
value
=
(
i
tem
&
0xfffffff
)
|
(
type
<<
28
)
|
((
count
-
1
)
<<
30
);
writer
.
writeUint32LE
(
value
);
}
};
...
...
@@ -33,12 +33,12 @@ export default class YGOProDeck {
return
writer
.
buffer
;
}
toEncodedString
()
{
return
toBase64Url
(
this
.
toUint8Array
());
toEncodedString
(
noCompact
=
false
)
{
return
toBase64Url
(
this
.
toUint8Array
(
noCompact
));
}
toString
()
{
return
this
.
toEncodedString
();
toString
(
noCompact
=
false
)
{
return
this
.
toEncodedString
(
noCompact
);
}
fromUint8Array
(
buf
:
Uint8Array
)
{
...
...
src/utils.ts
View file @
ee8b98be
...
...
@@ -3,8 +3,37 @@ export function countItems<T>(arr: T[]) {
for
(
const
item
of
arr
)
{
map
.
set
(
item
,
(
map
.
get
(
item
)
||
0
)
+
1
);
}
return
map
;
const
blocks
:
{
item
:
T
,
count
:
number
}[]
=
[];
for
(
const
[
item
,
count
]
of
map
.
entries
())
{
blocks
.
push
({
item
,
count
});
}
return
blocks
;
}
export
function
countConsecutiveItems
<
T
>
(
arr
:
T
[])
{
const
result
:
{
item
:
T
;
count
:
number
}[]
=
[];
if
(
arr
.
length
===
0
)
return
result
;
let
currentItem
=
arr
[
0
];
let
count
=
1
;
for
(
let
i
=
1
;
i
<
arr
.
length
;
i
++
)
{
if
(
arr
[
i
]
===
currentItem
)
{
count
++
;
}
else
{
result
.
push
({
item
:
currentItem
,
count
});
currentItem
=
arr
[
i
];
count
=
1
;
}
}
// 推入最后一组
result
.
push
({
item
:
currentItem
,
count
});
return
result
;
}
abstract
class
BufferCursor
{
buffer
:
Uint8Array
;
pointer
=
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment