@@ -2,9 +2,36 @@ import { state as meta3dState, getContribute as getContributeMeta3D, api } from
22// import { language } from "meta3d-action-mod-unit-add-careerfeature-protocol"
33import { actionContribute , service as editorWholeService } from "meta3d-editor-whole-protocol/src/service/ServiceType"
44import { actionName , state , uiData } from "meta3d-action-mod-unit-publish-to-game-protocol"
5+ import { actionName as initActionName , state as initState } from "meta3d-action-mod-unit-init-protocol"
56import { eventName , inputData } from "meta3d-action-mod-unit-publish-to-game-protocol/src/EventType"
6- import { publish } from "meta3d-action-mod-unit-publish-utils/src/Main"
7+ import { publish , getUserName , checkModData , buildUniqueName } from "meta3d-action-mod-unit-publish-utils/src/Main"
8+ import { getLanguageTextData , isChinese } from "meta3d-language-utils/src/Main"
9+ import { languageKey } from "meta3d-language-utils/src/Type"
710
11+ let _checkPublishData = ( api : api , meta3dState : meta3dState , { displayNameCN, displayNameEN, description, modIconBase64 } : initState , isChinese : boolean ) => {
12+ let message = api . nullable . getEmpty < string > ( )
13+
14+ if ( isChinese && displayNameCN . length <= 0 ) {
15+ message = api . nullable . return ( getLanguageTextData ( api , meta3dState , languageKey . NeedDisplayNameCN ) )
16+ }
17+ else if ( ! isChinese && displayNameEN . length <= 0 ) {
18+ message = api . nullable . return ( getLanguageTextData ( api , meta3dState , languageKey . NeedDisplayNameEN ) )
19+ }
20+ else if ( description . length <= 0 ) {
21+ message = api . nullable . return ( getLanguageTextData ( api , meta3dState , languageKey . NeedDescription ) )
22+ }
23+ else if ( api . nullable . isNullable ( modIconBase64 ) ) {
24+ message = api . nullable . return ( getLanguageTextData ( api , meta3dState , languageKey . NeedModIcon ) )
25+ }
26+
27+ return api . nullable . getWithDefault (
28+ api . nullable . map ( ( message ) => {
29+ api . message . warn ( message )
30+ return true
31+ } , message ) ,
32+ false
33+ )
34+ }
835
936export let getContribute : getContributeMeta3D < actionContribute < uiData , state > > = ( api ) => {
1037 return {
@@ -16,41 +43,36 @@ export let getContribute: getContributeMeta3D<actionContribute<uiData, state>> =
1643
1744 return new Promise ( ( resolve , reject ) => {
1845 resolve ( eventSourcingService . on < inputData > ( meta3dState , eventName , 0 , ( meta3dState ) => {
19- // let characterType_ = api.action.getActionState<selectCharacterTypeState>(meta3dState, selectCharacterTypeActionName).characterType
20- // let features = api.action.getActionState<addCareerFeatureState>(meta3dState, addCareerFeatureActionName).allSelectedCareerFeatureData.filter(d => {
21- // return _isCharacterTypeEqual(d.characterType, characterType_)
22- // })
23-
24- // let assetIconBase64 = api.nullable.getWithDefault(
25- // api.action.getActionState<loadModPreviewState>(meta3dState, loadModPreviewActionName).preview,
26- // ""
27- // )
28- // let careerIconBase64 = api.nullable.getWithDefault(
29- // api.action.getActionState<loadCareerPreviewState>(meta3dState, loadCareerPreviewActionName).preview,
30- // ""
31- // )
46+ console . log ( "publish mod" )
3247
33- // let isChinese = api.action.getActionState<languageState>(meta3dState, languageActionName).language == language.Chinese
48+ if ( _checkPublishData ( api , meta3dState , api . action . getActionState < initState > ( meta3dState , initActionName ) , isChinese ( api , meta3dState ) )
49+ || checkModData ( api , [ getLanguageTextData , languageKey ] , meta3dState , api . action . getActionState < initState > ( meta3dState , initActionName ) )
50+ ) {
51+ return Promise . resolve ( meta3dState )
52+ }
3453
35- // if (_check(api, api.action.getActionState<state>(meta3dState, actionName), isChinese, features)) {
36- // return Promise.resolve(meta3dState)
37- // }
54+ api . flow . deferExec ( api , ( meta3dState ) => {
55+ let initState = api . action . getActionState < initState > ( meta3dState , initActionName )
3856
39- console . log ( "publish mod" )
4057
58+ let author = getUserName ( api )
59+ return publish ( api ,
60+ meta3dState ,
61+ buildUniqueName ( author , initState . displayNameCN , initState . displayNameEN , isChinese ( api , meta3dState ) ) ,
62+ author ,
63+ initState . displayNameCN ,
64+ initState . displayNameEN ,
65+ initState . description ,
66+ initState . isPublic ,
67+ api . nullable . getExn ( initState . modIconBase64 )
68+ ) . then ( meta3dState => {
69+ meta3dState = api . action . setActionState < initState > ( meta3dState , initActionName , {
70+ ...api . action . getActionState < initState > ( meta3dState , initActionName ) ,
71+ isShowPublishModal : false
72+ } )
4173
42- // meta3dState = api.action.setActionState<state>(meta3dState, actionName, {
43- // ...api.action.getActionState<state>(meta3dState, actionName),
44- // isShowModal: false
45- // })
46- // meta3dState = api.action.setActionState<infoState>(meta3dState, infoActionName, {
47- // ...api.action.getActionState<infoState>(meta3dState, infoActionName),
48- // info: isChinese ? api.nullable.return("正在发布中...") : api.nullable.return("Publishing...")
49- // })
50- api . flow . deferExec ( api , ( meta3dState ) => {
51- let author = "Official"
52- let name = `unit-test1`
53- return publish ( api , meta3dState , name , author )
74+ return meta3dState
75+ } )
5476 } )
5577
5678 return Promise . resolve ( meta3dState )
0 commit comments