Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Neos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
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
Neos
Commits
2643ef1a
Commit
2643ef1a
authored
Jul 12, 2023
by
timel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: preload card image
parent
4459490c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
2 deletions
+31
-2
src/ui/Duel/PlayMat/Card/index.tsx
src/ui/Duel/PlayMat/Card/index.tsx
+6
-1
src/ui/Duel/PlayMat/Card/springs/index.ts
src/ui/Duel/PlayMat/Card/springs/index.ts
+1
-0
src/ui/Duel/PlayMat/Card/springs/utils.ts
src/ui/Duel/PlayMat/Card/springs/utils.ts
+23
-0
src/ui/Shared/YgoCard/index.tsx
src/ui/Shared/YgoCard/index.tsx
+1
-1
No files found.
src/ui/Duel/PlayMat/Card/index.tsx
View file @
2643ef1a
...
...
@@ -34,6 +34,7 @@ import {
moveToToken
,
}
from
"
./springs
"
;
import
type
{
SpringApiProps
}
from
"
./springs/types
"
;
import
{
preloadCardImage
}
from
"
./springs/utils
"
;
const
{
HAND
,
GRAVE
,
REMOVED
,
DECK
,
EXTRA
,
MZONE
,
SZONE
,
TZONE
}
=
ygopro
.
CardZone
;
...
...
@@ -106,7 +107,10 @@ export const Card: React.FC<{ idx: number }> = React.memo(({ idx }) => {
Task
.
Move
,
async
(
uuid
:
string
,
fromZone
?:
ygopro
.
CardZone
)
=>
{
if
(
uuid
===
card
.
uuid
)
{
await
addToAnimation
(()
=>
move
(
card
.
location
.
zone
,
fromZone
));
await
addToAnimation
(
async
()
=>
{
await
preloadCardImage
(
card
.
code
);
await
move
(
card
.
location
.
zone
,
fromZone
);
});
}
}
);
...
...
@@ -114,6 +118,7 @@ export const Card: React.FC<{ idx: number }> = React.memo(({ idx }) => {
eventbus
.
register
(
Task
.
Focus
,
async
(
uuid
:
string
)
=>
{
if
(
uuid
===
card
.
uuid
)
{
await
addToAnimation
(
async
()
=>
{
await
preloadCardImage
(
card
.
code
);
setClassFocus
(
true
);
setTimeout
(()
=>
setClassFocus
(
false
),
1000
);
await
focus
({
card
,
api
});
...
...
src/ui/Duel/PlayMat/Card/springs/index.ts
View file @
2643ef1a
...
...
@@ -5,3 +5,4 @@ export * from "./moveToGround";
export
*
from
"
./moveToHand
"
;
export
*
from
"
./moveToOutside
"
;
export
*
from
"
./moveToToken
"
;
export
*
from
"
./utils
"
;
src/ui/Duel/PlayMat/Card/springs/utils.ts
View file @
2643ef1a
...
...
@@ -2,6 +2,7 @@ import { type SpringConfig, type SpringRef } from "@react-spring/web";
import
type
{
ygopro
}
from
"
@/api
"
;
import
{
type
CardType
}
from
"
@/stores
"
;
import
{
getCardImgUrl
}
from
"
@/ui/Shared
"
;
import
type
{
SpringApi
}
from
"
./types
"
;
...
...
@@ -20,3 +21,25 @@ export type MoveFunc = (props: {
api
:
SpringApi
;
fromZone
?:
ygopro
.
CardZone
;
})
=>
Promise
<
void
>
;
// >>> preload image >>>
const
preloadImageSet
=
new
Set
<
string
>
();
export
const
preloadImage
=
(
src
:
string
)
=>
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
if
(
preloadImageSet
.
has
(
src
))
{
resolve
();
}
else
{
const
image
=
new
Image
();
image
.
onload
=
async
()
=>
{
await
new
Promise
((
r
)
=>
setTimeout
(
r
,
100
));
resolve
();
preloadImageSet
.
add
(
src
);
};
image
.
onerror
=
reject
;
image
.
src
=
src
;
}
});
export
const
preloadCardImage
=
(
code
:
number
)
=>
preloadImage
(
getCardImgUrl
(
code
));
// <<< preload image <<<
src/ui/Shared/YgoCard/index.tsx
View file @
2643ef1a
...
...
@@ -38,7 +38,7 @@ export const YgoCard: React.FC<Props> = (props) => {
const
NeosConfig
=
useConfig
();
function
getCardImgUrl
(
code
:
number
,
back
=
false
)
{
export
function
getCardImgUrl
(
code
:
number
,
back
=
false
)
{
const
ASSETS_BASE
=
import
.
meta
.
env
.
BASE_URL
===
"
/
"
?
NeosConfig
.
assetsPath
...
...
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