Skip to content

Commit

Permalink
add pixelscale to game config edit tab
Browse files Browse the repository at this point in the history
  • Loading branch information
preaction committed Jul 3, 2024
1 parent 782f3d7 commit a7e3f4b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
6 changes: 2 additions & 4 deletions editor/electron/bitwise-build/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const defaultGameConfig = {
renderer: {
width: 1280,
height: 720,
pixelScale: 128,
},
};

Expand Down Expand Up @@ -75,10 +76,7 @@ async function releaseZip(root: string, gameFilePath: string, dest: string): Pro
loader: {
base: '',
},
renderer: {
width: ${gameConfig.renderer?.width ?? defaultGameConfig.renderer.width},
height: ${gameConfig.renderer?.height ?? defaultGameConfig.renderer.height},
},
renderer: ${JSON.stringify(gameConfig.renderer)},
scene: '${initialScene}',
});
game.start();
Expand Down
7 changes: 6 additions & 1 deletion editor/src/components/GameConfig.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts" setup>
import { inject, onMounted, reactive, ref, watch, type Ref } from "vue";
import { inject, onMounted, ref, watch, type Ref } from "vue";
import type Project from "../model/Project";
import type { ConfigFile } from "../types";
Expand All @@ -11,6 +11,7 @@ let config = ref({
renderer: {
width: 1024,
height: 768,
pixelScale: 128,
},
},
} as ConfigFile);
Expand Down Expand Up @@ -47,6 +48,10 @@ async function save() {
<label for="height">Height</label>
<input id="height" v-model.number="config.game.renderer.height" />
</div>
<div class="form-group">
<label for="pixel-scale">Pixel Scale</label>
<input id="pixel-scale" v-model.number="config.game.renderer.pixelScale" />
</div>
</fieldset>
</div>
</form>
Expand Down
2 changes: 1 addition & 1 deletion editor/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type ReleaseConfig = {
};
export type ConfigFile = {
game: GameConfig,
release: {
release?: {
zip: ReleaseConfig,
},
};
Expand Down
8 changes: 5 additions & 3 deletions editor/test/unit/bitwise-build/release.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as fs from 'node:fs/promises';
import * as path from 'node:path';
import * as os from 'node:os';
import extract from 'extract-zip';
import type { GameConfig } from '../../../../game/dist/Game.js';
import type { GameConfig } from '@fourstar/bitwise';
import { release } from '../../../electron/bitwise-build/release.js';

let gameDir: string, gameFilePath: string, gameConfFile: string,
Expand All @@ -24,6 +24,7 @@ describe('release', () => {
renderer: {
width: 1920,
height: 1080,
pixelScale: 128,
},
};
const bitwiseConfig = {
Expand Down Expand Up @@ -51,8 +52,9 @@ describe('release', () => {
});

// Test the game configuration
expect(indexHtml).toMatch(`width: ${gameConf.renderer.width}`);
expect(indexHtml).toMatch(`height: ${gameConf.renderer.height}`);
expect(indexHtml).toMatch(new RegExp(`\"?width\"?\s*:\s*${gameConf.renderer.width}`));
expect(indexHtml).toMatch(new RegExp(`\"?height\"?\s*:\s*${gameConf.renderer.height}`));
expect(indexHtml).toMatch(new RegExp(`\"?pixelScale\"?\s*:\s*${gameConf.renderer.pixelScale}`));
});
});
});
5 changes: 5 additions & 0 deletions editor/test/unit/src/components/GameConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('GameConfig', () => {
renderer: {
width: 1280,
height: 720,
pixelScale: 128,
},
},
};
Expand All @@ -26,6 +27,7 @@ describe('GameConfig', () => {
expect(mockRead).toHaveBeenCalledWith(project.name, 'bitwise.json');
expect(wrapper.vm.$el.querySelector('#width').value).toBe("" + configData.game.renderer.width);
expect(wrapper.vm.$el.querySelector('#height').value).toBe("" + configData.game.renderer.height);
expect(wrapper.vm.$el.querySelector('#pixel-scale').value).toBe("" + configData.game.renderer.pixelScale);
});

test('write config to file', async () => {
Expand All @@ -35,8 +37,10 @@ describe('GameConfig', () => {

const newWidth = 1600;
const newHeight = 800;
const newScale = 64;
await wrapper.get('#width').setValue(newWidth);
await wrapper.get('#height').setValue(newHeight);
await wrapper.get('#pixel-scale').setValue(newScale);
expect(wrapper.get('[data-test=save]').attributes('disabled')).toBeFalsy();

await wrapper.get('form').trigger('submit');
Expand All @@ -46,5 +50,6 @@ describe('GameConfig', () => {
const configData = JSON.parse(mockWrite.mock.lastCall?.[2] || '{}')
expect(configData?.game?.renderer?.width).toBe(newWidth);
expect(configData?.game?.renderer?.height).toBe(newHeight);
expect(configData?.game?.renderer?.pixelScale).toBe(newScale);
});
});

0 comments on commit a7e3f4b

Please sign in to comment.