Skip to content

Commit

Permalink
Feat!(Battlemap): Integration with Obsidian Leaflet removed (#204)
Browse files Browse the repository at this point in the history
This removed the feature of Leaflet integration. However, this feature has been broken.

BREAKING CHANGE: As this is a removal of an existing feature, this is technically a breaking change.

Signed-off-by: Sigrunixia <Scholarlysigrun@icloud.com>
  • Loading branch information
sigrunixia authored Aug 10, 2023
1 parent b711c38 commit ad30f98
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 183 deletions.
1 change: 0 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export interface InitiativeTrackerData {
initiative: string;
modifier: string;
sync: boolean;
leafletIntegration: boolean;
playerMarker: string;
monsterMarker: string;
state: InitiativeViewState;
Expand Down
33 changes: 7 additions & 26 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
Conditions,
CREATURE_TRACKER_VIEW,
DEFAULT_SETTINGS,
INTIATIVE_TRACKER_VIEW,
INITIATIVE_TRACKER_VIEW,
registerIcons
} from "./utils";

Expand Down Expand Up @@ -149,7 +149,7 @@ export default class InitiativeTracker extends Plugin {
}
get view() {
const leaves = this.app.workspace.getLeavesOfType(
INTIATIVE_TRACKER_VIEW
INITIATIVE_TRACKER_VIEW
);
const leaf = leaves?.length ? leaves[0] : null;
if (leaf && leaf.view && leaf.view instanceof TrackerView)
Expand Down Expand Up @@ -203,7 +203,7 @@ export default class InitiativeTracker extends Plugin {
this.addSettingTab(new InitiativeTrackerSettings(this));

this.registerView(
INTIATIVE_TRACKER_VIEW,
INITIATIVE_TRACKER_VIEW,
(leaf: WorkspaceLeaf) => new TrackerView(leaf, this)
);
this.registerView(
Expand Down Expand Up @@ -494,7 +494,7 @@ export default class InitiativeTracker extends Plugin {
await this.saveSettings();
this.app.workspace.trigger("initiative-tracker:unload");
this.app.workspace
.getLeavesOfType(INTIATIVE_TRACKER_VIEW)
.getLeavesOfType(INITIATIVE_TRACKER_VIEW)
.forEach((leaf) => leaf.detach());
this.app.workspace
.getLeavesOfType(CREATURE_TRACKER_VIEW)
Expand All @@ -504,12 +504,12 @@ export default class InitiativeTracker extends Plugin {

async addTrackerView() {
if (
this.app.workspace.getLeavesOfType(INTIATIVE_TRACKER_VIEW)?.length
this.app.workspace.getLeavesOfType(INITIATIVE_TRACKER_VIEW)?.length
) {
return;
}
await this.app.workspace.getRightLeaf(false).setViewState({
type: INTIATIVE_TRACKER_VIEW
type: INITIATIVE_TRACKER_VIEW
});
}
get builder() {
Expand Down Expand Up @@ -580,15 +580,6 @@ export default class InitiativeTracker extends Plugin {
);

this.data = data;
if (
this.data.leafletIntegration &&
!this.data.players.every((p) => p.marker)
) {
this.data.players = this.data.players.map((p) => {
p.marker = p.marker ?? this.data.playerMarker;
return p;
});
}
if (this.data.statuses?.some((c) => !c.id)) {
for (const condition of this.data.statuses) {
condition.id =
Expand All @@ -605,16 +596,6 @@ export default class InitiativeTracker extends Plugin {
}

async saveSettings() {
if (
this.data.leafletIntegration &&
!this.data.players.every((p) => p.marker)
) {
this.data.players = this.data.players.map((p) => {
p.marker = p.marker ?? this.data.playerMarker;
return p;
});
}

await this.saveData(this.data);
tracker.setData(this.data);
}
Expand All @@ -636,7 +617,7 @@ export default class InitiativeTracker extends Plugin {
if (this.data.builder.sidebarIcon) {
this._builderIcon = this.addRibbonIcon(
BUILDER_VIEW,
"Intiative Tracker Encounter Builder",
"Initiative Tracker Encounter Builder",
() => {
this.addBuilderView();
}
Expand Down
106 changes: 1 addition & 105 deletions src/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export default class InitiativeTrackerSettings extends PluginSettingTab {
new Setting(containerEl)
.setName("Display Beginner Tips")
.setDesc(
"Display instructions in the intiative tracker, helping you get used to the workflow."
"Display instructions in the initiative tracker, helping you get used to the workflow."
)
.addToggle((t) => {
t.setValue(this.plugin.data.beginnerTips).onChange(
Expand Down Expand Up @@ -1034,110 +1034,6 @@ export default class InitiativeTrackerSettings extends PluginSettingTab {
await this.plugin.saveSettings();
};
});
new Setting(containerEl)
.setName("Integrate with Obsidian Leaflet")
.setDesc(
createFragment((e) => {
e.createSpan({
text: "Integrate with the Obsidian Leaflet plugin and display combats on a map."
});

if (!this.plugin.canUseLeaflet) {
e.createEl("br");
e.createEl("br");
e.createSpan({
attr: {
style: `color: var(--text-error);`
},
text: "Requires "
});
e.createEl("a", {
text: "Obsidian Leaflet",
href: "https://github.com/valentine195/obsidian-leaflet-plugin",
cls: "external-link"
});
e.createSpan({
attr: {
style: `color: var(--text-error);`
},
text: " version 4.0.0 to modify."
});
}
})
)
.addToggle((t) => {
if (!this.plugin.canUseLeaflet) {
t.setDisabled(true);
this.plugin.data.leafletIntegration = false;
}
t.setValue(this.plugin.data.leafletIntegration);
t.onChange(async (v) => {
this.plugin.data.leafletIntegration = v;
await this.plugin.saveSettings();
this._displayIntegrations(containerEl);
});
});

if (this.plugin.canUseLeaflet && this.plugin.data.leafletIntegration) {
new Setting(containerEl)
.setName("Default Player Marker Type")
.setDesc(
createFragment((e) => {
if (this.plugin.data.playerMarker) {
const div = e.createDiv("marker-type-display");
const inner = div.createDiv("marker-icon-display");

const marker = this.plugin.leaflet.markerIcons.find(
(icon) =>
icon.type == this.plugin.data.playerMarker
);
if (marker) {
inner.innerHTML = marker.html;
}
}
})
)
.addDropdown((drop) => {
for (let marker of this.plugin.leaflet.markerIcons) {
drop.addOption(marker.type, marker.type);
}
drop.setValue(this.plugin.data.playerMarker ?? "default");
drop.onChange(async (v) => {
this.plugin.data.playerMarker = v;
await this.plugin.saveSettings();
this._displayIntegrations(containerEl);
});
});
new Setting(containerEl)
.setName("Default Monster Marker Type")
.setDesc(
createFragment((e) => {
if (this.plugin.data.monsterMarker) {
const div = e.createDiv("marker-type-display");
const inner = div.createDiv("marker-icon-display");

const marker = this.plugin.leaflet.markerIcons.find(
(icon) =>
icon.type == this.plugin.data.monsterMarker
);
if (marker) {
inner.innerHTML = marker.html;
}
}
})
)
.addDropdown((drop) => {
for (let marker of this.plugin.leaflet.markerIcons) {
drop.addOption(marker.type, marker.type);
}
drop.setValue(this.plugin.data.monsterMarker);
drop.onChange(async (v) => {
this.plugin.data.monsterMarker = v;
await this.plugin.saveSettings();
this._displayIntegrations(containerEl);
});
});
}
}
}

Expand Down
8 changes: 0 additions & 8 deletions src/tracker/ui/Controls.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,6 @@
})
.setDisabled(Object.keys(plugin.data.encounters).length == 0);
});
if ($data.leafletIntegration) {
menu.addSeparator();
menu.addItem((item) => {
item.setIcon(MAP)
.setTitle("Open Leaflet Map")
.onClick(() => dispatch("open-map"));
});
}
menu.showAtMouseEvent(evt);
};
Expand Down
23 changes: 0 additions & 23 deletions src/tracker/ui/creatures/CreatureControls.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
ENABLE,
HIDDEN,
HP,
MAPMARKER,
REMOVE,
TAG
} from "src/utils";
Expand Down Expand Up @@ -99,28 +98,6 @@
});
});
}
if (plugin.data.leafletIntegration) {
menu.addItem((item) => {
item.setIcon(MAPMARKER)
.setTitle("Change Marker")
.onClick((evt: MouseEvent) => {
const markerMenu = new Menu();
markerMenu.setNoIcon();
for (let marker of plugin.leaflet.markerIcons) {
markerMenu.addItem((item) => {
item.setTitle(marker.type);
item.onClick(() => {
tracker.updateCreatures({
creature,
change: { marker: marker.type }
});
});
});
}
markerMenu.showAtMouseEvent(evt);
});
});
}
menu.addItem((item) => {
item.setIcon(REMOVE)
.setTitle("Remove")
Expand Down
9 changes: 3 additions & 6 deletions src/tracker/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
BASE,
CREATURE,
CREATURE_TRACKER_VIEW,
INTIATIVE_TRACKER_VIEW
INITIATIVE_TRACKER_VIEW
} from "../utils";

import type InitiativeTracker from "../main";
Expand Down Expand Up @@ -39,10 +39,9 @@ export default class TrackerView extends ItemView {
}
});
this.ui.$on("player-view", () => this.openPlayerView());
this.ui.$on("open-map", () => this.openInitiativeView());
}
getViewType() {
return INTIATIVE_TRACKER_VIEW;
return INITIATIVE_TRACKER_VIEW;
}
getDisplayText() {
return "Initiative Tracker";
Expand All @@ -58,9 +57,7 @@ export default class TrackerView extends ItemView {
get npcs(): Creature[] {
return [];
}
openInitiativeView() {
this.plugin.leaflet.openInitiativeView(this.pcs, this.npcs);
}


//open player view
playerViewOpened = false;
Expand Down
7 changes: 3 additions & 4 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { InitiativeTrackerData } from "index";
import { Platform } from "obsidian";
import { Conditions } from "./conditions";

export const INTIATIVE_TRACKER_VIEW = "initiative-tracker-view";
export const INITIATIVE_TRACKER_VIEW = "initiative-tracker-view";
export const PLAYER_VIEW_VIEW = "initiative-tracker-player-view";
export const CREATURE_TRACKER_VIEW = "initiative-tracker-creature-view";

Expand All @@ -24,7 +24,6 @@ export const DEFAULT_SETTINGS: InitiativeTrackerData = {
initiative: "1d20 + %mod%",
modifier: null,
sync: false,
leafletIntegration: false,
playerMarker: "default",
monsterMarker: "default",
state: {
Expand Down Expand Up @@ -61,7 +60,7 @@ export const DEFAULT_SETTINGS: InitiativeTrackerData = {
showParty: true,
showXP: true,
sidebarIcon: true
}
},
};


Expand All @@ -79,4 +78,4 @@ export const DECIMAL_TO_VULGAR_FRACTION: Record<string, string> = {
0.625: "⅝",
0.75: "¾",
0.875: "⅞",
} as const;
} as const;
10 changes: 0 additions & 10 deletions src/utils/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export function registerIcons() {
);

addIcon(BASE, ICON);

addIcon(SAVE, SAVE_ICON);
addIcon(ADD, ADD_ICON);
addIcon(RESTART, RESTART_ICON);
Expand All @@ -51,7 +50,6 @@ export function registerIcons() {
addIcon(NEW, NEW_ICON);
addIcon(DICE, DICE_ICON);
addIcon(START_ENCOUNTER, START_ENCOUNTER_ICON);
addIcon(MAP, MAP_ICON);
addIcon(COPY, COPY_ICON);
addIcon(
GROUP,
Expand All @@ -65,10 +63,6 @@ export function registerIcons() {
ACTIVE,
`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="angle-right" class="svg-inline--fa fa-angle-right fa-w-8" role="img" viewBox="0 0 256 512"><path fill="currentColor" d="M224.3 273l-136 136c-9.4 9.4-24.6 9.4-33.9 0l-22.6-22.6c-9.4-9.4-9.4-24.6 0-33.9l96.4-96.4-96.4-96.4c-9.4-9.4-9.4-24.6 0-33.9L54.3 103c9.4-9.4 24.6-9.4 33.9 0l136 136c9.5 9.4 9.5 24.6.1 34z"/></svg>`
);
addIcon(
MAPMARKER,
`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="map-marker-alt" class="svg-inline--fa fa-map-marker-alt fa-w-12" role="img" viewBox="0 0 384 512"><path fill="currentColor" d="M172.268 501.67C26.97 291.031 0 269.413 0 192 0 85.961 85.961 0 192 0s192 85.961 192 192c0 77.413-26.97 99.031-172.268 309.67-9.535 13.774-29.93 13.773-39.464 0zM192 272c44.183 0 80-35.817 80-80s-35.817-80-80-80-80 35.817-80 80 35.817 80 80 80z"/></svg>`
);
addIcon(
CREATURE,
`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="dragon" class="svg-inline--fa fa-dragon fa-w-20" role="img" viewBox="0 0 640 512"><path fill="currentColor" d="M18.32 255.78L192 223.96l-91.28 68.69c-10.08 10.08-2.94 27.31 11.31 27.31h222.7c-9.44-26.4-14.73-54.47-14.73-83.38v-42.27l-119.73-87.6c-23.82-15.88-55.29-14.01-77.06 4.59L5.81 227.64c-12.38 10.33-3.45 30.42 12.51 28.14zm556.87 34.1l-100.66-50.31A47.992 47.992 0 0 1 448 196.65v-36.69h64l28.09 22.63c6 6 14.14 9.37 22.63 9.37h30.97a32 32 0 0 0 28.62-17.69l14.31-28.62a32.005 32.005 0 0 0-3.02-33.51l-74.53-99.38C553.02 4.7 543.54 0 533.47 0H296.02c-7.13 0-10.7 8.57-5.66 13.61L352 63.96 292.42 88.8c-5.9 2.95-5.9 11.36 0 14.31L352 127.96v108.62c0 72.08 36.03 139.39 96 179.38-195.59 6.81-344.56 41.01-434.1 60.91C5.78 478.67 0 485.88 0 494.2 0 504 7.95 512 17.76 512h499.08c63.29.01 119.61-47.56 122.99-110.76 2.52-47.28-22.73-90.4-64.64-111.36zM489.18 66.25l45.65 11.41c-2.75 10.91-12.47 18.89-24.13 18.26-12.96-.71-25.85-12.53-21.52-29.67z"/></svg>`
Expand All @@ -84,7 +78,6 @@ export function registerIcons() {
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-arrow-down-a-z"><path d="m3 16 4 4 4-4"></path><path d="M7 20V4"></path><path d="M20 8h-5"></path><path d="M15 10V6.5a2.5 2.5 0 0 1 5 0V10"></path><path d="M15 14h5l-5 6h5"></path></svg>`
);
}
export const MAPMARKER = "tracker-map-marker";
export const EXPAND = "expand-creatures";
export const GROUP = "group-creatures";
export const ACTIVE = "initiative-tracker-active";
Expand All @@ -97,9 +90,6 @@ export const SORT_NUMBER = "ARROW_DOWN_0-1";
export const BASE = "initiative-tracker";
const ICON = `<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="dice-d20" class="svg-inline--fa fa-dice-d20 fa-w-15" role="img" viewBox="0 0 480 512"><path fill="currentColor" d="M106.75 215.06L1.2 370.95c-3.08 5 .1 11.5 5.93 12.14l208.26 22.07-108.64-190.1zM7.41 315.43L82.7 193.08 6.06 147.1c-2.67-1.6-6.06.32-6.06 3.43v162.81c0 4.03 5.29 5.53 7.41 2.09zM18.25 423.6l194.4 87.66c5.3 2.45 11.35-1.43 11.35-7.26v-65.67l-203.55-22.3c-4.45-.5-6.23 5.59-2.2 7.57zm81.22-257.78L179.4 22.88c4.34-7.06-3.59-15.25-10.78-11.14L17.81 110.35c-2.47 1.62-2.39 5.26.13 6.78l81.53 48.69zM240 176h109.21L253.63 7.62C250.5 2.54 245.25 0 240 0s-10.5 2.54-13.63 7.62L130.79 176H240zm233.94-28.9l-76.64 45.99 75.29 122.35c2.11 3.44 7.41 1.94 7.41-2.1V150.53c0-3.11-3.39-5.03-6.06-3.43zm-93.41 18.72l81.53-48.7c2.53-1.52 2.6-5.16.13-6.78l-150.81-98.6c-7.19-4.11-15.12 4.08-10.78 11.14l79.93 142.94zm79.02 250.21L256 438.32v65.67c0 5.84 6.05 9.71 11.35 7.26l194.4-87.66c4.03-1.97 2.25-8.06-2.2-7.56zm-86.3-200.97l-108.63 190.1 208.26-22.07c5.83-.65 9.01-7.14 5.93-12.14L373.25 215.06zM240 208H139.57L240 383.75 340.43 208H240z"/></svg>`;

export const MAP = "initiative-tracker-map";
const MAP_ICON = `<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="map-marked-alt" class="svg-inline--fa fa-map-marked-alt fa-w-18" role="img" viewBox="0 0 576 512"><path fill="currentColor" d="M288 0c-69.59 0-126 56.41-126 126 0 56.26 82.35 158.8 113.9 196.02 6.39 7.54 17.82 7.54 24.2 0C331.65 284.8 414 182.26 414 126 414 56.41 357.59 0 288 0zm0 168c-23.2 0-42-18.8-42-42s18.8-42 42-42 42 18.8 42 42-18.8 42-42 42zM20.12 215.95A32.006 32.006 0 0 0 0 245.66v250.32c0 11.32 11.43 19.06 21.94 14.86L160 448V214.92c-8.84-15.98-16.07-31.54-21.25-46.42L20.12 215.95zM288 359.67c-14.07 0-27.38-6.18-36.51-16.96-19.66-23.2-40.57-49.62-59.49-76.72v182l192 64V266c-18.92 27.09-39.82 53.52-59.49 76.72-9.13 10.77-22.44 16.95-36.51 16.95zm266.06-198.51L416 224v288l139.88-55.95A31.996 31.996 0 0 0 576 426.34V176.02c0-11.32-11.43-19.06-21.94-14.86z"/></svg>`;

export const START_ENCOUNTER = "crossed-swords";
const START_ENCOUNTER_ICON =
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024"><path fill="currentColor" d="M27.43 918.8l30.374-30.374 80.793 80.793-30.374 30.374L27.43 918.8zm422.393-253.815c0-48.521-39.36-87.882-87.882-87.882s-87.88 39.36-87.88 87.88c0 48.521 39.338 87.859 87.882 87.882s87.902-39.338 87.88-87.88zm-175.351 8.401l-.807-.807-166.337 166.336 80.794 80.794 166.337-166.337-.92-.92c-41.832-3.986-75.099-37.253-79.067-79.065zm-.411-8.402c0-45.507 34.621-82.952 78.95-87.431-46.731-53.121-88.214-110.883-123.852-172.613L117.593 516.506 274.47 673.383a88.927 88.927 0 0 1-.409-8.399zm175.315 8.962c-4.472 44.334-41.914 78.942-87.433 78.92a89.137 89.137 0 0 1-8.406-.413l157.058 157.058 111.566-111.566c-62.063-35.842-119.841-77.405-172.785-123.999zM815.497 74.632L392.493 497.636c6.535 9.622 10.729 21.41 10.729 33.817 0 19.234-9.188 36.441-23.375 47.483 34.711 7.191 61.918 34.869 68.453 69.814 11.013-14.625 28.5-24.14 48.078-24.14 12.407 0 23.51 3.51 32.978 9.891l423.002-423.002 29.691-166.555-166.553 29.688zM41.964 872.58l112.539 112.539 49.514-49.514L91.478 823.066 41.964 872.58z"/></svg>';
Expand Down

0 comments on commit ad30f98

Please sign in to comment.