Skip to content

Commit

Permalink
Merge pull request #1353 from solaris-games/dev
Browse files Browse the repository at this point in the history
Update 250.2
  • Loading branch information
SpacialCircumstances authored Jan 29, 2025
2 parents 6bd7241 + dd90736 commit ac36e08
Show file tree
Hide file tree
Showing 14 changed files with 139 additions and 68 deletions.
10 changes: 3 additions & 7 deletions client/src/game/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,16 +659,12 @@ export class Map extends EventEmitter {

if (empireCenter) {
this.gameContainer.viewport!.moveCenter(empireCenter.x, empireCenter.y)
} else {
const galaxyCenterX = gameHelper.calculateGalaxyCenterX(game)
const galaxyCenterY = gameHelper.calculateGalaxyCenterY(game)

this.gameContainer.viewport!.moveCenter(galaxyCenterX, galaxyCenterY)
}

const zoomPercent = this.gameContainer.getViewportZoomPercentage()
const zoomPercent = this.gameContainer.getViewportZoomPercentage()

this.refreshZoom(zoomPercent)
this.refreshZoom(zoomPercent)
}
}

panToUser (game) {
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/playerNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PlayerNames {
this.container.removeChildren()

for (let player of this.game!.galaxy.players) {
const empireCenter = gameHelper.getPlayerEmpireCenter(this.game, player)
const empireCenter = gameHelper.getPlayerEmpireCenter(this.game!, player)

if (empireCenter == null) {
continue
Expand Down
4 changes: 2 additions & 2 deletions client/src/game/territories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class Territories {
let territoryLines = new Graphics()
this.container.addChild(territoryPolygons)
this.container.addChild(territoryLines)
territoryPolygons.alpha = 0.333
territoryPolygons.alpha = userSettings.map.territoryOpacity;

const check = (ix: number, iy: number) => {
const point = playerSamplePoints[ix]?.[iy];
Expand All @@ -224,7 +224,7 @@ export class Territories {
let combining = false
for (let ix = 0; ix < samplePoints.length - 1; ix++) {
for (let iy = 0; iy < samplePoints[ix].length - 1; iy++) {
let alpha = 0.333333;
let alpha = userSettings.map.territoryOpacity;

let lookUpIndex = 0
lookUpIndex += (check(ix, iy) ? 1 : 0) * 8
Expand Down
25 changes: 17 additions & 8 deletions client/src/services/gameHelper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import moment, {type Moment} from 'moment'
import DiplomacyHelper from './diplomacyHelper.js'
import type {Game, Player} from "../types/game";
import type {Game, Player, Star} from "../types/game";

class GameHelper {
getUserPlayer (game) {
Expand Down Expand Up @@ -57,7 +57,7 @@ class GameHelper {
return game.galaxy.players.find(x => x._id === star.ownedByPlayerId)
}

getStarsOwnedByPlayer(player, stars) {
getStarsOwnedByPlayer(player: Player, stars: Star[]) {
if (player == null) {
return [];
}
Expand Down Expand Up @@ -939,17 +939,26 @@ class GameHelper {
return `${dayOfWeek[date.getDay()]} ${date.getDate()} ${monthOfYear[date.getMonth()]} ${date.getHours() < 10 ? '0' + date.getHours() : date.getHours()}:${date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()}`
}

getPlayerEmpireCenter (game, player) {
getPlayerEmpireCenter (game: Game, player: Player) {
// Get all of the player's stars.
let playerStars = this.getStarsOwnedByPlayer(player, game.galaxy.stars)
const playerStars = this.getStarsOwnedByPlayer(player, game.galaxy.stars)

if (!playerStars.length) {
return null
const playerCarriers = game.galaxy.carriers.filter(car => car.ownedByPlayerId === player._id);

if (playerCarriers.length === 0) {
return null;
}

const centerX = playerCarriers.reduce((sum, c) => sum + c.location.x, 0) / playerCarriers.length
const centerY = playerCarriers.reduce((sum, c) => sum + c.location.y, 0) / playerCarriers.length

return { x: centerX, y: centerY };
}

// Work out the center point of all stars
let centerX = playerStars.reduce((sum, s) => sum + s.location.x, 0) / playerStars.length
let centerY = playerStars.reduce((sum, s) => sum + s.location.y, 0) / playerStars.length
const centerX = playerStars.reduce((sum, s) => sum + s.location.x, 0) / playerStars.length
const centerY = playerStars.reduce((sum, s) => sum + s.location.y, 0) / playerStars.length

let closestStar = this.getClosestPlayerStar(game.galaxy.stars, { x: centerX, y: centerY }, player)

Expand Down Expand Up @@ -1145,7 +1154,7 @@ class GameHelper {
calculateTickIncome(game, player) {
let stars = this.getStarsOwnedByPlayer(player, game.galaxy.stars).filter(s => s.specialistId === 12); // Financial Analyst

let creditsPerTickByScience = stars[0]?.specialist.modifiers.special.creditsPerTickByScience ?? 0;
let creditsPerTickByScience = stars[0]?.specialist?.modifiers?.special?.creditsPerTickByScience ?? 0;

return (stars.reduce((totalScience, star) => totalScience + (star.infrastructure?.science ?? 0), 0) * game.constants.research.sciencePointMultiplier) * creditsPerTickByScience;
}
Expand Down
35 changes: 35 additions & 0 deletions client/src/views/game/ActiveGames.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
<view-container :is-auth-page="true">
<view-title title="My Games" />

<div v-if="showDonationBanner" class="row bg-secondary border-2 mb-4 p-1 support-banner" title="Support the project">
<p class="support-text">
Solaris is free, open source and does not have ads. Please consider donating or purchasing Galactic Credits to support the continued development of the project.
</p>

<p class="support-buttons">
<a class="btn btn-success" href="https://www.buymeacoffee.com/limitingfactor" target="_blank">Donate</a>
<a class="btn btn-primary" href="javascript:;" @click="closeDonationBanner">Dismiss</a>
</p>
</div>

<active-games/>
<hr/>
<spectating-games/>
Expand All @@ -24,9 +35,33 @@ export default {
'active-games': ActiveGamesVue,
'completed-games': CompletedGamesVue,
'spectating-games': SpectatingGamesVue
},
data () {
return {
showDonationBanner: Math.random() < 0.05
}
},
methods: {
closeDonationBanner () {
this.showDonationBanner = false
}
}
}
</script>

<style scoped>
.support-banner {
border-radius: 4px;
}
.support-text {
color: white;
white-space: pre-line;
}
.support-buttons {
display: flex;
justify-content: right;
gap: 8px;
}
</style>
20 changes: 0 additions & 20 deletions client/src/views/game/components/GameContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ export default {
this.polling = setInterval(this.touchPlayer, 60000)
this.touchPlayer()
}
this.tryShowDonateModal(game)
},
beforeUnmount () {
Expand Down Expand Up @@ -136,24 +134,6 @@ export default {
onObjectsClicked (e) {
this.$emit('onObjectsClicked', e)
},
async tryShowDonateModal (game) {
if (GameHelper.isTutorialGame(game)) {
return;
}
let chance = Math.floor(Math.random() * (20 - 0 + 1) + 0); // 1 in 20
if (chance === 0 &&
await this.$confirm('Support The Project',
`Hello there,
Solaris is free, open source and does not have ads. Please consider donating or purchasing Galactic Credits to support the continued development of the project.
Thank you,
LimitingFactor`, 'Donate', 'Dismiss', false, true)) {
window.open("https://www.buymeacoffee.com/limitingfactor", '_blank').focus();
}
}
},
computed: mapState(['game']),
Expand Down
6 changes: 6 additions & 0 deletions client/src/views/game/components/menu/OptionsForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@
</div>
</div>

<div class="row mb-1 pb-1">
<label for="territory-opacity" class="col col-form-label">Territory Opacity</label>
<div class="col">
<input type="number" max="1" min="0" step="0.05" class="form-control" id="territory-opacity" v-model="settings.map.territoryOpacity" :disabled="isSavingSettings">
</div>
</div>
</div>

<div class="mb-1 pb-1">
Expand Down
1 change: 1 addition & 0 deletions common/src/api/types/common/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type UserGameSettings = {
carrierPathWidth: number;
carrierPathDashLength: number;
territoryStyle: SettingTerritoryStyle;
territoryOpacity: number;
marchingSquareGridSize: number;
marchingSquareTerritorySize: number;
marchingSquareBorderWidth: number;
Expand Down
4 changes: 3 additions & 1 deletion server/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export default async (config, options) => {

const dbConnection = mongoose.connection;

dbConnection.on('error', log.error.bind(log.error, 'connection error:'));
dbConnection.on('error', (e) => {
log.error(e, 'connection error:')
});

options = options || {};
options.connectionString = options.connectionString || config.connectionString;
Expand Down
1 change: 1 addition & 0 deletions server/db/models/schemas/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const schema = new Schema({
carrierPathWidth: { type: Types.Number, required: false, default: 1, min: 1, max: 8 },
carrierPathDashLength: { type: Types.Number, required: false, default: 6, min: 4, max: 16 },
territoryStyle: { type: Types.String, required: false, enum: ['disabled', 'marching-square', 'voronoi'], default: 'marching-square' },
territoryOpacity: { type: Types.Number, required: false, default: 0.333, min: 0, max: 1 },
marchingSquareGridSize: { type: Types.Number, required: false, default: 6, min: 2, max: 32 },
marchingSquareTerritorySize:{ type: Types.Number, required: false, default: 5, min: 2, max: 32 },
marchingSquareBorderWidth: { type: Types.Number, required: false, default: 2, min: 0, max: 8 },
Expand Down
8 changes: 4 additions & 4 deletions server/services/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ function getNewConversation(game: Game, playerId: DBObjectId | null, name: strin
}

// Validate that another conversation doesn't already exist with the same participants.
let existingConvo = game.conversations
const existingConvo = game.conversations
.filter(c => c.participants.length === participantIds.length)
.find(c => arrayIsEqual(c.participants.map(p => p.toString()), participantIds));
.find(c => arrayIsEqual(c.participants.map(p => p.toString()), participantIds.map(pid => pid.toString())));

if (existingConvo) {
throw new ValidationError(`A conversation already exists with the selected participants named [${existingConvo.name}].`);
if (existingConvo && existingConvo.name === name) {
throw new ValidationError(`A conversation already exists with the same participants and name.`);
}

let convoId = new mongoose.Types.ObjectId();
Expand Down
6 changes: 3 additions & 3 deletions server/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ export default (config: Config,
const playerCycleRewardsService = new PlayerCycleRewardsService(starService, technologyService, playerStatisticsService, specialistService);
const diplomacyUpkeepService = new DiplomacyUpkeepService(playerCreditsService, playerCycleRewardsService);
const diplomacyService = new DiplomacyService(gameRepository, eventRepository, diplomacyUpkeepService)
const starCaptureService = new StarCaptureService(specialistService, starService, gameTypeService, gameStateService, diplomacyService);
const researchService = new ResearchService(gameRepository, technologyService, randomService, playerStatisticsService, starService, userService, gameTypeService);
const starUpgradeService = new StarUpgradeService(gameRepository, starService, carrierService, achievementService, researchService, technologyService, playerCreditsService, gameTypeService, shipService);
const starCaptureService = new StarCaptureService(specialistService, starService, gameTypeService, gameStateService, diplomacyService, technologyService, starUpgradeService);
const starContestedService = new StarContestedService(diplomacyService);
const carrierGiftService = new CarrierGiftService(gameRepository, diplomacyService);
const carrierMovementService = new CarrierMovementService(gameRepository, distanceService, starService, specialistService, diplomacyService, carrierGiftService, technologyService, starDistanceService);
Expand Down Expand Up @@ -220,13 +222,11 @@ export default (config: Config,
const playerServerSocketHandler = new PlayerServerSocketHandler(socketService, gameService, serverHandler);
const leaderboardService = new LeaderboardService(playerService, playerAfkService, userLevelService, ratingService, gameService, gameTypeService, gameStateService, badgeService, playerStatisticsService, teamService);
const userLeaderboardService = new UserLeaderboardService(userRepository, guildUserService);
const researchService = new ResearchService(gameRepository, technologyService, randomService, playerStatisticsService, starService, userService, gameTypeService);
const combatService = new CombatService(technologyService, specialistService, playerService, starService, reputationService, diplomacyService, gameTypeService, starCaptureService);
const historyService = new HistoryService(historyRepository, playerService, gameService, playerStatisticsService, gameStateService);
const waypointService = new WaypointService(gameRepository, carrierService, starService, distanceService, starDistanceService, technologyService, gameService, playerService, carrierMovementService, gameMaskingService, historyService);
const specialistBanService = new SpecialistBanService(specialistService);
const specialistHireService = new SpecialistHireService(gameRepository, specialistService, achievementService, waypointService, playerCreditsService, starService, gameTypeService, specialistBanService, technologyService);
const starUpgradeService = new StarUpgradeService(gameRepository, starService, carrierService, achievementService, researchService, technologyService, playerCreditsService, gameTypeService, shipService);
const shipTransferService = new ShipTransferService(gameRepository, carrierService, starService);
const pathfindingService = new PathfindingService(distanceService, starService, waypointService);
const basicAIService = new BasicAIService(starUpgradeService);
Expand Down
Loading

0 comments on commit ac36e08

Please sign in to comment.