Skip to content

Commit

Permalink
Advantage / Disadvantage rolls
Browse files Browse the repository at this point in the history
  • Loading branch information
jsavko committed Jul 29, 2022
1 parent 2a5b781 commit a393bdf
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 8 deletions.
8 changes: 8 additions & 0 deletions css/vagabonds.css
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,11 @@
.left {
text-align: left;
}

span.flavor-text h2 {
text-align: center;
}

span.flavor-text h1 {
text-align: center;
}
21 changes: 18 additions & 3 deletions dist/vagabonds.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/vagabonds.js.map

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions module/helper/roll_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@ export class RollHelper {
<option value="-3">-3</option>
</select>
</div>
<div class="form-group">
<div class="form-group">
<label>Defence Roll?</label>
<input type="checkbox" ` + defend + ` id="rolltype-defense" name="rolltype-defense" value="1"> Yes
</div>
<div class="form-group">
<label>Roll Type:</label>
<select id="roll-adv" name="roll-adv">
<option value="adv">Advantage</option>
<option value="normal" selected>Normal</option>
<option value="dis">Disadvantage</option>
</select>
</div>
</form>
`,
buttons: {
Expand All @@ -46,6 +54,7 @@ export class RollHelper {
if (confirmed) {
let rollModifier = parseInt(html.find('[name=modifier-value]')[0].value);
let rollisDefense= html.find(`[name=rolltype-defense]`).is(":checked");
let rollType =html.find('[name=roll-adv]')[0].value;
//let token = canvas.tokens.controlled;
let actor = game.user.character ?? canvas.tokens.controlled[0]?.actor ?? game.actors.find(a => a.owner);
//console.log(token);
Expand All @@ -55,10 +64,15 @@ export class RollHelper {
}
let roll;
let RollTemplate;
let baseRoll = "2d6";
console.log(rollType);
if (rollType == "adv") baseRoll = "3d6kh2"
if (rollType == "dis") baseRoll = "3d6kl2"

if (rollModifier >= 0) {
roll = new Roll("2d6 +" + rollModifier, actor.data);
roll = new Roll(baseRoll + " +" + rollModifier, actor.data);
} else {
roll = new Roll("2d6 " + rollModifier, actor.data);
roll = new Roll(baseRoll + rollModifier, actor.data);
}
roll.evaluate({async: true}).then(
function(result) {
Expand Down
49 changes: 49 additions & 0 deletions module/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
export class Logger {
static MODULE_ID = null;

static LOG_LEVEL = {
Debug: 0,
Log: 1,
Info: 2,
Warn: 3,
Error: 4
}

static log(force, logLevel, ...args) {
const shouldLog = force || game.modules.get('_dev-mode')?.api?.getPackageDebugValue(Logger.MODULE_ID);

if (shouldLog) {
switch (logLevel) {
case Logger.LOG_LEVEL.Error:
console.error(Logger.MODULE_ID, '|', ...args);
break;
case Logger.LOG_LEVEL.Warn:
console.warn(Logger.MODULE_ID, '|', ...args);
break;
case Logger.LOG_LEVEL.Info:
console.info(Logger.MODULE_ID, '|', ...args);
break;
case Logger.LOG_LEVEL.Debug:
default:
console.debug(Logger.MODULE_ID, '|', ...args);
break;
}
}
}

static error(force, ...args) {
Logger.log(force, Logger.LOG_LEVEL.Error, ...args);
}

static warn(force, ...args) {
Logger.log(force, Logger.LOG_LEVEL.Warn, ...args);
}

static info(force, ...args) {
Logger.log(force, Logger.LOG_LEVEL.Info, ...args);
}

static debug(force, ...args) {
Logger.log(force, Logger.LOG_LEVEL.Debug, ...args);
}
}

0 comments on commit a393bdf

Please sign in to comment.