forked from MotocalDevelopers/motocal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Critical Buff (old PR MotocalDevelopers#245) and Sun-Touched Para…
…side (MotocalDevelopers#250) * Add Critical Buff and Sun-Touched Paraside Recreate Branch. 'cuz whoopsie. - Add Sun-Touched Paraside (烈日の楽園), Alanaan (アラナン). * Fix missing curly bracket * various - remove redundant code in global.js and a missing semicolon - identitation in profile.js - jp text for 烈日の楽園説明 * Update global_logic.js missed one line deletion * Update global_logic.js Fix backward compatibility * remove state change in render() and, - correct some indentations. - correct mismatched text (translate) - minor logic change (reduce cases) * correct usage of event handlers. * Update global_logic.js * Add CriticalBuffList component This component will reduce 3 clone codes in profile, chara Added optional Count change behavior, truncate=false option that does not truncate array when count was changed. `trancate=false` and set `initialCount` can keep modified array but only "count" length available. - Usage storybook -> components -> CriticaBuffList - properties - criticalArray (required) - label (default: criticalBuff) ... used for key prefix - maxCount (default: 20) - truncate (default: true) - initialCount (default: 0) - onBlur - onCountChange * Add missing changes for previous commit, my git operation mistake. * Remove unnecessary code They were already moved to CriticalListBuff component * Update global_logic.js * Update global_logic.js - correct damageUP (shiva's passive/etc) * Update global_logic.js + * Update translate.js - add missing translation
- Loading branch information
1 parent
de98d27
commit 5af0a40
Showing
8 changed files
with
345 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
"use strict"; | ||
|
||
const React = require('react'); | ||
const {FormControl, InputGroup} = require('react-bootstrap'); | ||
const intl = require('./translate.js'); | ||
const {selector} = require('./global_const.js'); | ||
|
||
|
||
/** | ||
* Dynamic List component for Critical Buff inputs | ||
*/ | ||
class CriticalBuffList extends React.Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
count: props.initialCount || props.criticalArray.length, | ||
array: props.criticalArray | ||
}; | ||
} | ||
|
||
/** | ||
* Notify event | ||
* | ||
* @param {number} count | ||
*/ | ||
handleOnCountChange(count) { | ||
if (this.props.onCountChange) { | ||
this.props.onCountChange(count); | ||
} | ||
} | ||
|
||
/** | ||
* Notify event | ||
* | ||
* @param {string} key ... UNUSED | ||
* @param {Object} e ... Event object | ||
*/ | ||
handleOnBlur(key, e){ | ||
console.log(this, key, e) | ||
if (this.props.onBlur) { | ||
this.props.onBlur(e); | ||
} | ||
} | ||
|
||
/** | ||
* @param {string} key | ||
* @param {number} idx | ||
* @param {Object} e ... Event object | ||
* | ||
* when key is "count": | ||
* Change array's size if needed. | ||
* | ||
* when key is "value" or "attackRatio": | ||
* update value | ||
* | ||
*/ | ||
handleOnChange(key, idx, e) { | ||
let array = this.props.criticalArray; | ||
|
||
if (key === "count") { | ||
const count = e.target.value; | ||
|
||
while (count > array.length) { | ||
array.push({value: 0.0, attackRatio: 0.0}); | ||
} | ||
if (array.length > count && this.props.truncate) { | ||
array.length = count; | ||
} | ||
|
||
this.setState({count: count, array: array}); | ||
this.handleOnCountChange(count); | ||
} else if (key === "value" || key === "attackRatio") { | ||
const val = parseInt(e.target.value); | ||
|
||
array[idx][key] = val / 100; | ||
|
||
this.setState({array: array}); | ||
} | ||
} | ||
|
||
/** | ||
* Render Count form and list of Value/AttackRatio forms | ||
* | ||
* @return {ReactElement} | ||
*/ | ||
render() { | ||
const {state: {count, array}, props: {locale, label, maxCount}} = this; | ||
|
||
return <React.Fragment> | ||
<strong>{intl.translate("数", locale)}</strong> | ||
<FormControl type="number" | ||
min="0" max={maxCount} value={count} | ||
onBlur={this.handleOnBlur.bind(this)} | ||
onChange={this.handleOnChange.bind(this, "count", null)}/> | ||
{array.slice(0, count).map(({value,attackRatio}, idx) => | ||
<div key={label + idx}> | ||
<strong>{intl.translate("発動率", locale)}#{idx+1}</strong> | ||
<InputGroup> | ||
<FormControl | ||
componentClass="select" | ||
value={Math.round(100*value)} | ||
onBlur={this.handleOnBlur.bind(this)} | ||
onChange={this.handleOnChange.bind(this, "value", idx)}> | ||
{selector.criticalRateLevel} | ||
</FormControl> | ||
<InputGroup.Addon>%</InputGroup.Addon> | ||
</InputGroup> | ||
<strong>{intl.translate("倍率", locale)}#{idx+1}</strong> | ||
<InputGroup> | ||
<FormControl | ||
componentClass="select" | ||
value={Math.round(100*attackRatio)} | ||
onBlur={this.handleOnBlur.bind(this)} | ||
onChange={this.handleOnChange.bind(this, "attackRatio", idx)}> | ||
{selector.buffLevel} | ||
</FormControl> | ||
<InputGroup.Addon>%</InputGroup.Addon> | ||
</InputGroup> | ||
</div>)} | ||
</React.Fragment>; | ||
} | ||
} | ||
|
||
CriticalBuffList.defaultProps = { | ||
maxCount: 20, | ||
initialCount: 0, | ||
truncate: true, | ||
label: "criticalBuff", | ||
}; | ||
|
||
|
||
module.exports.CriticalBuffList = CriticalBuffList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.