Skip to content

Commit

Permalink
Import .dmvbrew/.orcbrew, export .dmvbrew
Browse files Browse the repository at this point in the history
  • Loading branch information
marloso2 committed Dec 1, 2019
1 parent 1cd50c0 commit 95d9424
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/cljs/orcpub/dnd/e5/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3127,7 +3127,7 @@
(let [blob (js/Blob.
(clj->js [(str plugin)])
(clj->js {:type "text/plain;charset=utf-8"}))]
(js/saveAs blob (str name ".orcbrew"))
(js/saveAs blob (str name ".dmvbrew"))
{})))

(reg-event-fx
Expand All @@ -3136,7 +3136,7 @@
(let [blob (js/Blob.
(clj->js [(str @(subscribe [::e5/plugins]))])
(clj->js {:type "text/plain;charset=utf-8"}))]
(js/saveAs blob (str "all-content.orcbrew"))
(js/saveAs blob (str "all-content.dmvbrew"))
{})))

(reg-event-fx
Expand All @@ -3145,15 +3145,15 @@
(let [blob (js/Blob.
(clj->js [(with-out-str (pprint/pprint plugin))])
(clj->js {:type "text/plain;charset=utf-8"}))]
(js/saveAs blob (str name ".orcbrew"))
(js/saveAs blob (str name ".dmvbrew"))
{})))
(reg-event-fx
::e5/export-all-plugins-pretty-print
(fn [_ _]
(let [blob (js/Blob.
(clj->js [(with-out-str (pprint/pprint @(subscribe [::e5/plugins])))])
(clj->js {:type "text/plain;charset=utf-8"}))]
(js/saveAs blob (str "all-content.orcbrew"))
(js/saveAs blob (str "all-content.dmvbrew"))
{})))

(reg-event-fx
Expand Down Expand Up @@ -3197,7 +3197,7 @@
(spec/explain-data ::e5/plugins plugin))
(prn "INVALID PLUGIN FILE"
(spec/explain-data ::e5/plugin plugin))
{:dispatch [:show-error-message "Invalid .orcbrew file"]})))))
{:dispatch [:show-error-message "Invalid .orcbrew/.dmvbrew file"]})))))

(reg-event-db
::spells/set-spell
Expand Down
28 changes: 18 additions & 10 deletions src/cljs/orcpub/dnd/e5/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6982,15 +6982,23 @@
(defn import-file [e]
(let [reader (js/FileReader.)
file (.. e -target -files (item 0))
filename (.-name file)
nm (first (s/split filename #".orcbrew"))]
(.addEventListener
reader
"load"
(fn [e]
(let [text (.. e -target -result)]
(dispatch [::e5/import-plugin nm text]))))
(.readAsText reader file)))
filename (.-name file)]
(if (s/includes? filename ".orcbrew") (let [nm (first (s/split filename (or #".orcbrew")))]
(.addEventListener
reader
"load"
(fn [e]
(let [text (.. e -target -result)]
(dispatch [::e5/import-plugin nm text]))))
(.readAsText reader file))
(let [nm (first (s/split filename (or #".dmvbrew")))]
(.addEventListener
reader
"load"
(fn [e]
(let [text (.. e -target -result)]
(dispatch [::e5/import-plugin nm text]))))
(.readAsText reader file)))))

(defn capitalize-words
[s]
Expand Down Expand Up @@ -7253,7 +7261,7 @@
[:div.p-20.bg-lighter.main-text-color.m-b-10.m-l-10.m-r-10.b-rad-5
[:div.f-w-b.f-s-24.m-b-5 "Import Option Source"]
[:input {:type "file"
:accept ".orcbrew"
:accept [".orcbrew", ".dmvbrew"]
:on-change import-file}]]
[my-content]]])

Expand Down

0 comments on commit 95d9424

Please sign in to comment.