ENH: Spell slots
							parent
							
								
									9bcc0fd975
								
							
						
					
					
						commit
						afef38bce6
					
				| 
						 | 
				
			
			@ -13,7 +13,8 @@ export class OseActorSheet extends ActorSheet {
 | 
			
		|||
    data.config = CONFIG.OSE;
 | 
			
		||||
    // Settings
 | 
			
		||||
    data.config.ascendingAC = game.settings.get("ose", "ascendingAC");
 | 
			
		||||
    data.config.encumbranceBasic = game.settings.get("ose", "encumbranceOption") == 'basic';
 | 
			
		||||
    data.config.encumbranceBasic =
 | 
			
		||||
      game.settings.get("ose", "encumbranceOption") == "basic";
 | 
			
		||||
 | 
			
		||||
    // Prepare owned items
 | 
			
		||||
    this._prepareItems(data);
 | 
			
		||||
| 
						 | 
				
			
			@ -42,11 +43,17 @@ export class OseActorSheet extends ActorSheet {
 | 
			
		|||
 | 
			
		||||
    // Sort spells by level
 | 
			
		||||
    var sortedSpells = {};
 | 
			
		||||
    var slots = {};
 | 
			
		||||
    for (var i = 0; i < spells.length; i++) {
 | 
			
		||||
      let lvl = spells[i].data.lvl;
 | 
			
		||||
      if (!sortedSpells[lvl]) sortedSpells[lvl] = [];
 | 
			
		||||
      if (!slots[lvl]) slots[lvl] = 0;
 | 
			
		||||
      slots[lvl] += spells[i].data.memorized;
 | 
			
		||||
      sortedSpells[lvl].push(spells[i]);
 | 
			
		||||
    }
 | 
			
		||||
    data.slots = {
 | 
			
		||||
      used: slots
 | 
			
		||||
    };
 | 
			
		||||
    // Assign and return
 | 
			
		||||
    data.owned = {
 | 
			
		||||
      items: items,
 | 
			
		||||
| 
						 | 
				
			
			@ -74,6 +81,18 @@ export class OseActorSheet extends ActorSheet {
 | 
			
		|||
    li.toggleClass("expanded");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async _onSpellChange(event) {
 | 
			
		||||
    event.preventDefault();
 | 
			
		||||
    const itemId = event.currentTarget.closest(".item").dataset.itemId;
 | 
			
		||||
    const item = this.actor.getOwnedItem(itemId);
 | 
			
		||||
    if (event.target.dataset.field == "cast") {
 | 
			
		||||
      return item.update({ "data.cast": parseInt(event.target.value) });
 | 
			
		||||
    } else if (event.target.dataset.field == "memorize") {
 | 
			
		||||
      return item.update({
 | 
			
		||||
        "data.memorized": parseInt(event.target.value),
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  activateListeners(html) {
 | 
			
		||||
    // Item summaries
 | 
			
		||||
| 
						 | 
				
			
			@ -117,21 +136,29 @@ export class OseActorSheet extends ActorSheet {
 | 
			
		|||
      item.roll({ skipDialog: event.ctrlKey });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    html.find(".item .item-rollable .item-image").click(async ev =>  {
 | 
			
		||||
    html.find(".item .item-rollable .item-image").click(async (ev) => {
 | 
			
		||||
      const li = $(ev.currentTarget).parents(".item");
 | 
			
		||||
      const item = this.actor.getOwnedItem(li.data("itemId"));
 | 
			
		||||
      if (item.type == 'weapon') {
 | 
			
		||||
      if (item.type == "weapon") {
 | 
			
		||||
        item.rollWeapon();
 | 
			
		||||
      } else {
 | 
			
		||||
        item.rollFormula();
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    html.find(".attack a").click(ev => {
 | 
			
		||||
    html
 | 
			
		||||
      .find(".memorize input")
 | 
			
		||||
      .click((ev) => ev.target.select())
 | 
			
		||||
      .change(this._onSpellChange.bind(this));
 | 
			
		||||
 | 
			
		||||
    html.find(".attack a").click((ev) => {
 | 
			
		||||
      let actorObject = this.actor;
 | 
			
		||||
      let element = event.currentTarget;
 | 
			
		||||
      let attack = element.parentElement.parentElement.dataset.attack;
 | 
			
		||||
      actorObject.rollAttack({label: this.actor.name, type: attack}, { event: event });
 | 
			
		||||
      actorObject.rollAttack(
 | 
			
		||||
        { label: this.actor.name, type: attack },
 | 
			
		||||
        { event: event }
 | 
			
		||||
      );
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    html.find(".hit-dice .attribute-name a").click((ev) => {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -281,6 +281,10 @@
 | 
			
		|||
        flex-grow: 0;
 | 
			
		||||
        text-align: center;
 | 
			
		||||
        font-size: 12px;
 | 
			
		||||
        &.memorize input {
 | 
			
		||||
          border-bottom: none;
 | 
			
		||||
          margin: 3px 0;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      .field-short {
 | 
			
		||||
        font-size: 12px;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,26 +7,28 @@
 | 
			
		|||
 | 
			
		||||
.ose.chat-block {
 | 
			
		||||
  margin: 0;
 | 
			
		||||
  .chat-title {
 | 
			
		||||
  .chat-header {
 | 
			
		||||
    height: 46px;
 | 
			
		||||
    margin: 4px 0;
 | 
			
		||||
    background: $darkBackground;
 | 
			
		||||
    border: 1px solid black;
 | 
			
		||||
    border-radius: 3px;
 | 
			
		||||
    color: white;
 | 
			
		||||
    padding: 2px;
 | 
			
		||||
    box-shadow: 0 0 2px #FFF inset;
 | 
			
		||||
    box-shadow: 0 0 2px #fff inset;
 | 
			
		||||
    .chat-title {
 | 
			
		||||
      margin: 4px 0;
 | 
			
		||||
    display: flex;
 | 
			
		||||
      h2 {
 | 
			
		||||
        border: none;
 | 
			
		||||
      line-height: 30px;
 | 
			
		||||
        line-height: 34px;
 | 
			
		||||
        margin: 0;
 | 
			
		||||
        text-indent: 10px;
 | 
			
		||||
        font-size: 16px;
 | 
			
		||||
      }
 | 
			
		||||
    img {
 | 
			
		||||
      border: none;
 | 
			
		||||
      width: 30px;
 | 
			
		||||
      height: 30px;
 | 
			
		||||
    }
 | 
			
		||||
    .chat-img {
 | 
			
		||||
      flex: 0 0 42px;
 | 
			
		||||
      background-size: cover;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  .chat-details {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -57,27 +57,21 @@
 | 
			
		|||
        "spells": {
 | 
			
		||||
          "enabled": false,
 | 
			
		||||
          "1": {
 | 
			
		||||
            "value": 0,
 | 
			
		||||
            "max": 0
 | 
			
		||||
          },
 | 
			
		||||
          "2": {
 | 
			
		||||
            "value": 0,
 | 
			
		||||
            "max": 0
 | 
			
		||||
          },
 | 
			
		||||
          "3": {
 | 
			
		||||
            "value": 0,
 | 
			
		||||
            "max": 0
 | 
			
		||||
          },
 | 
			
		||||
          "4": {
 | 
			
		||||
            "value": 0,
 | 
			
		||||
            "max": 0
 | 
			
		||||
          },
 | 
			
		||||
          "5": {
 | 
			
		||||
            "value": 0,
 | 
			
		||||
            "max": 0
 | 
			
		||||
          },
 | 
			
		||||
          "6": {
 | 
			
		||||
            "value": 0,
 | 
			
		||||
            "max": 0
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -191,8 +185,8 @@
 | 
			
		|||
      "range": "",
 | 
			
		||||
      "roll": "",
 | 
			
		||||
      "description": "",
 | 
			
		||||
      "memorized": false,
 | 
			
		||||
      "cast": false,
 | 
			
		||||
      "memorized": 0,
 | 
			
		||||
      "cast": 0,
 | 
			
		||||
      "save": ""
 | 
			
		||||
    },
 | 
			
		||||
    "ability": {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,8 +5,10 @@
 | 
			
		|||
      <div class="item-caret"><i class="fas fa-caret-down"></i> </div>
 | 
			
		||||
      <div class="item-name">{{localize "OSE.spells.Level"}} {{id}}</div>
 | 
			
		||||
      <div class="field-short">{{localize 'OSE.spells.Slots'}}</div>
 | 
			
		||||
      <div class="field-long flexrow"><input type="text" value="{{lookup (lookup ../actor.data.spells @key) 'value'}}" name="data.spells.{{id}}.value" data-dtype="Number"
 | 
			
		||||
          placeholder="0">/<input type="text" value="{{lookup (lookup ../actor.data.spells @key) 'max'}}" name="data.spells.{{id}}.max" data-dtype="Number"
 | 
			
		||||
      <div class="field-long flexrow">
 | 
			
		||||
        <input type="text" value="{{lookup @root.slots.used @key}}"
 | 
			
		||||
          name="data.spells.{{id}}.value" data-dtype="Number" placeholder="0" disabled>/<input type="text"
 | 
			
		||||
          value="{{lookup (lookup ../actor.data.spells @key) 'max'}}" name="data.spells.{{id}}.max" data-dtype="Number"
 | 
			
		||||
          placeholder="0"></div>
 | 
			
		||||
      <div class="item-controls">
 | 
			
		||||
        <a class="item-control item-create" data-type="spell" data-lvl="{{id}}" title="{{localize 'OSE.Add'}}"><i
 | 
			
		||||
| 
						 | 
				
			
			@ -17,11 +19,6 @@
 | 
			
		|||
      {{#each spellGroup as |item|}}
 | 
			
		||||
      <li class="item-entry">
 | 
			
		||||
        <div class="item flexrow" data-item-id="{{item._id}}">
 | 
			
		||||
        <div class="item-controls">
 | 
			
		||||
          <a class="item-control item-cast {{#unless item.data.cast}}item-unequipped{{/unless}}" title="{{localize 'OSE.spells.Cast'}}"><i class="{{#if item.data.cast}}fas{{else}}far{{/if}} fa-sun"></i></a>
 | 
			
		||||
          <a class="item-control item-memorize {{#unless item.data.memorized}}item-unequipped{{/unless}}" title="{{localize 'OSE.spells.Memorized'}}"><i
 | 
			
		||||
              class="fas fa-book-open"></i></a>
 | 
			
		||||
        </div>
 | 
			
		||||
          <div class="item-name  {{#if item.data.roll}}item-rollable{{/if}} flexrow">
 | 
			
		||||
            <div class="item-image" style="background-image: url({{item.img}})"></div>
 | 
			
		||||
            <a>
 | 
			
		||||
| 
						 | 
				
			
			@ -30,6 +27,10 @@
 | 
			
		|||
              </h4>
 | 
			
		||||
            </a>
 | 
			
		||||
          </div>
 | 
			
		||||
          <div class="field-long memorize flexrow">
 | 
			
		||||
            <input type="text" value="{{item.data.cast}}" data-dtype="Number" placeholder="0" data-field="cast" title="{{localize 'OSE.spells.Cast'}}">
 | 
			
		||||
            /
 | 
			
		||||
            <input type="text" value="{{item.data.memorized}}" data-field="memorize" data-dtype="Number" placeholder="0" title="{{localize 'OSE.spells.Memorized'}}"></div>
 | 
			
		||||
          <div class="item-controls">
 | 
			
		||||
            {{#if ../../owner}}
 | 
			
		||||
            <a class="item-control item-show" title='{{localize "OSE.Show"}}'><i class="fas fa-eye"></i></a>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,8 @@
 | 
			
		|||
<section class="ose chat-message">
 | 
			
		||||
    <div class="ose chat-block">
 | 
			
		||||
        <div class="chat-title">
 | 
			
		||||
            <img src="{{data.img}}">
 | 
			
		||||
            <h2>{{title}}</h2>
 | 
			
		||||
        <div class="flexrow chat-header">
 | 
			
		||||
            <div class="chat-title"><h2>{{title}}</h2></div>
 | 
			
		||||
            <div class="chat-img" style="background-image:url('{{data.img}}')"></div>
 | 
			
		||||
        </div>
 | 
			
		||||
        <div class="chat-details">
 | 
			
		||||
            <div class="roll-result">{{{result.details}}}</div>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,8 @@
 | 
			
		|||
<section class="ose chat-message">
 | 
			
		||||
    <div class="ose chat-block">
 | 
			
		||||
        <div class="chat-title">
 | 
			
		||||
            <img src="{{data.img}}">
 | 
			
		||||
            <h2>{{title}}</h2>
 | 
			
		||||
        <div class="flexrow chat-header">
 | 
			
		||||
            <div class="chat-title"><h2>{{title}}</h2></div>
 | 
			
		||||
            <div class="chat-img" style="background-image:url('{{data.img}}')"></div>
 | 
			
		||||
        </div>
 | 
			
		||||
        {{#if result.details}}<div class="chat-details">{{{result.details}}}</div>{{/if}}
 | 
			
		||||
        {{#if result.isFailure}}<div class='roll-result roll-fail'><b>{{localize 'OSE.Failure'}}</b> ({{result.target}})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue