Skip to content

Commit

Permalink
refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
zAlweNy26 committed Jan 12, 2023
1 parent 77e5487 commit c175687
Show file tree
Hide file tree
Showing 18 changed files with 240 additions and 568 deletions.
41 changes: 7 additions & 34 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ if (!app.requestSingleInstanceLock()) {
process.exit(0)
}

// Read more on https://www.electronjs.org/docs/latest/tutorial/security
//.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'

let win: BrowserWindow | null = null
// Here, you can also use other preload
const preload = join(__dirname, '../preload/index.js')
const url = process.env.VITE_DEV_SERVER_URL
const indexHtml = join(process.env.DIST, 'index.html')

async function createWindow() {
function createWindow() {
win = new BrowserWindow({
title: 'Penta Quest',
icon: join(process.env.PUBLIC, 'Logo.png'),
Expand All @@ -38,10 +35,6 @@ async function createWindow() {
center: true,
useContentSize: true,
webPreferences: {
//preload,
// Warning: Enable nodeIntegration and disable contextIsolation is not secure in production
// Consider using contextBridge.exposeInMainWorld
// Read more on https://www.electronjs.org/docs/latest/tutorial/context-isolation
nodeIntegration: true,
contextIsolation: false,
},
Expand All @@ -57,16 +50,18 @@ async function createWindow() {
win.webContents.openDevTools({ mode: "undocked", activate: false })
}

// Test actively push message to the Electron-Renderer
win.webContents.on('did-finish-load', () => {
win?.webContents.send('main-process-message', new Date().toLocaleString())
})

// Make all links open with the browser, not with the application
win.webContents.setWindowOpenHandler(({ url }) => {
if (url.startsWith('https:')) shell.openExternal(url)
return { action: 'deny' }
})

ipcMain.handle('close-window',() => win!.close())

ipcMain.handle('toggle-fullscreen', (event, arg) => win!.setFullScreen(arg))
}

app.whenReady().then(createWindow)
Expand All @@ -90,26 +85,4 @@ app.on('activate', () => {
} else {
createWindow()
}
})

// new window example arg: new windows url
ipcMain.handle('open-win', (event, arg) => {
const childWindow = new BrowserWindow({
webPreferences: {
preload,
nodeIntegration: true,
contextIsolation: false,
},
})

if (app.isPackaged) {
childWindow.loadFile(indexHtml, { hash: arg })
} else {
childWindow.loadURL(`${url}#${arg}`)
// childWindow.webContents.openDevTools({ mode: "undocked", activate: true })
}
})

ipcMain.handle('close-window',() => win.close())

ipcMain.handle('toggle-fullscreen', (event, arg) => win.setFullScreen(arg))
})
92 changes: 0 additions & 92 deletions electron/preload/index.ts

This file was deleted.

13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"type": "git",
"url": "git+https://github.com/UniDank/ProgettoPentagono.git"
},
"author": {
"name": "zAlweNy26, FedeDC512, valentimarco, xClaudi0, GiorgioZa"
},
"contributors": [
{
"name": "Daniele Nicosia"
Expand All @@ -32,7 +35,8 @@
"homepage": "https://github.com/UniDank/ProgettoPentagono#readme",
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build"
"check": "vue-tsc --noEmit",
"build": "npm run check && vite build"
},
"engines": {
"node": "^14.18.0 || >=16.0.0"
Expand All @@ -43,6 +47,7 @@
"@types/animejs": "^3.1.6",
"@types/jquery": "^3.5.14",
"@types/lodash.clonedeep": "^4.5.7",
"@types/webfontloader": "^1.6.35",
"@vitejs/plugin-vue": "^3.1.2",
"autoprefixer": "^10.4.13",
"electron": "^21.2.2",
Expand Down
51 changes: 51 additions & 0 deletions src/classes/Entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import Vector2 = Phaser.Math.Vector2
import { Direction, Position } from "grid-engine"

export class Entity {
public sprite: Phaser.GameObjects.Sprite
private movRange: number
public animations: Phaser.Animations.Animation[] = []

constructor(private scene: Phaser.Scene, public spriteName: string, private tilePos = new Vector2(0, 0)) {
this.animations = scene.anims.createFromAseprite(spriteName)
this.sprite = scene.add.sprite(0, 0, spriteName).setInteractive().setScale(2)
this.movRange = 1
}

public getCharacterConfig(collision: string[] = []): any{
return {
id: this.spriteName,
sprite: this.sprite,
startPosition: { x: this.tilePos.x, y: this.tilePos.y },
offsetY: -16,
offsetX: -8,
collides: {
collisionGroups: collision
}
};
}

public movePlayerTo(position: Vector2): void{
this.scene.gridEngine.moveTo(this.spriteName, { x: position.x, y: position.y })
}

private movePlayer(direction: Direction): void {
this.scene.gridEngine.move(this.spriteName,direction);
}

public setEvent(event: string, fn: Function): void {
this.sprite.on(event, fn)
}

public getPosition(): Position {
return this.scene.gridEngine.getPosition(this.spriteName)
}

public isMoving(): boolean {
return this.scene.gridEngine.isMoving(this.spriteName)
}

public getRangeMov(): number {
return this.movRange
}
}
109 changes: 0 additions & 109 deletions src/classes/TempPlayer.ts

This file was deleted.

Loading

0 comments on commit c175687

Please sign in to comment.