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
e5a7247c
Commit
e5a7247c
authored
Apr 08, 2023
by
timel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: make a config module
parent
a12d47ba
Pipeline
#21149
failed with stages
in 14 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
114 additions
and
7 deletions
+114
-7
src/config/automation.ts
src/config/automation.ts
+31
-0
src/config/defaults.ts
src/config/defaults.ts
+37
-0
src/config/env.ts
src/config/env.ts
+20
-0
src/config/index.ts
src/config/index.ts
+9
-0
src/hook/index.ts
src/hook/index.ts
+0
-1
src/ui/Login.tsx
src/ui/Login.tsx
+5
-2
src/ui/Mora.tsx
src/ui/Mora.tsx
+6
-2
src/ui/WaitRoom.tsx
src/ui/WaitRoom.tsx
+6
-2
No files found.
src/config/automation.ts
0 → 100644
View file @
e5a7247c
import
{
useEnv
}
from
"
../hook
"
;
const
{
DEV
,
VITE_IS_AI_MODE
,
VITE_IS_AI_FIRST
}
=
useEnv
();
interface
AutomationConfig
{
isAiMode
:
boolean
;
isAiFirst
:
boolean
;
}
const
defaultConfig
:
AutomationConfig
=
{
isAiMode
:
false
,
isAiFirst
:
false
,
};
const
aiModeConfig
:
AutomationConfig
=
{
isAiMode
:
true
,
isAiFirst
:
VITE_IS_AI_FIRST
,
};
const
genAutomationConfig
=
()
=>
{
if
(
DEV
)
{
if
(
VITE_IS_AI_MODE
)
{
return
aiModeConfig
;
}
// 待拓展
}
return
defaultConfig
;
};
export
const
automationConfig
:
AutomationConfig
=
genAutomationConfig
();
src/
hook/useConfig
.ts
→
src/
config/defaults
.ts
View file @
e5a7247c
/*
* 旨在跳过登录界面,直接进入游戏(和AI对战、后续可能增加自动的PVP)。
* 仅在开发环境下生效,便于开发者快速调节决斗界面。
*/
import
{
useEnv
}
from
"
.
"
;
import
{
useEnv
}
from
"
../hook
"
;
const
{
DEV
,
VITE_IS_AI_MODE
,
VITE_IS_AI_FIRST
,
VITE_AI_MODE_DEFAULT_DECK
}
=
useEnv
();
const
{
DEV
,
VITE_IS_AI_MODE
,
VITE_AI_MODE_DEFAULT_DECK
}
=
useEnv
();
interface
Prepare
Config
{
interface
Defaults
Config
{
defaultPlayer
:
string
;
defaultDeck
:
string
;
defaultPassword
:
string
;
defaultMora
:
string
;
isAiMode
:
boolean
;
isAiFirst
:
boolean
;
}
const
autoModeConfig
:
Prepare
Config
=
{
const
defaultConfig
:
Defaults
Config
=
{
defaultPlayer
:
""
,
// 无需考虑undefined的情况,如果为undefined,界面上会显示【请选择】
defaultDeck
:
VITE_AI_MODE_DEFAULT_DECK
,
defaultPassword
:
""
,
defaultMora
:
"
scissors
"
,
isAiMode
:
false
,
isAiFirst
:
false
,
};
const
aiModeConfig
:
Prepare
Config
=
{
...
autoMode
Config
,
const
aiModeConfig
:
Defaults
Config
=
{
...
default
Config
,
defaultPlayer
:
`AiKiller
${
Math
.
random
().
toString
(
36
).
slice
(
2
)}
}`
,
defaultPassword
:
"
AI
"
,
isAiMode
:
true
,
isAiFirst
:
VITE_IS_AI_FIRST
,
};
export
function
useConfig
():
PrepareConfig
{
const
genDefaultsConfig
=
()
=>
{
if
(
DEV
)
{
if
(
VITE_IS_AI_MODE
)
{
return
aiModeConfig
;
...
...
@@ -42,5 +31,7 @@ export function useConfig(): PrepareConfig {
// 待拓展
}
return
autoModeConfig
;
}
return
defaultConfig
;
};
export
const
defaultsConfig
:
DefaultsConfig
=
genDefaultsConfig
();
src/config/env.ts
0 → 100644
View file @
e5a7247c
import
{
useEnv
}
from
"
../hook
"
;
import
NeosDevConfig
from
"
../../neos.config.json
"
;
import
NeosProdConfig
from
"
../../neos.config.prod.json
"
;
const
{
DEV
}
=
useEnv
();
type
Equal
<
X
,
Y
>
=
(
<
T
>
()
=>
T
extends
X
?
1
:
2
)
extends
<
T
>
()
=>
T
extends
Y
?
1
:
2
?
true
:
false
;
type
Expect
<
T
extends
true
>
=
T
;
/**
* 确保两个json文件的结构一致,不一致会报错
*/
type
_
=
Expect
<
Equal
<
typeof
NeosDevConfig
,
typeof
NeosProdConfig
>>
;
export
const
envConfig
=
DEV
?
NeosDevConfig
:
NeosProdConfig
;
src/config/index.ts
0 → 100644
View file @
e5a7247c
import
{
automationConfig
}
from
"
./automation
"
;
import
{
defaultsConfig
}
from
"
./defaults
"
;
import
{
envConfig
}
from
"
./env
"
;
export
const
useConfig
=
()
=>
({
automation
:
automationConfig
,
defaults
:
defaultsConfig
,
...
envConfig
,
}
satisfies
Record
<
string
,
unknown
>
);
src/hook/index.ts
View file @
e5a7247c
export
*
from
"
./useApp
"
;
export
*
from
"
./useEnv
"
;
export
*
from
"
./useConfig
"
;
src/ui/Login.tsx
View file @
e5a7247c
...
...
@@ -11,10 +11,13 @@ import React, { useState, ChangeEvent, useEffect } from "react";
import
{
useNavigate
}
from
"
react-router-dom
"
;
import
"
../styles/core.scss
"
;
import
NeosConfig
from
"
../../neos.config.json
"
;
import
{
useConfig
}
from
"
../
hook
"
;
import
{
useConfig
}
from
"
../
config
"
;
const
serverConfig
=
NeosConfig
.
servers
;
const
{
isAiMode
,
defaultPlayer
,
defaultPassword
}
=
useConfig
();
const
{
defaults
:
{
defaultPlayer
,
defaultPassword
},
automation
:
{
isAiMode
},
}
=
useConfig
();
export
default
function
Login
()
{
const
[
player
,
setPlayer
]
=
useState
(
defaultPlayer
);
...
...
src/ui/Mora.tsx
View file @
e5a7247c
import
React
from
"
react
"
;
import
{
sendHandResult
,
sendTpResult
}
from
"
../api/ocgcore/ocgHelper
"
;
import
{
useAppSelector
,
useConfig
}
from
"
../hook
"
;
import
{
useAppSelector
}
from
"
../hook
"
;
import
{
useConfig
}
from
"
../config
"
;
import
{
selectHandSelectAble
,
unSelectHandAble
,
...
...
@@ -18,7 +19,10 @@ import {
TableOutlined
,
}
from
"
@ant-design/icons
"
;
const
{
isAiMode
,
isAiFirst
,
defaultMora
}
=
useConfig
();
const
{
automation
:
{
isAiMode
,
isAiFirst
},
defaults
:
{
defaultMora
},
}
=
useConfig
();
const
Mora
=
()
=>
{
const
dispatch
=
store
.
dispatch
;
...
...
src/ui/WaitRoom.tsx
View file @
e5a7247c
...
...
@@ -19,7 +19,8 @@ import {
selectPlayer0
,
selectPlayer1
,
}
from
"
../reducers/playerSlice
"
;
import
{
useAppSelector
,
useConfig
}
from
"
../hook
"
;
import
{
useAppSelector
}
from
"
../hook
"
;
import
{
useConfig
}
from
"
../config
"
;
import
{
selectJoined
}
from
"
../reducers/joinSlice
"
;
import
{
selectChat
}
from
"
../reducers/chatSlice
"
;
import
{
fetchDeck
,
type
IDeck
,
DeckManager
}
from
"
../api/deck
"
;
...
...
@@ -48,7 +49,10 @@ import { initStrings } from "../api/strings";
const
READY_STATE
=
"
ready
"
;
const
{
isAiMode
,
defaultDeck
}
=
useConfig
();
const
{
defaults
:
{
defaultDeck
},
automation
:
{
isAiMode
},
}
=
useConfig
();
const
WaitRoom
=
()
=>
{
const
params
=
useParams
<
{
...
...
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