Skip to content

Commit 06b54e2

Browse files
committed
Add version in properties of a project
1 parent daa683f commit 06b54e2

File tree

12 files changed

+182
-122
lines changed

12 files changed

+182
-122
lines changed

Core/GDCore/Project/Project.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Project::Project()
6161
:
6262
#if defined(GD_IDE_ONLY)
6363
name(_("Project")),
64+
version("1.0.0"),
6465
packageName("com.example.gamename"),
6566
orientation("landscape"),
6667
folderProject(false),
@@ -524,6 +525,7 @@ void Project::UnserializeFrom(const SerializerElement& element) {
524525
const SerializerElement& propElement =
525526
element.GetChild("properties", 0, "Info");
526527
SetName(propElement.GetChild("name", 0, "Nom").GetValue().GetString());
528+
SetVersion(propElement.GetStringAttribute("version", "1.0.0"));
527529
SetDefaultWidth(
528530
propElement.GetChild("windowWidth", 0, "WindowW").GetValue().GetInt());
529531
SetDefaultHeight(
@@ -782,6 +784,7 @@ void Project::SerializeTo(SerializerElement& element) const {
782784

783785
SerializerElement& propElement = element.AddChild("properties");
784786
propElement.AddChild("name").SetValue(GetName());
787+
propElement.SetAttribute("version", GetVersion());
785788
propElement.AddChild("author").SetValue(GetAuthor());
786789
propElement.AddChild("windowWidth").SetValue(GetMainWindowDefaultWidth());
787790
propElement.AddChild("windowHeight").SetValue(GetMainWindowDefaultHeight());
@@ -1100,6 +1103,7 @@ Project& Project::operator=(const Project& other) {
11001103
void Project::Init(const gd::Project& game) {
11011104
// Some properties
11021105
name = game.name;
1106+
version = game.version;
11031107
windowWidth = game.windowWidth;
11041108
windowHeight = game.windowHeight;
11051109
maxFPS = game.maxFPS;

Core/GDCore/Project/Project.h

+12-26
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,18 @@ class TiXmlElement;
2121
#include "GDCore/Project/VariablesContainer.h"
2222
namespace gd {
2323
class Platform;
24-
}
25-
namespace gd {
2624
class Layout;
27-
}
28-
namespace gd {
2925
class ExternalEvents;
30-
}
31-
namespace gd {
3226
class ResourcesManager;
33-
}
34-
namespace gd {
3527
class ExternalLayout;
36-
}
37-
namespace gd {
3828
class Object;
39-
}
40-
namespace gd {
4129
class VariablesContainer;
42-
}
43-
namespace gd {
4430
class ArbitraryResourceWorker;
45-
}
46-
namespace gd {
4731
class SourceFile;
48-
}
49-
namespace gd {
5032
class ImageManager;
51-
}
52-
namespace gd {
5333
class Behavior;
54-
}
55-
namespace gd {
5634
class BehaviorsSharedData;
57-
}
58-
namespace gd {
5935
class BaseEvent;
60-
}
61-
namespace gd {
6236
class SerializerElement;
6337
}
6438
#undef GetObject // Disable an annoying macro
@@ -92,6 +66,17 @@ class GD_CORE_API Project : public ClassWithObjects {
9266
*/
9367
const gd::String& GetName() const { return name; }
9468

69+
/**
70+
* \brief Change the version of the project.
71+
* This can be freely set, but should follow "X.Y.Z" format for compatibility with some exporters.
72+
*/
73+
void SetVersion(const gd::String& version_) { version = version_; };
74+
75+
/**
76+
* \brief Get project version.
77+
*/
78+
const gd::String& GetVersion() const { return version; }
79+
9580
#if defined(GD_IDE_ONLY)
9681
/**
9782
* \brief Change the author of the project.
@@ -877,6 +862,7 @@ class GD_CORE_API Project : public ClassWithObjects {
877862
void LoadProjectInformationFromXml(const TiXmlElement* elem);
878863

879864
gd::String name; ///< Game name
865+
gd::String version; ///< Game version number (used for some exports)
880866
unsigned int windowWidth; ///< Window default width
881867
unsigned int windowHeight; ///< Window default height
882868
int maxFPS; ///< Maximum Frame Per Seconds, -1 for unlimited

GDJS/GDJS/IDE/ExporterHelper.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ bool ExporterHelper::ExportElectronFiles(const gd::Project &project,
315315
project.GetName()) // TODO: JSON encode string
316316
.FindAndReplace("GDJS_GAME_AUTHOR",
317317
project.GetAuthor()) // TODO: JSON encode string
318+
.FindAndReplace("GDJS_GAME_VERSION", project.GetVersion())
318319
.FindAndReplace(
319320
"GDJS_GAME_MANGLED_NAME",
320321
project.GetName().LowerCase()); // TODO: JSON encode string

GDJS/Runtime/Electron/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"productName": "GDJS_GAME_NAME",
55
"description": "GDJS_GAME_NAME",
66
"author": "GDJS_GAME_AUTHOR",
7-
"version": "1.0.0",
7+
"version": "GDJS_GAME_VERSION",
88
"dependencies": {}
99
}
1010

newIDE/app/src/Export/LocalExporters/LocalCordovaExport.js

+20-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @flow
12
import React, { Component } from 'react';
23
import Dialog from '../../UI/Dialog';
34
import FlatButton from 'material-ui/FlatButton';
@@ -9,9 +10,11 @@ import { findGDJS } from './LocalGDJSFinder';
910
import localFileSystem from './LocalFileSystem';
1011
import LocalFolderPicker from '../../UI/LocalFolderPicker';
1112
import HelpButton from '../../UI/HelpButton';
12-
import { displaySanityCheck } from '../SanityChecker';
13-
import { getSanityMessages } from '../SanityChecker/ProjectSanityChecker';
14-
import { translate } from 'react-i18next';
13+
import {
14+
displayProjectErrorsBox,
15+
getErrors,
16+
} from '../../ProjectManager/ProjectErrorsChecker';
17+
import { translate, type TranslatorProps } from 'react-i18next';
1518
import assignIn from 'lodash/assignIn';
1619
import optionalRequire from '../../Utils/OptionalRequire';
1720
import Window from '../../Utils/Window';
@@ -20,7 +23,16 @@ const shell = electron ? electron.shell : null;
2023

2124
const gd = global.gd;
2225

23-
class LocalCordovaExport extends Component {
26+
type Props = TranslatorProps & {|
27+
project: gdProject,
28+
|};
29+
30+
type State = {|
31+
outputDir: string,
32+
exportFinishedDialogOpen: boolean,
33+
|};
34+
35+
class LocalCordovaExport extends Component<Props, State> {
2436
state = {
2537
exportFinishedDialogOpen: false,
2638
outputDir: '',
@@ -61,7 +73,7 @@ class LocalCordovaExport extends Component {
6173

6274
sendExportLaunched('local-cordova');
6375

64-
if (!displaySanityCheck(t, getSanityMessages(t, project))) return;
76+
if (!displayProjectErrorsBox(t, getErrors(t, project))) return;
6577

6678
const outputDir = this.state.outputDir;
6779
project.setLastCompilationDirectory(outputDir);
@@ -70,14 +82,10 @@ class LocalCordovaExport extends Component {
7082
.then(({ exporter }) => {
7183
const exportOptions = new gd.MapStringBoolean();
7284
exportOptions.set('exportForCordova', true);
73-
exporter.exportWholePixiProject(
74-
project,
75-
outputDir,
76-
exportOptions
77-
);
85+
exporter.exportWholePixiProject(project, outputDir, exportOptions);
7886
exportOptions.delete();
7987
exporter.delete();
80-
88+
8189
this.setState({
8290
exportFinishedDialogOpen: true,
8391
});
@@ -88,7 +96,7 @@ class LocalCordovaExport extends Component {
8896
};
8997

9098
openExportFolder = () => {
91-
shell.openItem(this.state.outputDir);
99+
if (shell) shell.openItem(this.state.outputDir);
92100
};
93101

94102
openPhoneGapBuild = () => {

newIDE/app/src/Export/LocalExporters/LocalElectronExport.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @flow
12
import React, { Component } from 'react';
23
import Dialog from '../../UI/Dialog';
34
import FlatButton from 'material-ui/FlatButton';
@@ -9,17 +10,25 @@ import { findGDJS } from './LocalGDJSFinder';
910
import localFileSystem from './LocalFileSystem';
1011
import LocalFolderPicker from '../../UI/LocalFolderPicker';
1112
import HelpButton from '../../UI/HelpButton';
12-
import { displaySanityCheck } from '../SanityChecker';
13-
import { getSanityMessages } from '../SanityChecker/ProjectSanityChecker';
14-
import { translate } from 'react-i18next';
13+
import { displayProjectErrorsBox, getErrors } from '../../ProjectManager/ProjectErrorsChecker';
14+
import { translate, type TranslatorProps } from 'react-i18next';
1515
import assignIn from 'lodash/assignIn';
1616
import optionalRequire from '../../Utils/OptionalRequire';
1717
const electron = optionalRequire('electron');
1818
const shell = electron ? electron.shell : null;
1919

2020
const gd = global.gd;
2121

22-
class LocalElectronExport extends Component {
22+
type Props = TranslatorProps & {|
23+
project: gdProject,
24+
|};
25+
26+
type State = {|
27+
outputDir: string,
28+
exportFinishedDialogOpen: boolean,
29+
|};
30+
31+
class LocalElectronExport extends Component<Props, State> {
2332
state = {
2433
exportFinishedDialogOpen: false,
2534
outputDir: '',
@@ -60,7 +69,7 @@ class LocalElectronExport extends Component {
6069

6170
sendExportLaunched('local-electron');
6271

63-
if (!displaySanityCheck(t, getSanityMessages(t, project))) return;
72+
if (!displayProjectErrorsBox(t, getErrors(t, project))) return;
6473

6574
const outputDir = this.state.outputDir;
6675
project.setLastCompilationDirectory(outputDir);
@@ -87,7 +96,7 @@ class LocalElectronExport extends Component {
8796
};
8897

8998
openExportFolder = () => {
90-
shell.openItem(this.state.outputDir);
99+
if (shell) shell.openItem(this.state.outputDir);
91100
};
92101

93102
render() {

newIDE/app/src/Export/LocalExporters/LocalOnlineCordovaExport/index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import Window from '../../../Utils/Window';
2424
import { delay } from '../../../Utils/Delay';
2525
import CreateProfile from '../../../Profile/CreateProfile';
2626
import LimitDisplayer from '../../../Profile/LimitDisplayer';
27-
import { displaySanityCheck } from '../../SanityChecker';
28-
import { getSanityMessages } from '../../SanityChecker/ProjectSanityChecker';
27+
import { displayProjectErrorsBox, getErrors } from '../../../ProjectManager/ProjectErrorsChecker';
2928
import { translate, type TranslatorProps } from 'react-i18next';
3029
import { type Limit } from '../../../Utils/GDevelopServices/Usage';
3130
const path = optionalRequire('path');
@@ -209,7 +208,7 @@ class LocalOnlineCordovaExport extends Component<Props, State> {
209208
const { t, project } = this.props;
210209
sendExportLaunched('local-online-cordova');
211210

212-
if (!displaySanityCheck(t, getSanityMessages(t, project))) return;
211+
if (!displayProjectErrorsBox(t, getErrors(t, project))) return;
213212

214213
const handleError = (message: string) => err => {
215214
if (!this.state.errored) {

newIDE/app/src/Export/LocalExporters/LocalOnlineElectronExport/index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import Window from '../../../Utils/Window';
2424
import { delay } from '../../../Utils/Delay';
2525
import CreateProfile from '../../../Profile/CreateProfile';
2626
import LimitDisplayer from '../../../Profile/LimitDisplayer';
27-
import { displaySanityCheck } from '../../SanityChecker';
28-
import { getSanityMessages } from '../../SanityChecker/ProjectSanityChecker';
27+
import { displayProjectErrorsBox, getErrors } from '../../../ProjectManager/ProjectErrorsChecker';
2928
import { translate, type TranslatorProps } from 'react-i18next';
3029
import { type Limit } from '../../../Utils/GDevelopServices/Usage';
3130
const path = optionalRequire('path');
@@ -209,7 +208,7 @@ class LocalOnlineElectronExport extends Component<Props, State> {
209208
const { t, project } = this.props;
210209
sendExportLaunched('local-online-electron');
211210

212-
if (!displaySanityCheck(t, getSanityMessages(t, project))) return;
211+
if (!displayProjectErrorsBox(t, getErrors(t, project))) return;
213212

214213
const handleError = (message: string) => err => {
215214
if (!this.state.errored) {

newIDE/app/src/Export/SanityChecker/ProjectSanityChecker.js

-30
This file was deleted.

newIDE/app/src/Export/SanityChecker/index.js

-25
This file was deleted.

0 commit comments

Comments
 (0)