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
f334f373
Commit
f334f373
authored
Nov 30, 2022
by
Chunchi Che
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feat/duel/slice' into 'main'
Feat/duel/slice See merge request
!26
parents
cd0de481
85edf087
Pipeline
#18289
passed with stages
in 2 minutes and 23 seconds
Changes
13
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
91 additions
and
36 deletions
+91
-36
src/api/cards.ts
src/api/cards.ts
+22
-1
src/config/ui.ts
src/config/ui.ts
+0
-0
src/reducers/duel/handsSlice.ts
src/reducers/duel/handsSlice.ts
+43
-7
src/ui/Duel/duel.ts
src/ui/Duel/duel.ts
+2
-2
src/ui/Duel/simpleDuel/cemetery.ts
src/ui/Duel/simpleDuel/cemetery.ts
+1
-1
src/ui/Duel/simpleDuel/deck.ts
src/ui/Duel/simpleDuel/deck.ts
+1
-1
src/ui/Duel/simpleDuel/exclusion.ts
src/ui/Duel/simpleDuel/exclusion.ts
+1
-1
src/ui/Duel/simpleDuel/extraMonsters.ts
src/ui/Duel/simpleDuel/extraMonsters.ts
+1
-1
src/ui/Duel/simpleDuel/field.ts
src/ui/Duel/simpleDuel/field.ts
+1
-1
src/ui/Duel/simpleDuel/hands.ts
src/ui/Duel/simpleDuel/hands.ts
+12
-11
src/ui/Duel/simpleDuel/magics.ts
src/ui/Duel/simpleDuel/magics.ts
+1
-1
src/ui/Duel/simpleDuel/mod.tsx
src/ui/Duel/simpleDuel/mod.tsx
+5
-8
src/ui/Duel/simpleDuel/monsters.ts
src/ui/Duel/simpleDuel/monsters.ts
+1
-1
No files found.
src/api/cards.ts
View file @
f334f373
import
axios
from
"
axios
"
;
export
interface
CardMeta
{
interface
CardMeta
{
id
:
number
;
data
:
{
ot
?:
number
;
...
...
@@ -19,6 +19,27 @@ export interface CardMeta {
};
}
interface
CardTransform
{
position
?:
{
x
:
number
;
y
:
number
;
z
:
number
;
};
rotation
?:
{
x
:
number
;
y
:
number
;
z
:
number
;
};
}
/*
* `Neos`中表示卡牌的通用结构
* */
export
interface
Card
{
meta
:
CardMeta
;
transform
:
CardTransform
;
}
/*
* 返回卡片元数据
*
...
...
src/
ui/Duel/simpleDuel/config
.ts
→
src/
config/ui
.ts
View file @
f334f373
File moved
src/reducers/duel/handsSlice.ts
View file @
f334f373
...
...
@@ -6,10 +6,11 @@ import {
}
from
"
@reduxjs/toolkit
"
;
import
{
DuelState
}
from
"
./mod
"
;
import
{
RootState
}
from
"
../../store
"
;
import
{
CardMeta
,
fetchCard
}
from
"
../../api/cards
"
;
import
{
Card
,
fetchCard
}
from
"
../../api/cards
"
;
import
*
as
UICONFIG
from
"
../../config/ui
"
;
export
interface
Hands
{
cards
:
Card
Meta
[];
cards
:
Card
[];
}
// 自己增加手牌
...
...
@@ -18,13 +19,16 @@ export const meAddHandsImpl: CaseReducer<DuelState, PayloadAction<number[]>> = (
action
)
=>
{
const
cards
=
action
.
payload
.
map
((
id
)
=>
{
return
{
id
,
data
:
{},
text
:
{}
};
return
{
meta
:
{
id
,
data
:
{},
text
:
{}
},
transform
:
{}
};
});
if
(
state
.
meHands
)
{
state
.
meHands
.
cards
=
state
.
meHands
.
cards
.
concat
(
cards
);
}
else
{
state
.
meHands
=
{
cards
};
}
setHandsTransform
(
state
.
meHands
.
cards
);
};
// 对手增加手牌
...
...
@@ -33,7 +37,7 @@ export const opAddHandsImpl: CaseReducer<DuelState, PayloadAction<number[]>> = (
action
)
=>
{
const
cards
=
action
.
payload
.
map
((
id
)
=>
{
return
{
id
,
data
:
{},
text
:
{}
};
return
{
meta
:
{
id
,
data
:
{},
text
:
{}
},
transform
:
{}
};
});
if
(
state
.
opHands
)
{
state
.
opHands
.
cards
=
state
.
opHands
.
cards
.
concat
(
cards
);
...
...
@@ -56,15 +60,47 @@ export const fetchMeHandsMeta = createAsyncThunk(
export
const
meHandsCase
=
(
builder
:
ActionReducerMapBuilder
<
DuelState
>
)
=>
{
builder
.
addCase
(
fetchMeHandsMeta
.
fulfilled
,
(
state
,
action
)
=>
{
// TODO: 合法性校验
const
cards
=
action
.
payload
;
const
cardMetas
=
action
.
payload
;
if
(
state
.
meHands
)
{
state
.
meHands
.
cards
=
cards
;
for
(
let
meta
of
cardMetas
)
{
for
(
let
hand
of
state
.
meHands
.
cards
)
{
if
(
hand
.
meta
.
id
===
meta
.
id
)
{
hand
.
meta
=
meta
;
}
}
}
}
else
{
state
.
meHands
=
{
cards
};
state
.
meHands
=
{
cards
:
cardMetas
.
map
((
meta
)
=>
{
return
{
meta
,
transform
:
{}
};
}),
};
setHandsTransform
(
state
.
meHands
.
cards
);
}
});
};
// 更新手牌的位置和旋转信息
function
setHandsTransform
(
hands
:
Card
[]):
void
{
const
groundShape
=
UICONFIG
.
GroundShape
();
const
handShape
=
UICONFIG
.
HandShape
();
const
gap
=
groundShape
.
width
/
(
hands
.
length
-
1
);
const
left
=
-
(
groundShape
.
width
/
2
);
hands
.
forEach
((
hand
,
idx
,
_
)
=>
{
hand
.
transform
.
position
=
{
x
:
left
+
gap
*
idx
,
y
:
handShape
.
height
/
2
,
z
:
-
(
groundShape
.
height
/
2
)
-
1
,
};
const
rotation
=
UICONFIG
.
HandRotation
();
hand
.
transform
.
rotation
=
{
x
:
rotation
.
x
,
y
:
rotation
.
y
,
z
:
rotation
.
z
};
});
}
export
const
selectMeHands
=
(
state
:
RootState
)
=>
state
.
duel
.
meHands
||
{
cards
:
[]
};
export
const
selectOpHands
=
(
state
:
RootState
)
=>
...
...
src/ui/Duel/duel.ts
View file @
f334f373
...
...
@@ -16,7 +16,7 @@
import
React
from
"
react
"
;
import
type
{
RootState
}
from
"
../../store
"
;
import
{
Card
Meta
}
from
"
../../api/cards
"
;
import
{
Card
}
from
"
../../api/cards
"
;
/*
* 通用的决斗界面抽象接口
...
...
@@ -26,7 +26,7 @@ export interface IDuelPlate {
// 渲染接口,返回一个React组件
render
():
React
.
ReactElement
;
// 注册手牌selector
registerHands
(
selector
:
TypeSelector
<
Card
Meta
[]
>
):
void
;
registerHands
(
selector
:
TypeSelector
<
Card
[]
>
):
void
;
}
export
interface
TypeSelector
<
T
>
{
...
...
src/ui/Duel/simpleDuel/cemetery.ts
View file @
f334f373
import
*
as
BABYLON
from
"
@babylonjs/core
"
;
import
*
as
CONFIG
from
"
.
/config
"
;
import
*
as
CONFIG
from
"
.
./../../config/ui
"
;
export
default
(
scene
:
BABYLON
.
Scene
)
=>
{
// 墓地
...
...
src/ui/Duel/simpleDuel/deck.ts
View file @
f334f373
import
*
as
BABYLON
from
"
@babylonjs/core
"
;
import
*
as
CONFIG
from
"
.
/config
"
;
import
*
as
CONFIG
from
"
.
./../../config/ui
"
;
export
default
(
scene
:
BABYLON
.
Scene
)
=>
{
// 卡组
...
...
src/ui/Duel/simpleDuel/exclusion.ts
View file @
f334f373
import
*
as
BABYLON
from
"
@babylonjs/core
"
;
import
*
as
CONFIG
from
"
.
/config
"
;
import
*
as
CONFIG
from
"
.
./../../config/ui
"
;
export
default
(
scene
:
BABYLON
.
Scene
)
=>
{
// 除外区
...
...
src/ui/Duel/simpleDuel/extraMonsters.ts
View file @
f334f373
import
*
as
BABYLON
from
"
@babylonjs/core
"
;
import
*
as
CONFIG
from
"
.
/config
"
;
import
*
as
CONFIG
from
"
.
./../../config/ui
"
;
export
default
(
scene
:
BABYLON
.
Scene
)
=>
{
const
xs
=
[
-
1.1
,
1
];
...
...
src/ui/Duel/simpleDuel/field.ts
View file @
f334f373
import
*
as
BABYLON
from
"
@babylonjs/core
"
;
import
*
as
CONFIG
from
"
.
/config
"
;
import
*
as
CONFIG
from
"
.
./../../config/ui
"
;
export
default
(
scene
:
BABYLON
.
Scene
)
=>
{
// 墓地
...
...
src/ui/Duel/simpleDuel/hands.ts
View file @
f334f373
import
*
as
BABYLON
from
"
@babylonjs/core
"
;
import
*
as
CONFIG
from
"
.
/config
"
;
import
{
Card
Meta
}
from
"
../../../api/cards
"
;
import
*
as
CONFIG
from
"
.
./../../config/ui
"
;
import
{
Card
}
from
"
../../../api/cards
"
;
export
default
(
hands
:
CardMeta
[],
scene
:
BABYLON
.
Scene
)
=>
{
const
groundShape
=
CONFIG
.
GroundShape
();
export
default
(
hands
:
Card
[],
scene
:
BABYLON
.
Scene
)
=>
{
const
handShape
=
CONFIG
.
HandShape
();
const
gap
=
groundShape
.
width
/
(
hands
.
length
-
1
);
const
left
=
-
(
groundShape
.
width
/
2
);
hands
.
forEach
((
item
,
idx
,
_
)
=>
{
const
hand
=
BABYLON
.
MeshBuilder
.
CreatePlane
(
`hand
${
idx
}
`
,
...
...
@@ -15,16 +12,20 @@ export default (hands: CardMeta[], scene: BABYLON.Scene) => {
);
// 位置
hand
.
position
=
new
BABYLON
.
Vector3
(
left
+
gap
*
idx
,
handShape
.
height
/
2
,
-
(
groundShape
.
height
/
2
)
-
1
item
.
transform
.
position
?.
x
,
item
.
transform
.
position
?.
y
,
item
.
transform
.
position
?.
z
);
hand
.
rotation
=
new
BABYLON
.
Vector3
(
item
.
transform
.
rotation
?.
x
,
item
.
transform
.
rotation
?.
y
,
item
.
transform
.
rotation
?.
z
);
hand
.
rotation
=
CONFIG
.
HandRotation
();
// 材质
const
handMaterial
=
new
BABYLON
.
StandardMaterial
(
"
handMaterial
"
,
scene
);
// 材质贴纸
handMaterial
.
diffuseTexture
=
new
BABYLON
.
Texture
(
`https://cdn02.moecube.com:444/images/ygopro-images-zh-CN/
${
item
.
id
}
.jpg`
,
`https://cdn02.moecube.com:444/images/ygopro-images-zh-CN/
${
item
.
meta
.
id
}
.jpg`
,
scene
);
hand
.
material
=
handMaterial
;
...
...
src/ui/Duel/simpleDuel/magics.ts
View file @
f334f373
import
*
as
BABYLON
from
"
@babylonjs/core
"
;
import
*
as
CONFIG
from
"
.
/config
"
;
import
*
as
CONFIG
from
"
.
./../../config/ui
"
;
export
default
(
scene
:
BABYLON
.
Scene
)
=>
{
const
left
=
-
2.15
;
...
...
src/ui/Duel/simpleDuel/mod.tsx
View file @
f334f373
...
...
@@ -16,13 +16,13 @@ import renderDeck from "./deck";
import
renderCemetery
from
"
./cemetery
"
;
import
renderExclusion
from
"
./exclusion
"
;
import
renderField
from
"
./field
"
;
import
*
as
CONFIG
from
"
.
/config
"
;
import
{
Card
Meta
}
from
"
../../../api/cards
"
;
import
*
as
CONFIG
from
"
.
./../../config/ui
"
;
import
{
Card
}
from
"
../../../api/cards
"
;
// CONFIG
export
default
class
SimpleDuelPlateImpl
implements
IDuelPlate
{
handsSelector
?:
TypeSelector
<
Card
Meta
[]
>
;
handsSelector
?:
TypeSelector
<
Card
[]
>
;
constructor
()
{}
...
...
@@ -110,10 +110,7 @@ export default class SimpleDuelPlateImpl implements IDuelPlate {
useEffect
(()
=>
{
// 监听状态变化,并实现动画
const
onHandsChange
=
(
prev_hands
:
CardMeta
[]
|
null
,
cur_hands
:
CardMeta
[]
)
=>
{
const
onHandsChange
=
(
prev_hands
:
Card
[]
|
null
,
cur_hands
:
Card
[])
=>
{
console
.
log
(
prev_hands
,
"
change to
"
,
cur_hands
);
};
...
...
@@ -136,7 +133,7 @@ export default class SimpleDuelPlateImpl implements IDuelPlate {
);
}
registerHands
(
selector
:
TypeSelector
<
Card
Meta
[]
>
):
void
{
registerHands
(
selector
:
TypeSelector
<
Card
[]
>
):
void
{
this
.
handsSelector
=
selector
;
}
}
src/ui/Duel/simpleDuel/monsters.ts
View file @
f334f373
import
*
as
BABYLON
from
"
@babylonjs/core
"
;
import
*
as
CONFIG
from
"
.
/config
"
;
import
*
as
CONFIG
from
"
.
./../../config/ui
"
;
export
default
(
scene
:
BABYLON
.
Scene
)
=>
{
const
left
=
-
2.15
;
...
...
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