Skip to content

Commit

Permalink
feat: Add colorful dice setting and default colors for standard rpg d…
Browse files Browse the repository at this point in the history
…ice (#228)
  • Loading branch information
AlexBieg authored Jul 15, 2023
1 parent 329dec9 commit 4ff934a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ interface DiceRollerSettings {
renderer: boolean;
renderAllDice: boolean;
renderTime: number;
colorfulDice: boolean,
diceColor: string;
textColor: string;
showLeafOnStartup: boolean;
Expand All @@ -177,6 +178,7 @@ export const DEFAULT_SETTINGS: DiceRollerSettings = {
renderer: false,
renderAllDice: false,
renderTime: 2000,
colorfulDice: false,
diceColor: "#202020",
textColor: "#ffffff",
showLeafOnStartup: true,
Expand Down
15 changes: 15 additions & 0 deletions src/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,21 @@ export default class SettingTab extends PluginSettingTab {
});
});

new Setting(containerEl)
.setName("Use Colorful Dice")
.setDesc("Rendered dice will be varied colors based on the dice type. This will override manually set dice and text colors.")
.addToggle((t) => {
t.setValue(this.plugin.data.colorfulDice);
t.onChange(async (v) => {
this.plugin.data.colorfulDice = v;
await this.plugin.saveSettings();

this.plugin.app.workspace.trigger(
"dice-roller:update-colors"
);
});
});

const diceColor = new Setting(containerEl)
.setName("Dice Base Color")
.setDesc("Rendered dice will be this color.");
Expand Down
14 changes: 11 additions & 3 deletions src/view/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -760,10 +760,18 @@ class LocalWorld {
class DiceFactory extends Component {
dice: Record<string, DiceGeometry> = {};
get colors() {
const diceColor = this.plugin.data.diceColor;
const textColor = this.plugin.data.textColor;

// If we want colorful dice then just use the default colors in the geometry
if (this.plugin.data.colorfulDice) {
return undefined
}

return {
diceColor: this.plugin.data.diceColor,
textColor: this.plugin.data.textColor
};
diceColor,
textColor,
}
}
constructor(
public width: number,
Expand Down
18 changes: 14 additions & 4 deletions src/view/renderer/geometries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ class D20DiceGeometry extends DiceGeometry {

mass = 400;

constructor(w: number, h: number, options = DEFAULT_DICE_OPTIONS) {
constructor(w: number, h: number, options = { diceColor: "#171120", textColor: "#FF0000"}) {
super(w, h, options);

let t = (1 + Math.sqrt(5)) / 2;
Expand Down Expand Up @@ -495,7 +495,7 @@ class D12DiceGeometry extends DiceGeometry {
scaleFactor = 0.9;
values = [...Array(12).keys()];
margin = 1;
constructor(w: number, h: number, options = DEFAULT_DICE_OPTIONS) {
constructor(w: number, h: number, options = { diceColor: "#7339BE", textColor: "#FFFFFF" }) {
super(w, h, options);

let p = (1 + Math.sqrt(5)) / 2;
Expand Down Expand Up @@ -557,7 +557,7 @@ class D10DiceGeometry extends DiceGeometry {
scaleFactor = 0.9;
values = [...Array(10).keys()];
margin = 1;
constructor(w: number, h: number, options = DEFAULT_DICE_OPTIONS) {
constructor(w: number, h: number, options = { diceColor: "#c74749", textColor: "#FFFFFF" }) {
super(w, h, options);
for (let i = 0, b = 0; i < 10; ++i, b += (Math.PI * 2) / 10) {
this.vertices.push([
Expand Down Expand Up @@ -603,7 +603,7 @@ class D100DiceGeometry extends DiceGeometry {
scaleFactor = 0.9;
values = [...Array(10).keys()];
margin = 1;
constructor(w: number, h: number, options = DEFAULT_DICE_OPTIONS) {
constructor(w: number, h: number, options = { diceColor: "#7a2c2d", textColor: "#FFFFFF" }) {
super(w, h, options);
for (let i = 0, b = 0; i < 10; ++i, b += (Math.PI * 2) / 10) {
this.vertices.push([
Expand Down Expand Up @@ -644,6 +644,9 @@ class D8DiceGeometry extends DiceGeometry {
scaleFactor = 1;
values = [...Array(8).keys()];
margin = 1.2;
constructor(w: number, h: number, options = { diceColor: "#5eb0c5", textColor: "#FFFFFF" }) {
super(w, h, options);
}
}

class D6DiceGeometry extends DiceGeometry {
Expand Down Expand Up @@ -673,6 +676,9 @@ class D6DiceGeometry extends DiceGeometry {
sides = 6;
margin = 1.0;
values = [...Array(6).keys()];
constructor(w: number, h: number, options = { diceColor: "#d68316", textColor: "#FFFFFF" }) {
super(w, h, options);
}
}
class FudgeDiceGeometry extends DiceGeometry {
mass = 300;
Expand Down Expand Up @@ -732,6 +738,10 @@ class D4DiceGeometry extends DiceGeometry {
faceTexts = this.d4FaceTexts[0];
values = [...Array(4).keys()];

constructor(w: number, h: number, options = { diceColor: "#93b139", textColor: "#FFFFFF" }) {
super(w, h, options);
}

getMaterials() {
let materials: MeshPhongMaterial[] = [];
for (let i = 0; i < this.d4FaceTexts[0].length; ++i) {
Expand Down

0 comments on commit 4ff934a

Please sign in to comment.