Skip to content

Commit b5f53a5

Browse files
committed
added frames counter when importing them
1 parent 21b8bdd commit b5f53a5

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/js/controller/dialogs/importwizard/steps/ImageImport.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
this.resizeHeight = this.container.querySelector('[name=resize-height]');
2727
this.smoothResize = this.container.querySelector('[name=smooth-resize-checkbox]');
2828

29+
this.framesH = this.container.querySelector('[name=frames-h]');
30+
this.framesV = this.container.querySelector('[name=frames-v]');
2931
this.frameSizeX = this.container.querySelector('[name=frame-size-x]');
3032
this.frameSizeY = this.container.querySelector('[name=frame-size-y]');
3133
this.frameOffsetX = this.container.querySelector('[name=frame-offset-x]');
@@ -34,6 +36,8 @@
3436
this.addEventListener(this.singleImportType, 'change', this.onImportTypeChange_);
3537
this.addEventListener(this.sheetImportType, 'change', this.onImportTypeChange_);
3638

39+
this.addEventListener(this.framesH, 'keyup', this.onFrameInputKeyUp_);
40+
this.addEventListener(this.framesV, 'keyup', this.onFrameInputKeyUp_);
3741
this.addEventListener(this.resizeWidth, 'keyup', this.onResizeInputKeyUp_);
3842
this.addEventListener(this.resizeHeight, 'keyup', this.onResizeInputKeyUp_);
3943
this.addEventListener(this.frameSizeX, 'keyup', this.onFrameInputKeyUp_);
@@ -73,6 +77,10 @@
7377
this.importedImage_,
7478
{
7579
importType: this.getImportType_(),
80+
framesH: this.getImportType_() === 'single' ?
81+
1 : this.sanitizeInputValue_(this.frameSizeX, 1),
82+
frameV: this.getImportType_() === 'single' ?
83+
1 : this.sanitizeInputValue_(this.frameSizeY, 1),
7684
frameSizeX: this.getImportType_() === 'single' ?
7785
this.resizeWidth.value : this.sanitizeInputValue_(this.frameSizeX, 1),
7886
frameSizeY: this.getImportType_() === 'single' ?
@@ -110,10 +118,34 @@
110118

111119
ns.ImageImport.prototype.onFrameInputKeyUp_ = function (evt) {
112120
if (this.importedImage_) {
121+
var targetName = evt.originalTarget.name;
122+
if (!targetName.includes('offset')) {
123+
this.synchronizeDivisions(targetName);
124+
}
113125
this.synchronizeFrameFields_(evt.target.value);
114126
}
115127
};
116128

129+
ns.ImageImport.prototype.synchronizeDivisions = function (targetName) {
130+
var divideBy = (targetName === 'frames-h' || targetName === 'frame-size-x') ?
131+
this.importedImage_.width : this.importedImage_.height;
132+
133+
switch (targetName) {
134+
case 'frames-h':
135+
this.frameSizeX.value = Math.floor(divideBy / this.sanitizeInputValue_(this.framesH, 0));
136+
break;
137+
case 'frame-size-x':
138+
this.framesH.value = Math.floor(divideBy / this.sanitizeInputValue_(this.frameSizeX, 1));
139+
break;
140+
case 'frames-v':
141+
this.frameSizeY.value = Math.floor(divideBy / this.sanitizeInputValue_(this.framesV, 1));
142+
break;
143+
case 'frame-size-y':
144+
this.framesV.value = Math.floor(divideBy / this.sanitizeInputValue_(this.frameSizeY, 1));
145+
break;
146+
}
147+
};
148+
117149
ns.ImageImport.prototype.synchronizeResizeFields_ = function (value, from) {
118150
value = parseInt(value, 10);
119151
if (isNaN(value)) {
@@ -139,6 +171,8 @@
139171
}
140172

141173
// Parse the frame input values
174+
var framesH = this.sanitizeInputValue_(this.framesH, 1);
175+
var framesV = this.sanitizeInputValue_(this.framesV, 1);
142176
var frameSizeX = this.sanitizeInputValue_(this.frameSizeX, 1);
143177
var frameSizeY = this.sanitizeInputValue_(this.frameSizeY, 1);
144178
var frameOffsetX = this.sanitizeInputValue_(this.frameOffsetX, 0);
@@ -187,6 +221,8 @@
187221
this.resizeWidth.value = w;
188222
this.resizeHeight.value = h;
189223

224+
this.framesH.value = 1;
225+
this.framesV.value = 1;
190226
this.frameSizeX.value = w;
191227
this.frameSizeY.value = h;
192228
this.frameOffsetX.value = 0;

src/templates/dialogs/import.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ <h3 class="dialog-head">
3838
Import as spritesheet
3939
</label>
4040
</div>
41+
<div class="import-section import-subsection">
42+
<span class="dialog-section-title">frames</span>
43+
<input type="text" class="textfield import-size-field" autocomplete="off" name="frames-h"/>x
44+
<input type="text" class="textfield import-size-field" autocomplete="off" name="frames-v"/>
45+
</div>
4146
<div class="import-section import-subsection">
4247
<span class="dialog-section-title">Frame size</span>
4348
<input type="text" class="textfield import-size-field" autocomplete="off" name="frame-size-x"/>x

0 commit comments

Comments
 (0)