@rpg-engine/long-bow 0.3.34 → 0.3.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ import { IRawSpell } from '@rpg-engine/shared';
2
+ import React from 'react';
3
+ export declare type QuickSpellsProps = {
4
+ quickSpells: IRawSpell[];
5
+ onSpellCast: (spellKey: string) => void;
6
+ mana: number;
7
+ isBlockedCastingByKeyboard?: boolean;
8
+ };
9
+ export declare const QuickSpells: React.FC<QuickSpellsProps>;
@@ -0,0 +1,11 @@
1
+ import { IRawSpell } from '@rpg-engine/shared';
2
+ import React from 'react';
3
+ interface Props extends IRawSpell {
4
+ charMana: number;
5
+ charMagicLevel: number;
6
+ onClick?: (spellKey: string) => void;
7
+ isSettingShortcut?: boolean;
8
+ spellKey: string;
9
+ }
10
+ export declare const Spell: React.FC<Props>;
11
+ export {};
@@ -0,0 +1,15 @@
1
+ import { IRawSpell } from '@rpg-engine/shared';
2
+ import React from 'react';
3
+ export interface ISpellbookProps {
4
+ onClose?: () => void;
5
+ onInputFocus?: () => void;
6
+ onInputBlur?: () => void;
7
+ spells: IRawSpell[];
8
+ magicLevel: number;
9
+ mana: number;
10
+ onSpellClick: (spellKey: string) => void;
11
+ setSpellShortcut: (key: string, index: number) => void;
12
+ spellShortcuts: IRawSpell[];
13
+ removeSpellShortcut: (index: number) => void;
14
+ }
15
+ export declare const Spellbook: React.FC<ISpellbookProps>;
@@ -0,0 +1,10 @@
1
+ import { IRawSpell } from '@rpg-engine/shared';
2
+ import React from 'react';
3
+ declare type Props = {
4
+ setSettingShortcutIndex: (index: number) => void;
5
+ settingShortcutIndex: number;
6
+ shortcuts: IRawSpell[];
7
+ removeShortcut: (index: number) => void;
8
+ };
9
+ export declare const SpellbookShortcuts: React.FC<Props>;
10
+ export {};
@@ -0,0 +1,3 @@
1
+ import { IRawSpell } from '@rpg-engine/shared';
2
+ export declare const SPELL_SHORTCUTS_STORAGE_KEY = "spellShortcuts";
3
+ export declare const defaultSpellShortcut: IRawSpell;
@@ -0,0 +1,2 @@
1
+ import { IRawSpell } from '@rpg-engine/shared';
2
+ export declare const mockSpells: IRawSpell[];
package/dist/index.d.ts CHANGED
@@ -29,6 +29,8 @@ export * from './components/RPGUIRoot';
29
29
  export * from './components/shared/SpriteFromAtlas';
30
30
  export * from './components/SkillProgressBar';
31
31
  export * from './components/SkillsContainer';
32
+ export * from './components/Spellbook/QuickSpells';
33
+ export * from './components/Spellbook/Spellbook';
32
34
  export * from './components/TextArea';
33
35
  export * from './components/TimeWidget/TimeWidget';
34
36
  export * from './components/TradingMenu/TradingMenu';
@@ -35427,6 +35427,240 @@ var CloseButton$3 = /*#__PURE__*/styled.div.withConfig({
35427
35427
  componentId: "sc-1g0c67q-2"
35428
35428
  })(["position:absolute;top:2px;right:2px;color:white;z-index:22;font-size:1.1rem;"]);
35429
35429
 
35430
+ var QuickSpells = function QuickSpells(_ref) {
35431
+ var quickSpells = _ref.quickSpells,
35432
+ onSpellCast = _ref.onSpellCast,
35433
+ mana = _ref.mana,
35434
+ _ref$isBlockedCasting = _ref.isBlockedCastingByKeyboard,
35435
+ isBlockedCastingByKeyboard = _ref$isBlockedCasting === void 0 ? false : _ref$isBlockedCasting;
35436
+ React.useEffect(function () {
35437
+ var handleKeyDown = function handleKeyDown(e) {
35438
+ if (isBlockedCastingByKeyboard) return;
35439
+ var shortcutIndex = Number(e.key) - 1;
35440
+ if (shortcutIndex >= 0 && shortcutIndex <= 3) {
35441
+ var shortcut = quickSpells[shortcutIndex];
35442
+ if (shortcut != null && shortcut.key && mana >= (shortcut == null ? void 0 : shortcut.manaCost)) {
35443
+ onSpellCast(shortcut.key);
35444
+ }
35445
+ }
35446
+ };
35447
+ window.addEventListener('keydown', handleKeyDown);
35448
+ return function () {
35449
+ window.removeEventListener('keydown', handleKeyDown);
35450
+ };
35451
+ }, [quickSpells, isBlockedCastingByKeyboard]);
35452
+ return React__default.createElement(List, null, Array.from({
35453
+ length: 4
35454
+ }).map(function (_, i) {
35455
+ var _quickSpells$i, _quickSpells$i2, _quickSpells$i3, _quickSpells$i4, _quickSpells$i5;
35456
+ return React__default.createElement(SpellShortcut, {
35457
+ key: i,
35458
+ onClick: onSpellCast.bind(null, (_quickSpells$i = quickSpells[i]) == null ? void 0 : _quickSpells$i.key),
35459
+ disabled: mana < ((_quickSpells$i2 = quickSpells[i]) == null ? void 0 : _quickSpells$i2.manaCost)
35460
+ }, React__default.createElement("span", {
35461
+ className: "mana"
35462
+ }, ((_quickSpells$i3 = quickSpells[i]) == null ? void 0 : _quickSpells$i3.key) && ((_quickSpells$i4 = quickSpells[i]) == null ? void 0 : _quickSpells$i4.manaCost)), React__default.createElement("span", {
35463
+ className: "magicWords"
35464
+ }, (_quickSpells$i5 = quickSpells[i]) == null ? void 0 : _quickSpells$i5.magicWords.split(' ').map(function (word) {
35465
+ return word[0];
35466
+ })), React__default.createElement("span", {
35467
+ className: "keyboard"
35468
+ }, i + 1));
35469
+ }));
35470
+ };
35471
+ var SpellShortcut = /*#__PURE__*/styled.button.withConfig({
35472
+ displayName: "QuickSpells__SpellShortcut",
35473
+ componentId: "sc-41yq7s-0"
35474
+ })(["width:3rem;height:3rem;background-color:", ";border:2px solid ", ";border-radius:50%;text-transform:uppercase;font-size:0.7rem;font-weight:bold;display:flex;align-items:center;justify-content:center;position:relative;.mana{position:absolute;top:-5px;right:0;font-size:0.65rem;color:", ";}.magicWords{margin-top:4px;}.keyboard{position:absolute;bottom:-5px;left:0;font-size:0.65rem;color:", ";}&:hover,&:focus{background-color:", ";}&:active{background-color:", ";}&:disabled{opacity:0.5;}"], uiColors.lightGray, uiColors.darkGray, uiColors.blue, uiColors.yellow, uiColors.darkGray, uiColors.gray);
35475
+ var List = /*#__PURE__*/styled.p.withConfig({
35476
+ displayName: "QuickSpells__List",
35477
+ componentId: "sc-41yq7s-1"
35478
+ })(["width:100%;display:flex;align-items:center;justify-content:center;gap:0.5rem;box-sizing:border-box;margin:0 !important;"]);
35479
+
35480
+ var Spell = function Spell(_ref) {
35481
+ var spellKey = _ref.spellKey,
35482
+ name = _ref.name,
35483
+ description = _ref.description,
35484
+ magicWords = _ref.magicWords,
35485
+ manaCost = _ref.manaCost,
35486
+ charMana = _ref.charMana,
35487
+ charMagicLevel = _ref.charMagicLevel,
35488
+ onClick = _ref.onClick,
35489
+ isSettingShortcut = _ref.isSettingShortcut,
35490
+ minMagicLevelRequired = _ref.minMagicLevelRequired;
35491
+ var disabled = isSettingShortcut ? charMagicLevel < minMagicLevelRequired : manaCost > charMana || charMagicLevel < minMagicLevelRequired;
35492
+ return React__default.createElement(Container$i, {
35493
+ disabled: disabled,
35494
+ onClick: onClick == null ? void 0 : onClick.bind(null, spellKey),
35495
+ isSettingShortcut: isSettingShortcut && !disabled,
35496
+ className: "spell"
35497
+ }, disabled && React__default.createElement(Overlay, null, charMagicLevel < minMagicLevelRequired ? 'Low magic level' : manaCost > charMana && 'No mana'), React__default.createElement(SpellImage, null, magicWords.split(' ').map(function (word) {
35498
+ return word[0];
35499
+ })), React__default.createElement(Info, null, React__default.createElement(Title$5, null, React__default.createElement("span", null, name), React__default.createElement("span", {
35500
+ className: "spell"
35501
+ }, "(", magicWords, ")")), React__default.createElement(Description, null, description)), React__default.createElement(Divider, null), React__default.createElement(Cost, null, React__default.createElement("span", null, "Mana cost:"), React__default.createElement("span", {
35502
+ className: "mana"
35503
+ }, manaCost)));
35504
+ };
35505
+ var Container$i = /*#__PURE__*/styled.button.withConfig({
35506
+ displayName: "Spell__Container",
35507
+ componentId: "sc-j96fa2-0"
35508
+ })(["display:block;background:none;border:2px solid transparent;border-radius:1rem;width:100%;display:flex;height:5rem;gap:1rem;align-items:center;padding:0 1rem;text-align:left;position:relative;animation:", ";@keyframes border-color-change{0%{border-color:", ";}50%{border-color:transparent;}100%{border-color:", ";}}&:hover,&:focus{background-color:", ";}&:active{background:none;}"], function (_ref2) {
35509
+ var isSettingShortcut = _ref2.isSettingShortcut;
35510
+ return isSettingShortcut ? 'border-color-change 1s infinite' : 'none';
35511
+ }, uiColors.yellow, uiColors.yellow, uiColors.darkGray);
35512
+ var SpellImage = /*#__PURE__*/styled.div.withConfig({
35513
+ displayName: "Spell__SpellImage",
35514
+ componentId: "sc-j96fa2-1"
35515
+ })(["width:4rem;height:4rem;font-size:", ";font-weight:bold;background-color:", ";color:", ";display:flex;justify-content:center;align-items:center;text-transform:uppercase;"], uiFonts.size.xLarge, uiColors.darkGray, uiColors.lightGray);
35516
+ var Info = /*#__PURE__*/styled.span.withConfig({
35517
+ displayName: "Spell__Info",
35518
+ componentId: "sc-j96fa2-2"
35519
+ })(["width:0;flex:1;"]);
35520
+ var Title$5 = /*#__PURE__*/styled.p.withConfig({
35521
+ displayName: "Spell__Title",
35522
+ componentId: "sc-j96fa2-3"
35523
+ })(["display:flex;flex-wrap:wrap;align-items:center;margin-bottom:5px;margin:0;span{font-size:", " !important;font-weight:bold !important;color:", " !important;margin-right:0.5rem;}.spell{font-size:", " !important;font-weight:normal !important;color:", " !important;}"], uiFonts.size.medium, uiColors.yellow, uiFonts.size.small, uiColors.lightGray);
35524
+ var Description = /*#__PURE__*/styled.div.withConfig({
35525
+ displayName: "Spell__Description",
35526
+ componentId: "sc-j96fa2-4"
35527
+ })(["font-size:", " !important;line-height:1.1 !important;"], uiFonts.size.small);
35528
+ var Divider = /*#__PURE__*/styled.div.withConfig({
35529
+ displayName: "Spell__Divider",
35530
+ componentId: "sc-j96fa2-5"
35531
+ })(["width:1px;height:100%;margin:0 1rem;background-color:", ";"], uiColors.lightGray);
35532
+ var Cost = /*#__PURE__*/styled.p.withConfig({
35533
+ displayName: "Spell__Cost",
35534
+ componentId: "sc-j96fa2-6"
35535
+ })(["display:flex;align-items:center;flex-direction:column;gap:0.5rem;div{z-index:1;}.mana{position:relative;font-size:", ";font-weight:bold;z-index:1;&::after{position:absolute;content:'';top:0;left:0;background-color:", ";width:100%;height:100%;border-radius:50%;transform:scale(1.8);filter:blur(10px);z-index:-1;}}"], uiFonts.size.medium, uiColors.blue);
35536
+ var Overlay = /*#__PURE__*/styled.p.withConfig({
35537
+ displayName: "Spell__Overlay",
35538
+ componentId: "sc-j96fa2-7"
35539
+ })(["margin:0 !important;position:absolute;top:0;left:0;width:100%;height:100%;border-radius:1rem;display:flex;justify-content:center;align-items:center;color:", ";font-size:", " !important;font-weight:bold;z-index:10;background-color:rgba(0 0 0 / 0.2);"], uiColors.yellow, uiFonts.size.large);
35540
+
35541
+ var SpellbookShortcuts = function SpellbookShortcuts(_ref) {
35542
+ var setSettingShortcutIndex = _ref.setSettingShortcutIndex,
35543
+ settingShortcutIndex = _ref.settingShortcutIndex,
35544
+ shortcuts = _ref.shortcuts,
35545
+ removeShortcut = _ref.removeShortcut;
35546
+ return React__default.createElement(List$1, {
35547
+ id: "shortcuts_list"
35548
+ }, "Spells shortcuts:", Array.from({
35549
+ length: 4
35550
+ }).map(function (_, i) {
35551
+ var _shortcuts$i2;
35552
+ return React__default.createElement(SpellShortcut$1, {
35553
+ key: i,
35554
+ onClick: function onClick() {
35555
+ var _shortcuts$i;
35556
+ removeShortcut(i);
35557
+ if (!((_shortcuts$i = shortcuts[i]) != null && _shortcuts$i.key)) setSettingShortcutIndex(i);
35558
+ },
35559
+ disabled: settingShortcutIndex !== -1 && settingShortcutIndex !== i,
35560
+ isBeingSet: settingShortcutIndex === i
35561
+ }, React__default.createElement("span", null, (_shortcuts$i2 = shortcuts[i]) == null ? void 0 : _shortcuts$i2.magicWords.split(' ').map(function (word) {
35562
+ return word[0];
35563
+ })));
35564
+ }));
35565
+ };
35566
+ var SpellShortcut$1 = /*#__PURE__*/styled.button.withConfig({
35567
+ displayName: "SpellbookShortcuts__SpellShortcut",
35568
+ componentId: "sc-fr4a0d-0"
35569
+ })(["width:2.6rem;height:2.6rem;background-color:", ";border:2px solid ", ";border-radius:50%;text-transform:uppercase;font-size:0.7rem;font-weight:bold;display:flex;align-items:center;justify-content:center;span{margin-top:4px;}&:hover,&:focus{background-color:", ";}&:active{background-color:", ";}&:disabled{opacity:0.5;}"], uiColors.lightGray, function (_ref2) {
35570
+ var isBeingSet = _ref2.isBeingSet;
35571
+ return isBeingSet ? uiColors.yellow : uiColors.darkGray;
35572
+ }, uiColors.darkGray, uiColors.gray);
35573
+ var List$1 = /*#__PURE__*/styled.p.withConfig({
35574
+ displayName: "SpellbookShortcuts__List",
35575
+ componentId: "sc-fr4a0d-1"
35576
+ })(["width:100%;display:flex;align-items:center;justify-content:flex-end;gap:0.5rem;padding:0.5rem;box-sizing:border-box;margin:0 !important;"]);
35577
+
35578
+ var Spellbook = function Spellbook(_ref) {
35579
+ var onClose = _ref.onClose,
35580
+ onInputFocus = _ref.onInputFocus,
35581
+ onInputBlur = _ref.onInputBlur,
35582
+ spells = _ref.spells,
35583
+ magicLevel = _ref.magicLevel,
35584
+ mana = _ref.mana,
35585
+ onSpellClick = _ref.onSpellClick,
35586
+ setSpellShortcut = _ref.setSpellShortcut,
35587
+ spellShortcuts = _ref.spellShortcuts,
35588
+ removeSpellShortcut = _ref.removeSpellShortcut;
35589
+ var _useState = React.useState(''),
35590
+ search = _useState[0],
35591
+ setSearch = _useState[1];
35592
+ var _useState2 = React.useState(-1),
35593
+ settingShortcutIndex = _useState2[0],
35594
+ setSettingShortcutIndex = _useState2[1];
35595
+ React.useEffect(function () {
35596
+ var handleEscapeClose = function handleEscapeClose(e) {
35597
+ if (e.key === 'Escape') {
35598
+ onClose == null ? void 0 : onClose();
35599
+ }
35600
+ };
35601
+ document.addEventListener('keydown', handleEscapeClose);
35602
+ return function () {
35603
+ document.removeEventListener('keydown', handleEscapeClose);
35604
+ };
35605
+ }, [onClose]);
35606
+ var spellsToDisplay = React.useMemo(function () {
35607
+ return spells.sort(function (a, b) {
35608
+ if (a.minMagicLevelRequired > b.minMagicLevelRequired) return 1;
35609
+ if (a.minMagicLevelRequired < b.minMagicLevelRequired) return -1;
35610
+ return 0;
35611
+ }).filter(function (spell) {
35612
+ return spell.name.toLocaleLowerCase().includes(search.toLocaleLowerCase()) || spell.magicWords.toLocaleLowerCase().includes(search.toLocaleLowerCase());
35613
+ });
35614
+ }, [search, spells]);
35615
+ var setShortcut = function setShortcut(spellKey) {
35616
+ setSpellShortcut == null ? void 0 : setSpellShortcut(spellKey, settingShortcutIndex);
35617
+ setSettingShortcutIndex(-1);
35618
+ };
35619
+ return React__default.createElement(DraggableContainer, {
35620
+ type: exports.RPGUIContainerTypes.Framed,
35621
+ onCloseButton: onClose,
35622
+ width: "inherit",
35623
+ height: "inherit",
35624
+ cancelDrag: "#spellbook-search, #shortcuts_list, .spell"
35625
+ }, React__default.createElement(Container$j, null, React__default.createElement(Title$6, null, "Learned Spells"), React__default.createElement(SpellbookShortcuts, {
35626
+ setSettingShortcutIndex: setSettingShortcutIndex,
35627
+ settingShortcutIndex: settingShortcutIndex,
35628
+ shortcuts: spellShortcuts,
35629
+ removeShortcut: removeSpellShortcut
35630
+ }), React__default.createElement(Input, {
35631
+ placeholder: "Search for spell",
35632
+ value: search,
35633
+ onChange: function onChange(e) {
35634
+ return setSearch(e.target.value);
35635
+ },
35636
+ onFocus: onInputFocus,
35637
+ onBlur: onInputBlur,
35638
+ id: "spellbook-search"
35639
+ }), React__default.createElement(SpellList, null, spellsToDisplay.map(function (spell) {
35640
+ return React__default.createElement(React.Fragment, {
35641
+ key: spell.key
35642
+ }, React__default.createElement(Spell, Object.assign({
35643
+ charMana: mana,
35644
+ charMagicLevel: magicLevel,
35645
+ onClick: settingShortcutIndex !== -1 ? setShortcut : onSpellClick,
35646
+ spellKey: spell.key,
35647
+ isSettingShortcut: settingShortcutIndex !== -1
35648
+ }, spell)));
35649
+ }))));
35650
+ };
35651
+ var Title$6 = /*#__PURE__*/styled.h1.withConfig({
35652
+ displayName: "Spellbook__Title",
35653
+ componentId: "sc-r02nfq-0"
35654
+ })(["font-size:", " !important;margin-bottom:0 !important;"], uiFonts.size.large);
35655
+ var Container$j = /*#__PURE__*/styled.div.withConfig({
35656
+ displayName: "Spellbook__Container",
35657
+ componentId: "sc-r02nfq-1"
35658
+ })(["width:100%;height:100%;color:white;display:flex;flex-direction:column;"]);
35659
+ var SpellList = /*#__PURE__*/styled.div.withConfig({
35660
+ displayName: "Spellbook__SpellList",
35661
+ componentId: "sc-r02nfq-2"
35662
+ })(["width:100%;min-height:0;flex:1;overflow-y:auto;display:flex;flex-direction:column;gap:1.5rem;margin-top:1rem;"]);
35663
+
35430
35664
  var TextArea = function TextArea(_ref) {
35431
35665
  var props = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
35432
35666
  return React__default.createElement("textarea", Object.assign({}, props));
@@ -35627,7 +35861,7 @@ var TradingMenu = function TradingMenu(_ref) {
35627
35861
  style: {
35628
35862
  width: '100%'
35629
35863
  }
35630
- }, React__default.createElement(Title$5, null, Capitalize(type), " Menu"), React__default.createElement("hr", {
35864
+ }, React__default.createElement(Title$7, null, Capitalize(type), " Menu"), React__default.createElement("hr", {
35631
35865
  className: "golden"
35632
35866
  })), React__default.createElement(TradingComponentScrollWrapper, null, traderItems.map(function (tradeItem, index) {
35633
35867
  var _qtyMap$get;
@@ -35653,7 +35887,7 @@ var TradingMenu = function TradingMenu(_ref) {
35653
35887
  }
35654
35888
  }, "Cancel"))));
35655
35889
  };
35656
- var Title$5 = /*#__PURE__*/styled.h1.withConfig({
35890
+ var Title$7 = /*#__PURE__*/styled.h1.withConfig({
35657
35891
  displayName: "TradingMenu__Title",
35658
35892
  componentId: "sc-1wjsz1l-0"
35659
35893
  })(["z-index:22;font-size:0.6rem;color:yellow !important;"]);
@@ -35687,11 +35921,11 @@ var Truncate = function Truncate(_ref) {
35687
35921
  var _ref$maxLines = _ref.maxLines,
35688
35922
  maxLines = _ref$maxLines === void 0 ? 1 : _ref$maxLines,
35689
35923
  children = _ref.children;
35690
- return React__default.createElement(Container$i, {
35924
+ return React__default.createElement(Container$k, {
35691
35925
  maxLines: maxLines
35692
35926
  }, children);
35693
35927
  };
35694
- var Container$i = /*#__PURE__*/styled.div.withConfig({
35928
+ var Container$k = /*#__PURE__*/styled.div.withConfig({
35695
35929
  displayName: "Truncate__Container",
35696
35930
  componentId: "sc-6x00qb-0"
35697
35931
  })(["display:-webkit-box;max-width:100%;max-height:100%;-webkit-line-clamp:", ";-webkit-box-orient:vertical;overflow:hidden;"], function (props) {
@@ -35724,11 +35958,13 @@ exports.PropertySelect = PropertySelect;
35724
35958
  exports.QuestInfo = QuestInfo;
35725
35959
  exports.QuestList = QuestList;
35726
35960
  exports.QuestionDialog = QuestionDialog;
35961
+ exports.QuickSpells = QuickSpells;
35727
35962
  exports.RPGUIContainer = RPGUIContainer;
35728
35963
  exports.RPGUIRoot = RPGUIRoot;
35729
35964
  exports.RangeSlider = RangeSlider;
35730
35965
  exports.SkillProgressBar = SkillProgressBar;
35731
35966
  exports.SkillsContainer = SkillsContainer;
35967
+ exports.Spellbook = Spellbook;
35732
35968
  exports.SpriteFromAtlas = SpriteFromAtlas;
35733
35969
  exports.TextArea = TextArea;
35734
35970
  exports.TimeWidget = TimeWidget;