mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 14:17:22 +01:00
refactor: move randomVal to a lib
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import handleTwoHanded from './handleTwoHanded';
|
||||
import predictableRandom from './predictableRandom';
|
||||
import crit from './crit';
|
||||
import randomVal from './randomVal';
|
||||
import randomDrop from './randomDrop';
|
||||
import autoAllocate from './autoAllocate';
|
||||
import updateStats from './updateStats';
|
||||
@@ -11,7 +10,6 @@ module.exports = {
|
||||
handleTwoHanded,
|
||||
predictableRandom,
|
||||
crit,
|
||||
randomVal,
|
||||
randomDrop,
|
||||
autoAllocate,
|
||||
updateStats,
|
||||
|
||||
@@ -3,7 +3,7 @@ import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
import { daysSince } from '../cron';
|
||||
import { diminishingReturns } from '../statHelpers';
|
||||
import randomVal from './randomVal';
|
||||
import randomVal from '../libs/randomVal';
|
||||
|
||||
// TODO This is only used on the server
|
||||
// move to user model as an instance method?
|
||||
|
||||
@@ -91,12 +91,14 @@ api.statsComputed = statsComputed;
|
||||
import shops from './libs/shops';
|
||||
api.shops = shops;
|
||||
|
||||
import randomVal from './libs/randomVal';
|
||||
api.randomVal = randomVal;
|
||||
|
||||
import autoAllocate from './fns/autoAllocate';
|
||||
import crit from './fns/crit';
|
||||
import handleTwoHanded from './fns/handleTwoHanded';
|
||||
import predictableRandom from './fns/predictableRandom';
|
||||
import randomDrop from './fns/randomDrop';
|
||||
import randomVal from './fns/randomVal';
|
||||
import resetGear from './fns/resetGear';
|
||||
import ultimateGear from './fns/ultimateGear';
|
||||
import updateStats from './fns/updateStats';
|
||||
@@ -107,7 +109,6 @@ api.fns = {
|
||||
handleTwoHanded,
|
||||
predictableRandom,
|
||||
randomDrop,
|
||||
randomVal,
|
||||
resetGear,
|
||||
ultimateGear,
|
||||
updateStats,
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
// Get a random property from an object
|
||||
// returns random property (the value)
|
||||
|
||||
function trueRandom () {
|
||||
return Math.random();
|
||||
}
|
||||
|
||||
// Get a random property from an object
|
||||
// returns random property (the value)
|
||||
module.exports = function randomVal (obj, options = {}) {
|
||||
let array = options.key ? _.keys(obj) : _.values(obj);
|
||||
let random = (options.predictableRandom || trueRandom)();
|
||||
@@ -6,7 +6,7 @@ import splitWhitespace from '../libs/splitWhitespace';
|
||||
import {
|
||||
NotAuthorized,
|
||||
} from '../libs/errors';
|
||||
import randomVal from '../fns/randomVal';
|
||||
import randomVal from '../libs/randomVal';
|
||||
|
||||
// TODO this is only used on the server
|
||||
// move out of common?
|
||||
|
||||
@@ -4,7 +4,7 @@ import _ from 'lodash';
|
||||
import {
|
||||
NotAuthorized,
|
||||
} from '../libs/errors';
|
||||
import randomVal from '../fns/randomVal';
|
||||
import randomVal from '../libs/randomVal';
|
||||
|
||||
// TODO this is only used on the server
|
||||
// move out of common?
|
||||
|
||||
Reference in New Issue
Block a user