diff --git a/android/app/src/debug/AndroidManifest.xml b/android/app/src/debug/AndroidManifest.xml index 4b185bc1597eb762051660198c02074bf82ab974..2f0fa58e42c76b5b45666c2887d43cc0e0a480bd 100644 --- a/android/app/src/debug/AndroidManifest.xml +++ b/android/app/src/debug/AndroidManifest.xml @@ -2,7 +2,11 @@ - + + + + + + + { - const {opponentID} = this.state; + const {opponent} = this.state; if (true) { //this.props.navigation.navigate('双人PK结算'); - this.props.navigation.navigate('双人PK中', {opponentID: opponentID}); - this.setState({isStarted: false, opponentID: 0}); + this.props.navigation.navigate('双人PK中', {opponent: opponent}); + this.setState({isStarted: false, opponent: null}); clearInterval(this.timer); } }; @@ -36,7 +36,7 @@ class TwoPlayerPKHome extends Component { cancelSearching = () => { clearInterval(this.timer); - this.setState({isStarted: false, opponentID: 0}); + this.setState({isStarted: false, opponent: null}); }; render() { diff --git a/component/OnlineStudy/2-PlayerPKStudy/index.js b/component/OnlineStudy/2-PlayerPKStudy/index.js index 11221e0eb6b0507f55c430e12301e34f2dec750a..bf6deb13e0f60100bdd6e63ccb752af83f112391 100644 --- a/component/OnlineStudy/2-PlayerPKStudy/index.js +++ b/component/OnlineStudy/2-PlayerPKStudy/index.js @@ -5,6 +5,7 @@ import MyTitle from '../MyTitle'; import SettingButton from '../SettingButton'; import MyBanner from '../MyBanner'; import TwoPlayerPKState from '../2-PlayerPKState'; +import {parseMinute, parseTime} from '../MyUtilities'; const {width, height} = Dimensions.get('window'); /** @@ -25,11 +26,21 @@ class TwoPlayerPKStudy extends Component { } state = { - opponentID: undefined, + user: { + name: 'username', + rank: 'error', + duration: -1, + }, + opponent: { + id: undefined, + name: 'opponent', + rank: 'error', + duration: -1, + }, victories: 0, isStarted: false, - timeInAGame: 0, - timeInAMatch: 999, + timeInTheGame: 0, + timeInTheMatch: 999, }; componentDidMount() { @@ -48,8 +59,8 @@ class TwoPlayerPKStudy extends Component { this.forceUpdate(); }); // 以下不是标语风格切换相关 - if (typeof params.opponentID !== 'undefined') { - this.setState({opponentID: params.opponentID, isStarted: true}); + if (params.opponent !== undefined && params.opponent !== null) { + this.setState({opponent: params.opponent, isStarted: true}); } this.startTimer(); } @@ -60,21 +71,11 @@ class TwoPlayerPKStudy extends Component { clearInterval(this.timer); } - parseTime = time => { - const minute = parseInt(time / 60, 10); - const second = time % 60; - return minute.toString() + ':' + second.toString(); - }; - - parseMinute = time => { - return parseInt(time / 60, 10).toString(); - }; - calculateTime = () => { - const {timeInAGame, timeInAMatch} = this.state; + const {timeInTheGame, timeInTheMatch} = this.state; this.setState({ - timeInAGame: timeInAGame + 1, - timeInAMatch: timeInAMatch + 1, + timeInTheGame: timeInTheGame + 1, + timeInTheMatch: timeInTheMatch + 1, }); }; @@ -97,7 +98,7 @@ class TwoPlayerPKStudy extends Component { //console.log('OK Pressed'); clearInterval(this.timer); this.props.navigation.navigate('双人PK结算', { - numberTop: parseInt(this.state.timeInAMatch / 60, 10), + numberTop: parseInt(this.state.timeInTheMatch / 60, 10), numberCentre: 999, numberBottom: 9999, }); @@ -107,7 +108,14 @@ class TwoPlayerPKStudy extends Component { }; render() { - const {victories, isStarted, timeInAGame, timeInAMatch} = this.state; + const { + user, + opponent, + victories, + isStarted, + timeInTheGame, + timeInTheMatch, + } = this.state; return ( @@ -120,25 +128,25 @@ class TwoPlayerPKStudy extends Component { text={{ first: { top: '用户', - bottom: 'name', + bottom: user.name, }, second: { top: '段位', - bottom: '黄金', + bottom: user.rank, }, third: { top: '本次时长', - bottom: this.parseMinute(timeInAMatch) + ' min', + bottom: parseMinute(timeInTheMatch) + ' min', }, forth: { top: '生涯时长', - bottom: '1' + ' min', + bottom: parseMinute(timeInTheMatch) + user.duration + ' min', }, }} /> - - {this.parseTime(timeInAMatch)} - + {parseTime(timeInTheMatch)} { return; @@ -38,7 +40,7 @@ class RangePKHome extends Component { state = { isStarted: false, isLocated: false, - rangeID: undefined, + rangeID: 'notLocated', // 初始rangeID longitude: undefined, latitude: undefined, }; @@ -52,12 +54,11 @@ class RangePKHome extends Component { // const error = {code: 100, message: 'Locating request is aborted.'}; // return reject(error); // }); - Geolocation.getCurrentPosition( location => { const longitude = location.coords.longitude; //经度 const latitude = location.coords.latitude; //纬度 - const rangeID = this.parseLocation(longitude, latitude); + const rangeID = parseLocation(longitude, latitude); // this.setState({isStarted: false, isLocated: true, rangeID: rangID}); this.setState({ isStarted: false, @@ -87,7 +88,7 @@ class RangePKHome extends Component { { enableHighAccuracy: true, timeout: 5000, - maximumAge: 10000, + maximumAge: 50, }, ); }); @@ -107,11 +108,6 @@ class RangePKHome extends Component { } }; - parseLocation = (longitude, latitude) => { - console.log('longitude: ' + longitude + ' latitude: ' + latitude); - return 'x1'; - }; - startLocating = () => { // // eslint-disable-next-line no-undef // this.abortController = new AbortController(); @@ -119,50 +115,33 @@ class RangePKHome extends Component { this.geoLocate().then(r => {}); }; - cancelLocating = () => { - // if (this.abortController) { - // this.abortController.abort(); - // this.abortController = null; - // } - // this.setState({isStarted: false}); - }; + // cancelLocating = () => { + // if (this.abortController) { + // this.abortController.abort(); + // this.abortController = null; + // } + // this.setState({isStarted: false}); + // }; startStudy = () => { //this.props.navigation.navigate(''); this.props.navigation.navigate('区域PK中', {rangeID: this.state.rangeID}); }; - parseRangeID = () => { - let {rangeID} = this.state; - // console.log('parseRangeID rangID: ' + rangeID); - switch (rangeID) { - case undefined: - rangeID = '未定位'; - break; - case 'x1': - rangeID = '西1'; - break; - default: - rangeID = 'Error'; - break; - } - return rangeID; - }; - render() { - const {isStarted, isLocated} = this.state; + const {isStarted, isLocated, rangeID} = this.state; return ( - 当前所在区域:{this.parseRangeID()} + 当前所在区域:{parseRangeID(rangeID)} {isStarted ? ( ) : ( )} { - const minute = parseInt(time / 60, 10); - const second = time % 60; - return minute.toString() + ':' + second.toString(); - }; - - parseMinute = time => { - return parseInt(time / 60, 10).toString(); - }; - calculateTime = () => { - const {timeInAGame, timeInAMatch} = this.state; + const {timeInAGame, timeInTheMatch} = this.state; this.setState({ timeInAGame: timeInAGame + 1, - timeInAMatch: timeInAMatch + 1, + timeInTheMatch: timeInTheMatch + 1, }); }; @@ -89,22 +98,6 @@ class RangePKStudy extends Component { }, 1000); }; - parseRangeID = () => { - let {rangeID} = this.state; - switch (rangeID) { - case 'undefined': - rangeID = '未定位'; - break; - case 'x1': - rangeID = '西1'; - break; - default: - rangeID = 'Error'; - break; - } - return rangeID; - }; - openRankingList = () => { this.props.navigation.navigate('区域排行榜'); }; @@ -144,10 +137,10 @@ class RangePKStudy extends Component { //console.log('OK Pressed'); clearInterval(this.timer); this.props.navigation.navigate('区域PK结算', { - numberTop: parseInt(this.state.timeInAMatch / 60, 10), + numberTop: parseInt(this.state.timeInTheMatch / 60, 10), numberCentre: 999, numberBottom: 9999, - range: this.parseRangeID(), + range: parseRangeID(this.state.rangeID), }); }, }, @@ -155,7 +148,14 @@ class RangePKStudy extends Component { }; render() { - const {ranking, timeInAMatch} = this.state; + const { + user, + ranking, + timeInTheMatch, + rankingFirst, + rankingSecond, + rankingThird, + } = this.state; return ( @@ -168,23 +168,23 @@ class RangePKStudy extends Component { text={{ first: { top: '用户', - bottom: 'name', + bottom: user.name, }, second: { top: '段位', - bottom: '黄金', + bottom: user.rank, }, third: { top: '本次时长', - bottom: this.parseMinute(timeInAMatch) + ' min', + bottom: parseMinute(timeInTheMatch) + ' min', }, forth: { top: '生涯时长', - bottom: '1' + ' min', + bottom: parseMinute(timeInTheMatch) + user.duration + ' min', }, }} /> - + {'<--'}左滑打开排行榜 - {this.parseTime(timeInAMatch)} + {parseTime(timeInTheMatch)}