/*** @jsx React.DOM */ var valid_sorts = ['series', 'name', 'popularity']; var valid_charts = ['Novice', 'Advanced', 'Exhaust', 'Infinite', 'Maximum']; var valid_mixes = Object.keys(window.versions); var valid_subsorts = [valid_mixes, false, false, valid_charts, valid_charts]; if (window.showpersonalsort) { valid_sorts.push('grade'); valid_sorts.push('clear'); } var pagenav = new History(valid_sorts, valid_subsorts); var sort_names = { 'series': 'Series', 'name': 'Song Name', 'popularity': 'Popularity', 'grade': 'Score', 'clear': 'Clear Type', }; var HighScore = createReactClass({ render: function() { if (!this.props.score) { return null; } has_stats = ( this.props.score.stats.critical > 0 || this.props.score.stats.near > 0 || this.props.score.stats.error > 0 ); return (
{this.props.score.grade} Score {this.props.score.points} Combo {this.props.score.combo < 0 ? '-' : this.props.score.combo}
{has_stats ?
{this.props.score.stats.critical} / {this.props.score.stats.near} / {this.props.score.stats.error}
: null}
{this.props.score.clear_type}
{ this.props.score.userid && window.shownames ?
{ this.props.players[this.props.score.userid].name }
: null }
); }, }); var network_records = createReactClass({ sortRecords: function(records) { var sorted_records = {}; records.forEach(function(record) { if (!(record.songid in sorted_records)) { sorted_records[record.songid] = {} } sorted_records[record.songid][record.chart] = record; }); return sorted_records; }, getInitialState: function(props) { return { songs: window.songs, records: this.sortRecords(window.records), players: window.players, versions: window.versions, sort: pagenav.getInitialState('series', '0'), subtab: this.getSubIndex('series', pagenav.getInitialSubState('series', '0')), offset: 0, limit: 10, }; }, getSubIndex: function(sort, subsort) { var subtab = 0; window.valid_sorts.forEach(function(potential, index) { if (window.valid_subsorts[index]) { window.valid_subsorts[index].forEach(function(subpotential, subindex) { if (subpotential == subsort) { subtab = subindex; } }.bind(this)); } }.bind(this)); return subtab; }, componentDidMount: function() { pagenav.onChange(function(sort, subsort) { var subtab = this.getSubIndex(sort, subsort); this.setState({sort: sort, offset: 0, subtab: subtab}); }.bind(this)); this.refreshRecords(); }, refreshRecords: function() { AJAX.get( Link.get('refresh'), function(response) { this.setState({ records: this.sortRecords(response.records), players: response.players, }); // Refresh every 15 seconds setTimeout(this.refreshRecords, 15000); }.bind(this) ); }, renderDifficulty: function(songid, chart) { if (this.state.songs[songid].difficulties[chart] == 0) { return --; } else { return {this.state.songs[songid].difficulties[chart]}; } }, getPlays: function(record) { if (!record) { return 0; } var plays = 0; for (var i = 0; i < 4; i++) { if (record[i]) { plays += record[i].plays; } } return plays; }, renderBySeries: function() { var songids = Object.keys(this.state.songs).sort(function(a, b) { var ac = this.state.songs[a].category; var bc = this.state.songs[b].category; return parseInt(bc) - parseInt(ac); }.bind(this)); if (window.filterempty) { songids = songids.filter(function(songid) { return this.getPlays(this.state.records[songid]) > 0; }.bind(this)); } var lastSeries = 0; for (var i = 0; i < songids.length; i++) { var curSeries = parseInt(this.state.songs[songids[i]].category) + 1; if (curSeries != lastSeries) { lastSeries = curSeries; songids.splice(i, 0, -curSeries); } } if (songids.length == 0) { return (
No records to display!
); } var paginate = false; var curpage = -1; var curbutton = -1; if (songids.length > 99) { // Arbitrary limit for perf reasons paginate = true; } return ( <> { paginate ?
{songids.map(function(songid) { if (songid < 0) { curbutton = curbutton + 1; var subtab = curbutton; return (
: null }
{songids.map(function(songid) { if (songid < 0) { // This is a series header curpage = curpage + 1; if (paginate && curpage != this.state.subtab) { return null; } return ( ); } else { if (paginate && curpage != this.state.subtab) { return null; } var records = this.state.records[songid]; if (!records) { records = {}; } var difficulties = this.state.songs[songid].difficulties; return ( ); } }.bind(this))}
{ !paginate ? this.state.versions[(-songid) - 1] : "Song / Artist / Difficulties" } Novice Advanced Exhaust Infinite Maximum
{this.renderDifficulty(songid, 0)} / {this.renderDifficulty(songid, 1)} / {this.renderDifficulty(songid, 2)} / {this.renderDifficulty(songid, 3)} / {this.renderDifficulty(songid, 4)}
0 ? "" : "nochart"}> 0 ? "" : "nochart"}> 0 ? "" : "nochart"}> 0 ? "" : "nochart"}> 0 ? "" : "nochart"}>
); }, renderByName: function() { var songids = Object.keys(this.state.songs).sort(function(a, b) { var an = this.state.songs[a].name; var bn = this.state.songs[b].name; var c = an.localeCompare(bn); if (c == 0) { return parseInt(a) - parseInt(b) } else { return c; } }.bind(this)); if (window.filterempty) { songids = songids.filter(function(songid) { return this.getPlays(this.state.records[songid]) > 0; }.bind(this)); } return this.renderBySongIDList(songids, false); }, renderByPopularity: function() { var songids = Object.keys(this.state.songs).sort(function(a, b) { var ap = this.getPlays(this.state.records[a]); var bp = this.getPlays(this.state.records[b]); if (bp == ap) { return parseInt(a) - parseInt(b) } else { return bp - ap; } }.bind(this)); if (window.filterempty) { songids = songids.filter(function(songid) { return this.getPlays(this.state.records[songid]) > 0; }.bind(this)); } return this.renderBySongIDList(songids, true); }, renderByScore: function() { var songids = Object.keys(this.state.songs).sort(function(a, b) { // Grab records for this song var ar = this.state.records[a]; var br = this.state.records[b]; var ac = null; var bc = null; var as = 0; var bs = 0; // Fill in record for current chart only if it exists if (ar) { ac = ar[this.state.subtab]; } if (br) { bc = br[this.state.subtab]; } if (ac) { as = ac.points; } if (bc) { bs = bc.points; } if (bs == as) { return parseInt(a) - parseInt(b); } else { return bs - as; } }.bind(this)); if (window.filterempty) { songids = songids.filter(function(songid) { return this.getPlays(this.state.records[songid]) > 0; }.bind(this)); } return ( <>
{window.valid_charts.map(function(chartname, index) { return (
{ this.renderBySongIDList(songids, false) } ); }, renderByClearType: function() { var songids = Object.keys(this.state.songs).sort(function(a, b) { // Grab records for this song var ar = this.state.records[a]; var br = this.state.records[b]; var ac = null; var bc = null; var al = 0; var bl = 0; // Fill in record for current chart only if it exists if (ar) { ac = ar[this.state.subtab]; } if (br) { bc = br[this.state.subtab]; } if (ac) { al = ac.medal; } if (bc) { bl = bc.medal; } if (al == bl) { return parseInt(a) - parseInt(b) } else { return bl - al; } }.bind(this)); if (window.filterempty) { songids = songids.filter(function(songid) { return this.getPlays(this.state.records[songid]) > 0; }.bind(this)); } return ( <>
{window.valid_charts.map(function(chartname, index) { return (
{ this.renderBySongIDList(songids, false) } ); }, renderBySongIDList: function(songids, showplays) { return (
{songids.map(function(songid, index) { if (index < this.state.offset || index >= this.state.offset + this.state.limit) { return null; } var records = this.state.records[songid]; if (!records) { records = {}; } var plays = this.getPlays(records); var difficulties = this.state.songs[songid].difficulties; return ( ); }.bind(this))}
Song / Artist / Difficulties Novice Advanced Exhaust Infinite Maximum
{this.renderDifficulty(songid, 0)} / {this.renderDifficulty(songid, 1)} / {this.renderDifficulty(songid, 2)} / {this.renderDifficulty(songid, 3)} / {this.renderDifficulty(songid, 4)}
{ showplays ?
#{index + 1} - {plays}{plays == 1 ? ' play' : ' plays'}
: null }
0 ? "" : "nochart"}> 0 ? "" : "nochart"}> 0 ? "" : "nochart"}> 0 ? "" : "nochart"}> 0 ? "" : "nochart"}>
{ this.state.offset > 0 ? : null } { (this.state.offset + this.state.limit) < songids.length ? = songids.length) { return } this.setState({offset: page}); }.bind(this)}/> : null }
); }, render: function() { var data = null; if (this.state.sort == 'series') { data = this.renderBySeries(); } else if (this.state.sort == 'popularity') { data = this.renderByPopularity(); } else if (this.state.sort == 'name') { data = this.renderByName(); } else if (this.state.sort == 'grade') { data = this.renderByScore(); } else if (this.state.sort == 'clear') { data = this.renderByClearType(); } return (
{ window.valid_sorts.map(function(sort, index) { return (
{data}
); }, }); ReactDOM.render( React.createElement(network_records, null), document.getElementById('content') );