Skip to content

Commit

Permalink
Improve exported filename generation
Browse files Browse the repository at this point in the history
Merge pull request #89 from haroldo-ok/export-image
  • Loading branch information
haroldo-ok authored Jun 12, 2024
2 parents 1db4ca4 + 0afd57c commit 97d3431
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/components/PixelEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import {chunk, debounce} from 'lodash';
import {saveAs} from 'file-saver';
import {isMatrixEqual} from '../utils/array';
import {getDateInfix} from '../utils/date';
import {loadImageFromFile, openFileDialog} from '../utils/file';
import {createResizedCanvas} from '../utils/image';
Expand All @@ -84,6 +85,7 @@ export default {
aspectRatio: {type: Number, default: 4.0 / 3},
fgColor: {type: String, default: 'white'},
bgColor: {type: String, default: 'black'},
name: {type: String, default: 'image'},
},
data() {
return {
Expand Down Expand Up @@ -126,9 +128,8 @@ export default {
ctx.fillRect(px.x, px.y, 1, 1);
});
canvas.toBlob(function(blob) {
const dateInfix = new Date().toISOString().replace(/\..*/, '').replace(/[T:]/g, '-');
saveAs(blob, `image-${dateInfix}.png`);
canvas.toBlob((blob) => {
saveAs(blob, `${this.name}-${getDateInfix()}.png`);
});
},
Expand Down
3 changes: 2 additions & 1 deletion src/components/PlayerEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
:aspectRatio="160/192"
v-model="frame.pixels"
:fgColor="fgColor"
:name="name"
@input="handleChildChange"
/>
</div>
Expand Down Expand Up @@ -157,7 +158,7 @@ import {playfieldToMatrix} from '../utils/pixels';
export default defineComponent({
components: {PixelEditor},
props: ['storageFactory', 'title', 'fgColor'],
props: ['storageFactory', 'title', 'fgColor', 'name'],
setup(props) {
const getMaxId = (elements) => {
return max(elements.map((o) => o.id))||0;
Expand Down
1 change: 1 addition & 0 deletions src/utils/date.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const getDateInfix = () => new Date().toISOString().replace(/\..*/, '').replace(/[T:]/g, '-');
1 change: 1 addition & 0 deletions src/views/BackgroundEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<pixel-editor
:width="32"
:height="11"
name="background"
v-model="background.pixels"
fgColor="orange"
@input="handleChildChange"
Expand Down
1 change: 1 addition & 0 deletions src/views/Player0Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
:storageFactory="usePlayer0Storage"
title="Player 0"
fgColor="red"
name="player0"
/>
</template>
<script>
Expand Down
1 change: 1 addition & 0 deletions src/views/Player1Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
:storageFactory="usePlayer1Storage"
title="Player 1"
fgColor="blue"
name="player1"
/>
</template>
<script>
Expand Down
4 changes: 2 additions & 2 deletions src/views/Project.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {saveAs} from 'file-saver';
import YAML from 'yaml';
import {useBackgroundsStorage, usePlayer0Storage, usePlayer1Storage, useWorkspaceStorage} from '../hooks/project';
import {getDateInfix} from '../utils/date';
import {matrixToPlayfield, playfieldToMatrix} from '../utils/pixels';
const FORMAT_TYPE = 'VCS Game Maker Project';
Expand Down Expand Up @@ -77,8 +78,7 @@ export default defineComponent({
});
const projectBlob = new Blob([projectYaml], {type: 'text/yaml'});
const dateInfix = new Date().toISOString().replace(/\..*/, '').replace(/[T:]/g, '-');
saveAs(projectBlob, `project-${dateInfix}.vcsgm`);
saveAs(projectBlob, `project-${getDateInfix()}.vcsgm`);
},
handleLoadProject() {
Expand Down

0 comments on commit 97d3431

Please sign in to comment.