Compare commits

...

31 Commits

Author SHA1 Message Date
Florian Rival
f8a31cf3a9 Bump newIDE version 2018-05-22 23:41:11 -07:00
Florian Rival
5372f09c67 Fix closing confirmation 2018-05-22 23:30:33 -07:00
Florian Rival
b9f0e88f7e Bump version 2018-05-22 22:53:16 -07:00
Florian Rival
a5c3767cca Properly refresh textures of edited objects (useful after editing an image with Piskel) 2018-05-22 22:48:33 -07:00
Florian Rival
05e21484cf Fix React warning in PropertiesEditor 2018-05-22 07:53:48 -07:00
Florian Rival
6c204494b5 Add analytics to track usefulness of embedded Piskel editor 2018-05-21 22:17:42 -07:00
Todor Imreorov
af4cdcd485 Add a bundled version of Piskel for edition of image resources directly from GDevelop
* Supports SpriteObject and other object editors using ResourceSelector.
* This system could handle other editors too.
2018-05-20 22:33:08 -07:00
Nnarol
2977f0b1a7 Fix compilation error due to incomplete type. (#496)
Remove inclusion of wx/propgrid/property.h preceding
inclusion of wx/propgrid/propgrid.h to avoid incomplete type
error of object m_bitmap in property.h of type wxBitmap during build.
propgrid.h includes property.h anyway.
2018-05-20 20:49:03 -07:00
Nnarol
16a31cf1ae Prevent fly from disappearing behind cloud in platformer example (#492)
Set z-order of "Cloud" instances to -5.
Set z-order of "BackgroundObjects" to -2.
2018-05-10 19:06:47 -07:00
Florian Rival
dd14a2a86c Run clang-format on some missing files 2018-05-09 16:52:27 -07:00
Florian Rival
a8559bfbbc Add clang-format to format (C++) source files automatically (#491)
* Update all CMakeLists of extensions to use clang-format
* Run clang-format on all Extensions
* Update GDCore CMakeLists.txt to add clang-format
* Run clang-format on GDCore files
* Update GDJS and GDCpp CMakeLists.txt to add clang-format
* Run clang-format on GDCpp and GDJS files
2018-05-09 15:57:38 -07:00
Florian Rival
a77f8e139f Add Opacity expression for Sprite objects 2018-05-05 15:29:30 +01:00
Florian Rival
07af3990ac Add button to open object editor from InstancePropertiesEditor 2018-05-05 13:55:54 +01:00
Florian Rival
33eee8e00a Update demo gif shown on the README with GDevelop 5 2018-05-04 17:50:45 +01:00
Florian Rival
3f32134018 Fix tests 2018-05-04 13:37:52 +01:00
Florian Rival
5b12935851 Add npm package caching for faster Travis CI builds 2018-05-04 13:31:37 +01:00
Florian Rival
7a4d563875 Remove AppVeyor badge for now as it's not stable yet 2018-05-04 13:25:17 +01:00
Florian Rival
a0105fda37 Disable GDJS Runtime tests on Travis-CI as ChromeHeadless is not working 2018-05-04 13:23:05 +01:00
Florian Rival
d2f997ab4c Remove useless use of filter in ObjectSelector 2018-05-02 20:30:34 +01:00
Florian Rival
eb58f592ed Refactor FuzzyOrEmptyFilter to use it all AutoComplete by default 2018-05-02 15:43:17 +01:00
Florian Rival
8b6b896520 Ensure all AutoComplete popover are visible on screen (even if on the bottom of the window) 2018-05-02 15:03:40 +01:00
Florian Rival
34f240fe59 Fix flow issue 2018-05-02 15:00:08 +01:00
Florian Rival
e78411f3a8 Increase width of GenericExpressionField (useful for when clicking on a expression/string parameter) 2018-05-02 14:39:14 +01:00
Florian Rival
3128a19901 Add Checkbox to enable/disable stopping sounds on scene startup in ScenePropertiesDialog 2018-05-02 14:36:33 +01:00
Florian Rival
14d58eac32 Avoid Popover displayed by ObjectSelector to go outside of the screen 2018-05-01 00:21:07 +01:00
Florian Rival
7488b12704 Add documentation about optionalRequire 2018-04-30 14:02:27 +01:00
Lizard-13
f5fa82c95e Fix distance check (#487) 2018-04-30 10:42:39 +01:00
Florian Rival
6ddd093d56 Fix missing flow annotations 2018-04-28 15:09:32 +01:00
Florian Rival
b5ce3a996d Avoid inactive SceneEditor/ExternalLayoutEditor to drain CPU 2018-04-28 14:37:10 +01:00
Florian Rival
d8409d5f1e Make GenericExpressionField multiline (better readabiliy of long expressions) 2018-04-28 00:44:14 +01:00
Florian Rival
7773d431e8 Improve editor performance (#485)
* Use PureComponent to avoid useless rerenderings
* Disable update to editor tabs that are not active
* Add UpdatesProfiler to ease the detection of unnecessary updates in React components
2018-04-27 22:38:12 +01:00
962 changed files with 146910 additions and 108295 deletions

View File

@@ -4,6 +4,11 @@ compiler:
- gcc
- clang
# Cache .npm folder for faster npm install
cache:
directories:
- $HOME/.npm
git:
depth: 999999
@@ -53,17 +58,19 @@ install:
- cd ..
script:
#newIDE tests:
- cd newIDE/app
- npm test
- npm run flow
- cd ../..
#GDJS game engine tests:
- cd GDJS/tests && npm test
- cd ../..
#GDCore and GDCpp game engine tests:
- cd .build-tests
- Core/GDCore_tests
- GDCpp/GDCpp_tests
- Extensions/PathfindingBehavior/PathfindingBehavior_Runtime_tests
- Extensions/LinkedObjects/LinkedObjects_Runtime_tests
- cd ..
#newIDE tests:
- cd newIDE/app
- npm test
- npm run flow
- cd ../..
#GDJS game engine tests, disabled on Travis CI because ChromeHeadless can't be started.
#See them running on Semaphore-CI instead: https://semaphoreci.com/4ian/gd
# - cd GDJS/tests && npm test
# - cd ../..

View File

@@ -121,5 +121,5 @@
}
}
],
"version": 3
"version": 4
}

View File

@@ -71,7 +71,10 @@
"atomic": "cpp",
"locale": "cpp",
"string_view": "cpp",
"__string": "cpp"
"__string": "cpp",
"cstring": "cpp",
"iomanip": "cpp",
"cstdint": "cpp"
},
"files.exclude": {
"Binaries/*build*": true,

View File

@@ -4,6 +4,9 @@
cmake_minimum_required(VERSION 2.6)
cmake_policy(SET CMP0011 NEW)
# Add utility functions
include(scripts/CMakeClangUtils.txt) # To add clang-format and clang-tidy support to a target
# Macro for defining an option
macro(gd_set_option var default type docstring)
if(NOT DEFINED ${var})

View File

@@ -72,6 +72,10 @@ IF(NO_GUI)
list(REMOVE_ITEM source_files "${CMAKE_CURRENT_SOURCE_DIR}/GDCore/IDE/Dialogs/GDCoreDialogs.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/GDCore/IDE/Dialogs/GDCoreDialogs.h" "${CMAKE_CURRENT_SOURCE_DIR}/GDCore/IDE/Dialogs/GDCoreDialogs_dialogs_bitmaps.cpp")
ENDIF()
file(GLOB_RECURSE formatted_source_files tests/* GDCore/Events/* GDCore/Extensions/* GDCore/IDE/* GDCore/Project/* GDCore/Serialization/* GDCore/Tools/*)
list(REMOVE_ITEM formatted_source_files "${CMAKE_CURRENT_SOURCE_DIR}/GDCore/IDE/Dialogs/GDCoreDialogs.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/GDCore/IDE/Dialogs/GDCoreDialogs.h" "${CMAKE_CURRENT_SOURCE_DIR}/GDCore/IDE/Dialogs/GDCoreDialogs_dialogs_bitmaps.cpp")
gd_add_clang_utils(GDCore "${formatted_source_files}")
add_library(GDCore SHARED ${source_files})
add_dependencies(GDCore GDVersion)
IF(EMSCRIPTEN)

View File

@@ -1,152 +1,189 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#if !defined(GD_NO_WX_GUI)
#include <wx/dcmemory.h>
#endif
#include "CommentEvent.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsRenderingHelper.h"
#include "GDCore/Serialization/SerializerElement.h"
#include "GDCore/CommonTools.h"
#include "GDCore/IDE/Dialogs/EditComment.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsEditorItemsAreas.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsEditorSelection.h"
#include "GDCore/CommonTools.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsRenderingHelper.h"
#include "GDCore/Serialization/SerializerElement.h"
using namespace std;
namespace gd
{
namespace gd {
void CommentEvent::SerializeTo(SerializerElement & element) const
{
element.AddChild("color")
.SetAttribute("r", r)
.SetAttribute("g", v)
.SetAttribute("b", b)
.SetAttribute("textR", textR)
.SetAttribute("textG", textG)
.SetAttribute("textB", textB);
void CommentEvent::SerializeTo(SerializerElement &element) const {
element.AddChild("color")
.SetAttribute("r", r)
.SetAttribute("g", v)
.SetAttribute("b", b)
.SetAttribute("textR", textR)
.SetAttribute("textG", textG)
.SetAttribute("textB", textB);
element.AddChild("comment").SetValue(com1);
element.AddChild("comment2").SetValue(com2);
element.AddChild("comment").SetValue(com1);
element.AddChild("comment2").SetValue(com2);
}
void CommentEvent::UnserializeFrom(gd::Project & project, const SerializerElement & element)
{
const SerializerElement & colorElement = element.GetChild("color", 0, "Couleur");
r = colorElement.GetIntAttribute("r");
v = colorElement.GetIntAttribute("g", 0, "v");
b = colorElement.GetIntAttribute("b");
textR = colorElement.GetIntAttribute("textR");
textG = colorElement.GetIntAttribute("textG");
textB = colorElement.GetIntAttribute("textB");
void CommentEvent::UnserializeFrom(gd::Project &project,
const SerializerElement &element) {
const SerializerElement &colorElement =
element.GetChild("color", 0, "Couleur");
r = colorElement.GetIntAttribute("r");
v = colorElement.GetIntAttribute("g", 0, "v");
b = colorElement.GetIntAttribute("b");
textR = colorElement.GetIntAttribute("textR");
textG = colorElement.GetIntAttribute("textG");
textB = colorElement.GetIntAttribute("textB");
com1 = element.GetChild("comment", 0, "Com1").GetValue().GetString();
com2 = element.GetChild("comment2", 0, "Com2").GetValue().GetString();
com1 = element.GetChild("comment", 0, "Com1").GetValue().GetString();
com2 = element.GetChild("comment2", 0, "Com2").GetValue().GetString();
}
gd::BaseEvent::EditEventReturnType CommentEvent::EditEvent(wxWindow* parent_, gd::Project & game_, gd::Layout & scene_, gd::MainFrameWrapper & mainFrameWrapper_)
{
gd::BaseEvent::EditEventReturnType CommentEvent::EditEvent(
wxWindow *parent_,
gd::Project &game_,
gd::Layout &scene_,
gd::MainFrameWrapper &mainFrameWrapper_) {
#if !defined(GD_NO_WX_GUI)
EditComment dialog(parent_, *this);
if ( dialog.ShowModal() == 0) return Cancelled;
EditComment dialog(parent_, *this);
if (dialog.ShowModal() == 0) return Cancelled;
#endif
return ChangesMadeButNoNeedForEventsRecompilation;
return ChangesMadeButNoNeedForEventsRecompilation;
}
/**
* Render the event
*/
void CommentEvent::Render(wxDC & dc, int x, int y, unsigned int width, gd::EventsEditorItemsAreas & areas, gd::EventsEditorSelection & selection, const gd::Platform &)
{
void CommentEvent::Render(wxDC &dc,
int x,
int y,
unsigned int width,
gd::EventsEditorItemsAreas &areas,
gd::EventsEditorSelection &selection,
const gd::Platform &) {
#if !defined(GD_NO_WX_GUI)
x += 1; //Small border
x += 1; // Small border
gd::EventsRenderingHelper *renderingHelper = gd::EventsRenderingHelper::Get();
renderingHelper->GetHTMLRenderer().SetDC(&dc);
renderingHelper->GetHTMLRenderer().SetStandardFonts(
renderingHelper->GetNiceFont().GetPointSize());
// Prepare HTML texts
gd::String str1 =
"<FONT color=" +
wxColour(textR, textG, textB).GetAsString(wxC2S_HTML_SYNTAX) + ">" +
renderingHelper->GetHTMLText(com1) + "</FONT>";
gd::String str2 =
"<FONT color=" +
wxColour(textR, textG, textB).GetAsString(wxC2S_HTML_SYNTAX) + ">" +
renderingHelper->GetHTMLText(com2) + "</FONT>";
// Calculate space constraints
const int sideSeparation = 3; // Spacing between text and borders
unsigned int textWidth = com2.empty() ? width - sideSeparation * 2
: width / 2 - sideSeparation * 2;
renderingHelper->GetHTMLRenderer().SetSize(textWidth, 9999);
renderingHelper->GetHTMLRenderer().SetHtmlText(str1);
unsigned int text1Height =
renderingHelper->GetHTMLRenderer().GetTotalHeight();
renderingHelper->GetHTMLRenderer().SetHtmlText(str2);
unsigned int text2Height =
renderingHelper->GetHTMLRenderer().GetTotalHeight();
// Prepare background
dc.SetBrush(wxBrush(wxColour(r, v, b), wxBRUSHSTYLE_TRANSPARENT));
dc.SetPen(wxPen(wxColour(r / 2, v / 2, b / 2), 1));
// Draw the background
unsigned int height = std::max(text1Height, text2Height) + sideSeparation * 2;
height = std::max(height, (unsigned int)15);
wxRect rectangle(x, y, width - 2, height);
dc.GradientFillLinear(rectangle,
wxColour(r + 20 > 255 ? 255 : r + 20,
v + 20 > 255 ? 255 : v + 20,
b + 20 > 255 ? 255 : b + 20),
wxColour(r, v, b),
wxSOUTH);
dc.DrawRectangle(rectangle);
// Draw text
{
renderingHelper->GetHTMLRenderer().SetHtmlText(str1);
wxArrayInt neededArray;
renderingHelper->GetHTMLRenderer().Render(
x + sideSeparation, y + sideSeparation, neededArray);
}
if (!com2.empty()) // Optional text
{
renderingHelper->GetHTMLRenderer().SetHtmlText(str2);
wxArrayInt neededArray;
renderingHelper->GetHTMLRenderer().Render(
x + sideSeparation + textWidth + sideSeparation,
y + sideSeparation,
neededArray);
}
#endif
}
unsigned int CommentEvent::GetRenderedHeight(unsigned int width,
const gd::Platform &) const {
#if !defined(GD_NO_WX_GUI)
if (eventHeightNeedUpdate) {
gd::EventsRenderingHelper *renderingHelper =
gd::EventsRenderingHelper::Get();
wxMemoryDC dc;
wxBitmap fakeBmp(1, 1);
dc.SelectObject(fakeBmp);
gd::EventsRenderingHelper * renderingHelper = gd::EventsRenderingHelper::Get();
renderingHelper->GetHTMLRenderer().SetDC(&dc);
renderingHelper->GetHTMLRenderer().SetStandardFonts(renderingHelper->GetNiceFont().GetPointSize());
renderingHelper->GetHTMLRenderer().SetStandardFonts(
renderingHelper->GetNiceFont().GetPointSize());
//Prepare HTML texts
gd::String str1 = "<FONT color="+wxColour(textR, textG, textB).GetAsString(wxC2S_HTML_SYNTAX)+">"+renderingHelper->GetHTMLText(com1)+"</FONT>";
gd::String str2 = "<FONT color="+wxColour(textR, textG, textB).GetAsString(wxC2S_HTML_SYNTAX)+">"+renderingHelper->GetHTMLText(com2)+"</FONT>";
gd::String str1 =
"<FONT color=" +
wxColour(textR, textG, textB).GetAsString(wxC2S_HTML_SYNTAX) + ">" +
renderingHelper->GetHTMLText(com1) + "</FONT>";
gd::String str2 =
"<FONT color=" +
wxColour(textR, textG, textB).GetAsString(wxC2S_HTML_SYNTAX) + ">" +
renderingHelper->GetHTMLText(com2) + "</FONT>";
//Calculate space constraints
const int sideSeparation = 3; //Spacing between text and borders
// Calculate space constraints
const int sideSeparation = 3; // Spacing between text and borders
unsigned int textWidth = com2.empty() ? width-sideSeparation*2 : width/2-sideSeparation*2;
unsigned int textWidth = com2.empty() ? width - sideSeparation * 2
: width / 2 - sideSeparation * 2;
renderingHelper->GetHTMLRenderer().SetSize(textWidth, 9999);
renderingHelper->GetHTMLRenderer().SetHtmlText(str1);
unsigned int text1Height = renderingHelper->GetHTMLRenderer().GetTotalHeight();
unsigned int text1Height =
renderingHelper->GetHTMLRenderer().GetTotalHeight();
renderingHelper->GetHTMLRenderer().SetHtmlText(str2);
unsigned int text2Height = renderingHelper->GetHTMLRenderer().GetTotalHeight();
unsigned int text2Height =
renderingHelper->GetHTMLRenderer().GetTotalHeight();
//Prepare background
dc.SetBrush(wxBrush(wxColour(r, v, b), wxBRUSHSTYLE_TRANSPARENT));
dc.SetPen(wxPen(wxColour(r/2, v/2, b/2), 1));
//Draw the background
unsigned int height = std::max(text1Height, text2Height)+sideSeparation*2;
unsigned int height =
std::max(text1Height, text2Height) + sideSeparation * 2;
height = std::max(height, (unsigned int)15);
wxRect rectangle(x, y, width-2, height);
dc.GradientFillLinear(rectangle, wxColour(r+20 > 255 ? 255 : r+20, v+20 > 255 ? 255 : v+20, b+20 > 255 ? 255 : b+20), wxColour(r, v, b), wxSOUTH);
dc.DrawRectangle(rectangle);
//Draw text
{
renderingHelper->GetHTMLRenderer().SetHtmlText(str1);
wxArrayInt neededArray;
renderingHelper->GetHTMLRenderer().Render(x + sideSeparation, y+sideSeparation, neededArray);
}
if ( !com2.empty() ) //Optional text
{
renderingHelper->GetHTMLRenderer().SetHtmlText(str2);
wxArrayInt neededArray;
renderingHelper->GetHTMLRenderer().Render(x + sideSeparation + textWidth + sideSeparation, y+sideSeparation, neededArray);
}
renderedHeight = height;
}
#endif
return renderedHeight + 2; // 2 : 2 small borders
}
unsigned int CommentEvent::GetRenderedHeight(unsigned int width, const gd::Platform &) const
{
#if !defined(GD_NO_WX_GUI)
if ( eventHeightNeedUpdate )
{
gd::EventsRenderingHelper * renderingHelper = gd::EventsRenderingHelper::Get();
wxMemoryDC dc;
wxBitmap fakeBmp(1,1);
dc.SelectObject(fakeBmp);
renderingHelper->GetHTMLRenderer().SetDC(&dc);
renderingHelper->GetHTMLRenderer().SetStandardFonts(renderingHelper->GetNiceFont().GetPointSize());
gd::String str1 = "<FONT color="+wxColour(textR, textG, textB).GetAsString(wxC2S_HTML_SYNTAX)+">"+renderingHelper->GetHTMLText(com1)+"</FONT>";
gd::String str2 = "<FONT color="+wxColour(textR, textG, textB).GetAsString(wxC2S_HTML_SYNTAX)+">"+renderingHelper->GetHTMLText(com2)+"</FONT>";
//Calculate space constraints
const int sideSeparation = 3; //Spacing between text and borders
unsigned int textWidth = com2.empty() ? width-sideSeparation*2 : width/2-sideSeparation*2;
renderingHelper->GetHTMLRenderer().SetSize(textWidth, 9999);
renderingHelper->GetHTMLRenderer().SetHtmlText(str1);
unsigned int text1Height = renderingHelper->GetHTMLRenderer().GetTotalHeight();
renderingHelper->GetHTMLRenderer().SetHtmlText(str2);
unsigned int text2Height = renderingHelper->GetHTMLRenderer().GetTotalHeight();
unsigned int height = std::max(text1Height, text2Height)+sideSeparation*2;
height = std::max(height, (unsigned int)15);
renderedHeight = height;
}
#endif
return renderedHeight+2;//2 : 2 small borders
}
}
} // namespace gd

View File

@@ -1,74 +1,105 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef COMMENTEVENT_H
#define COMMENTEVENT_H
#include "GDCore/Events/Event.h"
class TiXmlElement;
namespace gd { class Layout; }
namespace gd { class Project; }
namespace gd { class MainFrameWrapper; }
namespace gd { class Project; }
namespace gd {
class Layout;
}
namespace gd {
class Project;
}
namespace gd {
class MainFrameWrapper;
}
namespace gd {
class Project;
}
class wxWindow;
namespace gd { class EventsEditorItemsAreas; }
namespace gd { class EventsEditorSelection; }
namespace gd {
class EventsEditorItemsAreas;
}
namespace gd {
class EventsEditorSelection;
}
namespace gd
{
namespace gd {
/**
* \brief Allows to add a text in the events editor.
*/
class GD_CORE_API CommentEvent : public gd::BaseEvent
{
public:
CommentEvent() : BaseEvent(), r(255), v(230), b(109), textR(0), textG(0), textB(0) {};
virtual ~CommentEvent() {};
virtual gd::CommentEvent * Clone() const { return new CommentEvent(*this);}
class GD_CORE_API CommentEvent : public gd::BaseEvent {
public:
CommentEvent()
: BaseEvent(), r(255), v(230), b(109), textR(0), textG(0), textB(0){};
virtual ~CommentEvent(){};
virtual gd::CommentEvent* Clone() const { return new CommentEvent(*this); }
int GetBackgroundColorRed() const { return r; }
int GetBackgroundColorGreen() const { return v; }
int GetBackgroundColorBlue() const { return b; }
void SetBackgroundColor(int r_, int g_, int b_) { r = r_; v = g_; b = b_; }
int GetBackgroundColorRed() const { return r; }
int GetBackgroundColorGreen() const { return v; }
int GetBackgroundColorBlue() const { return b; }
void SetBackgroundColor(int r_, int g_, int b_) {
r = r_;
v = g_;
b = b_;
}
int GetTextColorRed() const { return textR; }
int GetTextColorGreen() const { return textG; }
int GetTextColorBlue() const { return textB; }
void SetTextColor(int r_, int g_, int b_) { textR = r_; textG = g_; textB = b_; }
int GetTextColorRed() const { return textR; }
int GetTextColorGreen() const { return textG; }
int GetTextColorBlue() const { return textB; }
void SetTextColor(int r_, int g_, int b_) {
textR = r_;
textG = g_;
textB = b_;
}
const gd::String & GetComment() const { return com1; }
void SetComment(const gd::String & comment) { com1 = comment; }
const gd::String& GetComment() const { return com1; }
void SetComment(const gd::String& comment) { com1 = comment; }
virtual void SerializeTo(SerializerElement & element) const;
virtual void UnserializeFrom(gd::Project & project, const SerializerElement & element);
virtual void SerializeTo(SerializerElement& element) const;
virtual void UnserializeFrom(gd::Project& project,
const SerializerElement& element);
int r; ///< Background color Red component
int v; ///< Background color Green component
int b; ///< Background color Blue component
int r; ///< Background color Red component
int v; ///< Background color Green component
int b; ///< Background color Blue component
int textR; ///< Text color Red component
int textG; ///< Text color Green component
int textB; ///< Text color Blue component
int textR; ///< Text color Red component
int textG; ///< Text color Green component
int textB; ///< Text color Blue component
gd::String com1; ///< Comment
gd::String com2; ///< Optional second column comment, deprecated
gd::String com1; ///< Comment
gd::String com2; ///< Optional second column comment, deprecated
/**
* Called by event editor to draw the event.
*/
virtual void Render(wxDC & dc, int x, int y, unsigned int width, gd::EventsEditorItemsAreas & areas, gd::EventsEditorSelection & selection, const gd::Platform & );
/**
* Called by event editor to draw the event.
*/
virtual void Render(wxDC& dc,
int x,
int y,
unsigned int width,
gd::EventsEditorItemsAreas& areas,
gd::EventsEditorSelection& selection,
const gd::Platform&);
/**
* Must return the height of the event when rendered
*/
virtual unsigned int GetRenderedHeight(unsigned int width, const gd::Platform & ) const;
/**
* Must return the height of the event when rendered
*/
virtual unsigned int GetRenderedHeight(unsigned int width,
const gd::Platform&) const;
virtual EditEventReturnType EditEvent(wxWindow* parent_, gd::Project & game_, gd::Layout & scene_, gd::MainFrameWrapper & mainFrameWrapper_);
virtual EditEventReturnType EditEvent(
wxWindow* parent_,
gd::Project& game_,
gd::Layout& scene_,
gd::MainFrameWrapper& mainFrameWrapper_);
};
}
} // namespace gd
#endif // COMMENTEVENT_H
#endif // COMMENTEVENT_H

View File

@@ -1,167 +1,198 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "ForEachEvent.h"
#include <iostream>
#include "GDCore/TinyXml/tinyxml.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsRenderingHelper.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsEditorItemsAreas.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsEditorSelection.h"
#include "GDCore/Serialization/SerializerElement.h"
#include "GDCore/Events/Serialization.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerationContext.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerator.h"
#include "GDCore/Events/CodeGeneration/ExpressionsCodeGeneration.h"
#include "GDCore/Events/Serialization.h"
#include "GDCore/Events/Tools/EventsCodeNameMangler.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerationContext.h"
#include "GDCore/IDE/Dialogs/EditForEachEvent.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsEditorItemsAreas.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsEditorSelection.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsRenderingHelper.h"
#include "GDCore/Serialization/SerializerElement.h"
#include "GDCore/TinyXml/tinyxml.h"
using namespace std;
namespace gd
{
namespace gd {
ForEachEvent::ForEachEvent() :
BaseEvent(),
objectsToPick(""),
objectsToPickSelected(false)
{
ForEachEvent::ForEachEvent()
: BaseEvent(), objectsToPick(""), objectsToPickSelected(false) {}
vector<gd::InstructionsList*> ForEachEvent::GetAllConditionsVectors() {
vector<gd::InstructionsList*> allConditions;
allConditions.push_back(&conditions);
return allConditions;
}
vector < gd::InstructionsList* > ForEachEvent::GetAllConditionsVectors()
{
vector < gd::InstructionsList* > allConditions;
allConditions.push_back(&conditions);
vector<gd::InstructionsList*> ForEachEvent::GetAllActionsVectors() {
vector<gd::InstructionsList*> allActions;
allActions.push_back(&actions);
return allConditions;
return allActions;
}
vector < gd::InstructionsList* > ForEachEvent::GetAllActionsVectors()
{
vector < gd::InstructionsList* > allActions;
allActions.push_back(&actions);
vector<gd::Expression*> ForEachEvent::GetAllExpressions() {
vector<gd::Expression*> allExpressions;
allExpressions.push_back(&objectsToPick);
return allActions;
return allExpressions;
}
vector<const gd::InstructionsList*> ForEachEvent::GetAllConditionsVectors()
const {
vector<const gd::InstructionsList*> allConditions;
allConditions.push_back(&conditions);
return allConditions;
}
vector < gd::Expression* > ForEachEvent::GetAllExpressions()
{
vector < gd::Expression* > allExpressions;
allExpressions.push_back(&objectsToPick);
vector<const gd::InstructionsList*> ForEachEvent::GetAllActionsVectors() const {
vector<const gd::InstructionsList*> allActions;
allActions.push_back(&actions);
return allExpressions;
}
vector < const gd::InstructionsList* > ForEachEvent::GetAllConditionsVectors() const
{
vector < const gd::InstructionsList* > allConditions;
allConditions.push_back(&conditions);
return allConditions;
return allActions;
}
vector < const gd::InstructionsList* > ForEachEvent::GetAllActionsVectors() const
{
vector < const gd::InstructionsList* > allActions;
allActions.push_back(&actions);
vector<const gd::Expression*> ForEachEvent::GetAllExpressions() const {
vector<const gd::Expression*> allExpressions;
allExpressions.push_back(&objectsToPick);
return allActions;
return allExpressions;
}
vector < const gd::Expression* > ForEachEvent::GetAllExpressions() const
{
vector < const gd::Expression* > allExpressions;
allExpressions.push_back(&objectsToPick);
return allExpressions;
void ForEachEvent::SerializeTo(SerializerElement& element) const {
element.AddChild("object").SetValue(objectsToPick.GetPlainString());
gd::EventsListSerialization::SerializeInstructionsTo(
conditions, element.AddChild("conditions"));
gd::EventsListSerialization::SerializeInstructionsTo(
actions, element.AddChild("actions"));
gd::EventsListSerialization::SerializeEventsTo(events,
element.AddChild("events"));
}
void ForEachEvent::SerializeTo(SerializerElement & element) const
{
element.AddChild("object").SetValue(objectsToPick.GetPlainString());
gd::EventsListSerialization::SerializeInstructionsTo(conditions, element.AddChild("conditions"));
gd::EventsListSerialization::SerializeInstructionsTo(actions, element.AddChild("actions"));
gd::EventsListSerialization::SerializeEventsTo(events, element.AddChild("events"));
}
void ForEachEvent::UnserializeFrom(gd::Project & project, const SerializerElement & element)
{
objectsToPick = gd::Expression(element.GetChild("object", 0, "Object").GetValue().GetString());
gd::EventsListSerialization::UnserializeInstructionsFrom(project, conditions, element.GetChild("conditions", 0, "Conditions"));
gd::EventsListSerialization::UnserializeInstructionsFrom(project, actions, element.GetChild("actions", 0, "Actions"));
gd::EventsListSerialization::UnserializeEventsFrom(project, events, element.GetChild("events", 0, "Events"));
void ForEachEvent::UnserializeFrom(gd::Project& project,
const SerializerElement& element) {
objectsToPick = gd::Expression(
element.GetChild("object", 0, "Object").GetValue().GetString());
gd::EventsListSerialization::UnserializeInstructionsFrom(
project, conditions, element.GetChild("conditions", 0, "Conditions"));
gd::EventsListSerialization::UnserializeInstructionsFrom(
project, actions, element.GetChild("actions", 0, "Actions"));
gd::EventsListSerialization::UnserializeEventsFrom(
project, events, element.GetChild("events", 0, "Events"));
}
/**
* Render the event in the bitmap
*/
void ForEachEvent::Render(wxDC & dc, int x, int y, unsigned int width, gd::EventsEditorItemsAreas & areas, gd::EventsEditorSelection & selection, const gd::Platform & platform)
{
void ForEachEvent::Render(wxDC& dc,
int x,
int y,
unsigned int width,
gd::EventsEditorItemsAreas& areas,
gd::EventsEditorSelection& selection,
const gd::Platform& platform) {
#if !defined(GD_NO_WX_GUI)
gd::EventsRenderingHelper * renderingHelper = gd::EventsRenderingHelper::Get();
gd::EventsRenderingHelper* renderingHelper = gd::EventsRenderingHelper::Get();
int border = renderingHelper->instructionsListBorder;
const int forEachTextHeight = 20;
// Draw header rectangle
wxRect headerRect(x, y, width, forEachTextHeight);
renderingHelper->DrawNiceRectangle(dc, headerRect);
// For Each text
dc.SetFont(renderingHelper->GetNiceFont().Bold());
if (!IsDisabled())
dc.SetTextForeground(wxColour(0, 0, 0));
else
dc.SetTextForeground(wxColour(160, 160, 160));
dc.DrawText(_("For each object") + " " + objectsToPick.GetPlainString() +
_(", repeat :"),
x + 4,
y + 3);
// Draw conditions rectangle
wxRect rect(x,
y + forEachTextHeight,
renderingHelper->GetConditionsColumnWidth() + border,
GetRenderedHeight(width, platform) - forEachTextHeight);
renderingHelper->DrawNiceRectangle(dc, rect);
// Draw actions and conditions
renderingHelper->DrawConditionsList(
conditions,
dc,
x + border,
y + forEachTextHeight + border,
renderingHelper->GetConditionsColumnWidth() - border,
this,
areas,
selection,
platform);
renderingHelper->DrawActionsList(
actions,
dc,
x + renderingHelper->GetConditionsColumnWidth() + border,
y + forEachTextHeight + border,
width - renderingHelper->GetConditionsColumnWidth() - border * 2,
this,
areas,
selection,
platform);
#endif
}
unsigned int ForEachEvent::GetRenderedHeight(
unsigned int width, const gd::Platform& platform) const {
#if !defined(GD_NO_WX_GUI)
if (eventHeightNeedUpdate) {
gd::EventsRenderingHelper* renderingHelper =
gd::EventsRenderingHelper::Get();
int border = renderingHelper->instructionsListBorder;
const int forEachTextHeight = 20;
//Draw header rectangle
wxRect headerRect(x, y, width, forEachTextHeight);
renderingHelper->DrawNiceRectangle(dc, headerRect);
// Get maximum height needed
int conditionsHeight = renderingHelper->GetRenderedConditionsListHeight(
conditions,
renderingHelper->GetConditionsColumnWidth() - border,
platform);
int actionsHeight = renderingHelper->GetRenderedActionsListHeight(
actions,
width - renderingHelper->GetConditionsColumnWidth() - border * 2,
platform);
//For Each text
dc.SetFont( renderingHelper->GetNiceFont().Bold() );
if ( !IsDisabled() )
dc.SetTextForeground( wxColour( 0, 0, 0 ) );
else
dc.SetTextForeground( wxColour( 160, 160, 160 ) );
dc.DrawText( _("For each object") + " " + objectsToPick.GetPlainString() + _(", repeat :"), x + 4, y + 3 );
renderedHeight =
((conditionsHeight > actionsHeight ? conditionsHeight : actionsHeight) +
forEachTextHeight) +
border * 2;
eventHeightNeedUpdate = false;
}
//Draw conditions rectangle
wxRect rect(x, y+forEachTextHeight, renderingHelper->GetConditionsColumnWidth()+border, GetRenderedHeight(width, platform)-forEachTextHeight);
renderingHelper->DrawNiceRectangle(dc, rect);
//Draw actions and conditions
renderingHelper->DrawConditionsList(conditions, dc,
x+border,
y+forEachTextHeight+border,
renderingHelper->GetConditionsColumnWidth()-border, this, areas, selection, platform);
renderingHelper->DrawActionsList(actions, dc,
x+renderingHelper->GetConditionsColumnWidth()+border,
y+forEachTextHeight+border,
width-renderingHelper->GetConditionsColumnWidth()-border*2, this, areas, selection, platform);
#endif
}
unsigned int ForEachEvent::GetRenderedHeight(unsigned int width, const gd::Platform & platform) const
{
#if !defined(GD_NO_WX_GUI)
if ( eventHeightNeedUpdate )
{
gd::EventsRenderingHelper * renderingHelper = gd::EventsRenderingHelper::Get();
int border = renderingHelper->instructionsListBorder;
const int forEachTextHeight = 20;
//Get maximum height needed
int conditionsHeight = renderingHelper->GetRenderedConditionsListHeight(conditions, renderingHelper->GetConditionsColumnWidth()-border, platform);
int actionsHeight = renderingHelper->GetRenderedActionsListHeight(actions, width-renderingHelper->GetConditionsColumnWidth()-border*2, platform);
renderedHeight = (( conditionsHeight > actionsHeight ? conditionsHeight : actionsHeight ) + forEachTextHeight)+border*2;
eventHeightNeedUpdate = false;
}
return renderedHeight;
return renderedHeight;
#else
return 0;
return 0;
#endif
}
gd::BaseEvent::EditEventReturnType ForEachEvent::EditEvent(wxWindow* parent_, gd::Project & game_, gd::Layout & scene_, gd::MainFrameWrapper & mainFrameWrapper_)
{
gd::BaseEvent::EditEventReturnType ForEachEvent::EditEvent(
wxWindow* parent_,
gd::Project& game_,
gd::Layout& scene_,
gd::MainFrameWrapper& mainFrameWrapper_) {
#if !defined(GD_NO_WX_GUI)
EditForEachEvent dialog(parent_, *this, game_, scene_);
if ( dialog.ShowModal() == 0 ) return Cancelled;
EditForEachEvent dialog(parent_, *this, game_, scene_);
if (dialog.ShowModal() == 0) return Cancelled;
#endif
return ChangesMade;
return ChangesMade;
}
}
} // namespace gd

View File

@@ -1,7 +1,7 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef FOREACHEVENT_H
@@ -9,79 +9,107 @@
#include "GDCore/Events/Event.h"
#include "GDCore/Events/EventsList.h"
class RuntimeScene;
namespace gd { class Instruction; }
namespace gd { class Project; }
namespace gd { class MainFrameWrapper; }
namespace gd {
class Instruction;
}
namespace gd {
class Project;
}
namespace gd {
class MainFrameWrapper;
}
class TiXmlElement;
namespace gd { class EventsEditorItemsAreas; }
namespace gd { class EventsEditorSelection; }
namespace gd { class Layout; }
namespace gd {
class EventsEditorItemsAreas;
}
namespace gd {
class EventsEditorSelection;
}
namespace gd {
class Layout;
}
class wxWindow;
namespace gd
{
namespace gd {
/**
* \brief Event repeated for each object of a list.
*
* Each time the event is repeated, only the specific object of the list is picked.
* Each time the event is repeated, only the specific object of the list is
* picked.
*/
class GD_CORE_API ForEachEvent : public gd::BaseEvent
{
public:
ForEachEvent();
virtual ~ForEachEvent() {};
virtual gd::ForEachEvent * Clone() const { return new ForEachEvent(*this);}
class GD_CORE_API ForEachEvent : public gd::BaseEvent {
public:
ForEachEvent();
virtual ~ForEachEvent(){};
virtual gd::ForEachEvent* Clone() const { return new ForEachEvent(*this); }
virtual bool IsExecutable() const {return true;}
virtual bool IsExecutable() const { return true; }
virtual bool CanHaveSubEvents() const {return true;}
virtual const gd::EventsList & GetSubEvents() const {return events;};
virtual gd::EventsList & GetSubEvents() {return events;};
virtual bool CanHaveSubEvents() const { return true; }
virtual const gd::EventsList& GetSubEvents() const { return events; };
virtual gd::EventsList& GetSubEvents() { return events; };
const gd::InstructionsList & GetConditions() const { return conditions; };
gd::InstructionsList & GetConditions() { return conditions; };
const gd::InstructionsList& GetConditions() const { return conditions; };
gd::InstructionsList& GetConditions() { return conditions; };
const gd::InstructionsList & GetActions() const { return actions; };
gd::InstructionsList & GetActions() { return actions; };
const gd::InstructionsList& GetActions() const { return actions; };
gd::InstructionsList& GetActions() { return actions; };
const gd::String & GetObjectToPick() const { return objectsToPick.GetPlainString(); };
void SetObjectToPick(gd::String objectsToPick_) { objectsToPick = gd::Expression(objectsToPick_); };
const gd::String& GetObjectToPick() const {
return objectsToPick.GetPlainString();
};
void SetObjectToPick(gd::String objectsToPick_) {
objectsToPick = gd::Expression(objectsToPick_);
};
virtual std::vector < const gd::InstructionsList* > GetAllConditionsVectors() const;
virtual std::vector < const gd::InstructionsList* > GetAllActionsVectors() const;
virtual std::vector < const gd::Expression* > GetAllExpressions() const;
virtual std::vector < gd::InstructionsList* > GetAllConditionsVectors();
virtual std::vector < gd::InstructionsList* > GetAllActionsVectors();
virtual std::vector < gd::Expression* > GetAllExpressions();
virtual std::vector<const gd::InstructionsList*> GetAllConditionsVectors()
const;
virtual std::vector<const gd::InstructionsList*> GetAllActionsVectors() const;
virtual std::vector<const gd::Expression*> GetAllExpressions() const;
virtual std::vector<gd::InstructionsList*> GetAllConditionsVectors();
virtual std::vector<gd::InstructionsList*> GetAllActionsVectors();
virtual std::vector<gd::Expression*> GetAllExpressions();
virtual void SerializeTo(SerializerElement & element) const;
virtual void UnserializeFrom(gd::Project & project, const SerializerElement & element);
virtual void SerializeTo(SerializerElement& element) const;
virtual void UnserializeFrom(gd::Project& project,
const SerializerElement& element);
/**
* Called by event editor to draw the event.
*/
virtual void Render(wxDC & dc, int x, int y, unsigned int width, gd::EventsEditorItemsAreas & areas, gd::EventsEditorSelection & selection, const gd::Platform & platform);
/**
* Called by event editor to draw the event.
*/
virtual void Render(wxDC& dc,
int x,
int y,
unsigned int width,
gd::EventsEditorItemsAreas& areas,
gd::EventsEditorSelection& selection,
const gd::Platform& platform);
/**
* Must return the height of the event when rendered
*/
virtual unsigned int GetRenderedHeight(unsigned int width, const gd::Platform & platform) const;
/**
* Must return the height of the event when rendered
*/
virtual unsigned int GetRenderedHeight(unsigned int width,
const gd::Platform& platform) const;
/**
* Called when the user want to edit the event
*/
virtual EditEventReturnType EditEvent(wxWindow* parent_, gd::Project & game_, gd::Layout & scene_, gd::MainFrameWrapper & mainFrameWrapper_);
/**
* Called when the user want to edit the event
*/
virtual EditEventReturnType EditEvent(
wxWindow* parent_,
gd::Project& game_,
gd::Layout& scene_,
gd::MainFrameWrapper& mainFrameWrapper_);
private:
gd::Expression objectsToPick;
gd::InstructionsList conditions;
gd::InstructionsList actions;
gd::EventsList events;
private:
gd::Expression objectsToPick;
gd::InstructionsList conditions;
gd::InstructionsList actions;
gd::EventsList events;
bool objectsToPickSelected;
bool objectsToPickSelected;
};
}
} // namespace gd
#endif // FOREACHEVENT_H
#endif // FOREACHEVENT_H

View File

@@ -1,7 +1,7 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "GroupEvent.h"
@@ -10,155 +10,154 @@
#include <wx/renderer.h>
#include "GDCore/IDE/Dialogs/MainFrameWrapper.h"
#endif
#include "GDCore/IDE/Dialogs/EventsEditor/EventsRenderingHelper.h"
#include "GDCore/CommonTools.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerationContext.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerator.h"
#include "GDCore/Events/Serialization.h"
#include "GDCore/IDE/Dialogs/EventStoreDialog.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsEditorItemsAreas.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsEditorSelection.h"
#include "GDCore/Events/Serialization.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsRenderingHelper.h"
#include "GDCore/IDE/Dialogs/GroupEventDialog.h"
#include "GDCore/Serialization/SerializerElement.h"
#include "GDCore/TinyXml/tinyxml.h"
#include "GDCore/CommonTools.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerator.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerationContext.h"
#include "GDCore/IDE/Dialogs/GroupEventDialog.h"
#include "GDCore/IDE/Dialogs/EventStoreDialog.h"
using namespace std;
namespace gd
{
namespace gd {
GroupEvent::GroupEvent() :
BaseEvent(),
creationTime(0),
colorR(74),
colorG(176),
colorB(228)
{
GroupEvent::GroupEvent()
: BaseEvent(), creationTime(0), colorR(74), colorG(176), colorB(228) {}
void GroupEvent::SerializeTo(SerializerElement& element) const {
element.SetAttribute("name", name);
element.SetAttribute("source", source);
element.SetAttribute("creationTime", (int)creationTime);
element.SetAttribute("colorR", (int)colorR);
element.SetAttribute("colorG", (int)colorG);
element.SetAttribute("colorB", (int)colorB);
gd::EventsListSerialization::SerializeEventsTo(events,
element.AddChild("events"));
gd::SerializerElement& parametersElement = element.AddChild("parameters");
parametersElement.ConsiderAsArrayOf("parameter");
for (std::size_t i = 0; i < parameters.size(); ++i)
parametersElement.AddChild("parameter").SetValue(parameters[i]);
}
void GroupEvent::SerializeTo(SerializerElement & element) const
{
element.SetAttribute("name", name);
element.SetAttribute("source", source);
element.SetAttribute("creationTime", (int)creationTime);
element.SetAttribute("colorR", (int)colorR);
element.SetAttribute("colorG", (int)colorG);
element.SetAttribute("colorB", (int)colorB);
gd::EventsListSerialization::SerializeEventsTo(events, element.AddChild("events"));
void GroupEvent::UnserializeFrom(gd::Project& project,
const SerializerElement& element) {
name = element.GetStringAttribute("name");
source = element.GetStringAttribute("source");
creationTime = element.GetIntAttribute("creationTime");
colorR = element.GetIntAttribute("colorR");
colorG = element.GetIntAttribute("colorG");
colorB = element.GetIntAttribute("colorB");
gd::EventsListSerialization::UnserializeEventsFrom(
project, events, element.GetChild("events"));
gd::SerializerElement & parametersElement = element.AddChild("parameters");
parametersElement.ConsiderAsArrayOf("parameter");
for ( std::size_t i = 0;i < parameters.size();++i)
parametersElement.AddChild("parameter").SetValue(parameters[i]);
parameters.clear();
gd::SerializerElement& parametersElement = element.GetChild("parameters");
parametersElement.ConsiderAsArrayOf("parameters");
for (std::size_t i = 0; i < parametersElement.GetChildrenCount(); ++i)
parameters.push_back(parametersElement.GetChild(i).GetValue().GetString());
}
void GroupEvent::UnserializeFrom(gd::Project & project, const SerializerElement & element)
{
name = element.GetStringAttribute("name");
source = element.GetStringAttribute("source");
creationTime = element.GetIntAttribute("creationTime");
colorR = element.GetIntAttribute("colorR");
colorG = element.GetIntAttribute("colorG");
colorB = element.GetIntAttribute("colorB");
gd::EventsListSerialization::UnserializeEventsFrom(project, events, element.GetChild("events"));
parameters.clear();
gd::SerializerElement & parametersElement = element.GetChild("parameters");
parametersElement.ConsiderAsArrayOf("parameters");
for ( std::size_t i = 0;i < parametersElement.GetChildrenCount();++i)
parameters.push_back(parametersElement.GetChild(i).GetValue().GetString());
}
gd::BaseEvent::EditEventReturnType GroupEvent::EditEvent(wxWindow* parent_, gd::Project & project, gd::Layout & scene, gd::MainFrameWrapper & mainFrameWrapper)
{
if (events.IsEmpty())
events.InsertNewEvent(project, "BuiltinCommonInstructions::Standard");
gd::BaseEvent::EditEventReturnType GroupEvent::EditEvent(
wxWindow* parent_,
gd::Project& project,
gd::Layout& scene,
gd::MainFrameWrapper& mainFrameWrapper) {
if (events.IsEmpty())
events.InsertNewEvent(project, "BuiltinCommonInstructions::Standard");
#if !defined(GD_NO_WX_GUI)
if (source.empty())
{
GroupEventDialog dialog(parent_, *this);
dialog.ShowModal();
return ChangesMadeButNoNeedForEventsRecompilation;
if (source.empty()) {
GroupEventDialog dialog(parent_, *this);
dialog.ShowModal();
return ChangesMadeButNoNeedForEventsRecompilation;
} else {
gd::EventStoreDialog dialog(parent_, project, scene);
size_t found = source.rfind("/");
if (found != gd::String::npos && found < source.size() - 1) {
gd::String sourceId = source.substr(found + 1, source.size());
dialog.RefreshWith(sourceId, parameters);
}
else
{
gd::EventStoreDialog dialog(parent_, project, scene);
size_t found = source.rfind("/");
if (found != gd::String::npos && found < source.size()-1) {
gd::String sourceId = source.substr(found+1, source.size());
dialog.RefreshWith(sourceId, parameters);
}
if (dialog.ShowModal() != 1) return Cancelled;
if (dialog.ShowModal() != 1) return Cancelled;
//Insert new events
*this = dialog.GetGroupEvent();
return ChangesMade;
}
// Insert new events
*this = dialog.GetGroupEvent();
return ChangesMade;
}
#else
return Cancelled;
return Cancelled;
#endif
}
void GroupEvent::SetBackgroundColor(unsigned int colorR_, unsigned int colorG_, unsigned int colorB_)
{
colorR = colorR_;
colorG = colorG_;
colorB = colorB_;
void GroupEvent::SetBackgroundColor(unsigned int colorR_,
unsigned int colorG_,
unsigned int colorB_) {
colorR = colorR_;
colorG = colorG_;
colorB = colorB_;
}
/**
* Render the event in the bitmap
*/
void GroupEvent::Render(wxDC & dc, int x, int y, unsigned int width, gd::EventsEditorItemsAreas & areas, gd::EventsEditorSelection & selection, const gd::Platform & platform)
{
void GroupEvent::Render(wxDC& dc,
int x,
int y,
unsigned int width,
gd::EventsEditorItemsAreas& areas,
gd::EventsEditorSelection& selection,
const gd::Platform& platform) {
#if !defined(GD_NO_WX_GUI)
wxString groupTitle = name.empty() ? _("Untitled group") : wxString(name);
wxColour backgroundColor = wxColour(colorR, colorG, colorB);
wxColour textColor = colorR + colorG + colorB > 200 * 3 ? *wxBLACK : *wxWHITE;
if (IsDisabled()) {
backgroundColor.MakeDisabled();
textColor = wxColour(160, 160, 160);
}
dc.SetBrush(wxBrush(backgroundColor));
dc.SetPen(wxPen(backgroundColor.ChangeLightness(70)));
wxRect rect(x + 1, y, width - 2, GetRenderedHeight(width, platform) - 2);
dc.DrawRectangle(rect);
dc.SetTextBackground(backgroundColor);
dc.SetTextForeground(textColor);
dc.SetFont(
wxFont(12, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));
dc.DrawText(groupTitle, x + 5, y + 5);
#endif
}
unsigned int GroupEvent::GetRenderedHeight(unsigned int width,
const gd::Platform& platform) const {
#if !defined(GD_NO_WX_GUI)
if (eventHeightNeedUpdate) {
wxMemoryDC dc;
wxBitmap fakeBmp(1, 1);
dc.SelectObject(fakeBmp);
wxString groupTitle = name.empty() ? _("Untitled group") : wxString(name);
wxColour backgroundColor = wxColour(colorR, colorG, colorB);
wxColour textColor = colorR + colorG + colorB > 200*3 ? *wxBLACK : *wxWHITE;
if (IsDisabled())
{
backgroundColor.MakeDisabled();
textColor = wxColour(160, 160, 160);
}
dc.SetBrush(wxBrush(backgroundColor));
dc.SetPen(wxPen(backgroundColor.ChangeLightness(70)));
wxRect rect(x+1, y, width-2, GetRenderedHeight(width, platform)-2);
dc.DrawRectangle(rect);
dc.SetFont(wxFont(
12, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
wxRect text = dc.GetTextExtent(groupTitle);
dc.SetTextBackground(backgroundColor);
dc.SetTextForeground(textColor);
dc.SetFont( wxFont( 12, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD ) );
dc.DrawText( groupTitle, x+5, y + 5 );
#endif
}
renderedHeight = text.GetHeight() + 10;
eventHeightNeedUpdate = false;
}
unsigned int GroupEvent::GetRenderedHeight(unsigned int width, const gd::Platform & platform) const
{
#if !defined(GD_NO_WX_GUI)
if ( eventHeightNeedUpdate )
{
wxMemoryDC dc;
wxBitmap fakeBmp(1,1);
dc.SelectObject(fakeBmp);
wxString groupTitle = name.empty() ? _("Untitled group") : wxString(name);
dc.SetFont( wxFont( 12, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ) );
wxRect text = dc.GetTextExtent(groupTitle);
renderedHeight = text.GetHeight()+10;
eventHeightNeedUpdate = false;
}
return renderedHeight;
return renderedHeight;
#else
return 0;
return 0;
#endif
}
}
} // namespace gd

View File

@@ -1,136 +1,165 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#if defined(GD_IDE_ONLY)
#ifndef GDCORE_GROUPEVENT_H
#define GDCORE_GROUPEVENT_H
#include "GDCore/Events/Event.h"
#include "GDCore/Events/Instruction.h"
#include "GDCore/Events/EventsList.h"
namespace gd { class Instruction; }
namespace gd { class Project; }
#include "GDCore/Events/Instruction.h"
namespace gd {
class Instruction;
}
namespace gd {
class Project;
}
class RuntimeScene;
class TiXmlElement;
class EventsCodeGenerationContext;
namespace gd { class EventsEditorItemsAreas; }
namespace gd { class EventsEditorSelection; }
namespace gd
{
/**
* \brief A group event, containing only sub events and some (visual only) properties.
*/
class GD_CORE_API GroupEvent : public gd::BaseEvent
{
public:
GroupEvent();
virtual ~GroupEvent() {};
virtual gd::GroupEvent * Clone() const { return new GroupEvent(*this);}
virtual bool IsExecutable() const {return true;}
/**
* \brief Get the name of the group.
*/
const gd::String & GetName() const { return name; }
/**
* \brief Change the name of the group.
*/
void SetName(const gd::String & name_) { name = name_; }
/**
* \brief Get the source of the group.
* \note The source is usually an URL from which
* the group and its events was downloaded.
*/
const gd::String & GetSource() const { return source; }
/**
* \brief Set the source of the group.
*/
void SetSource(const gd::String & source_) { source = source_; }
/**
* \brief Get the vector containing the parameters that have been used to
* create the group and its sub events.
* \note These parameters are optional and only used to remember how the
* group was created from an events template for example: if the user wants
* to update the group with a new version of the template, the parameters
* can be displayed again to easy the update.
*/
std::vector<gd::String> & GetCreationParameters() { return parameters; }
const std::vector<gd::String> & GetCreationParameters() const { return parameters; }
/**
* \brief Return the creation timestamp
* \return The timestamp, or 0 if not specified for the group.
*/
unsigned int GetCreationTimestamp() const { return creationTime; }
/**
* \brief Set timestamp of the creation of the group.
* \note This is purely optional and only used for checking for example if
* a new version of the group is available, if it has a source URL.
*/
void SetCreationTimestamp(unsigned int creationTime_) { creationTime = creationTime_; }
/**
* \brief Change the color of the group
*/
void SetBackgroundColor(unsigned int colorR, unsigned int colorG, unsigned int colorB);
/**
* \brief Get background color red component.
*/
unsigned int GetBackgroundColorR() const { return colorR; };
/**
* \brief Get background color green component.
*/
unsigned int GetBackgroundColorG() const { return colorG; };
/**
* \brief Get background color blue component.
*/
unsigned int GetBackgroundColorB() const { return colorB; };
virtual bool CanHaveSubEvents() const {return true;}
virtual const gd::EventsList & GetSubEvents() const {return events;};
virtual gd::EventsList & GetSubEvents() {return events;};
virtual void SerializeTo(SerializerElement & element) const;
virtual void UnserializeFrom(gd::Project & project, const SerializerElement & element);
virtual gd::BaseEvent::EditEventReturnType EditEvent(wxWindow* parent_, gd::Project & project, gd::Layout & scene, gd::MainFrameWrapper & mainFrameWrapper);
/**
* Called by event editor to draw the event.
*/
virtual void Render(wxDC & dc, int x, int y, unsigned int width, gd::EventsEditorItemsAreas & areas, gd::EventsEditorSelection & selection, const gd::Platform & platform);
/**
* Must return the height of the event when rendered
*/
virtual unsigned int GetRenderedHeight(unsigned int width, const gd::Platform & platform) const;
private:
EventsList events;
gd::String name; ///<Optional. A name displayed in the events editor.
gd::String source; ///< Optional. The source can contains the URL from which the group was downloaded.
unsigned int creationTime; ///< Optional. The time when the group was created from an event template.
std::vector<gd::String> parameters; ///< Optional. Can be used to remember the parameters used if the group was created from an events template.
unsigned int colorR;
unsigned int colorG;
unsigned int colorB;
};
namespace gd {
class EventsEditorItemsAreas;
}
namespace gd {
class EventsEditorSelection;
}
#endif // GDCORE_GROUPEVENT_H
namespace gd {
/**
* \brief A group event, containing only sub events and some (visual only)
* properties.
*/
class GD_CORE_API GroupEvent : public gd::BaseEvent {
public:
GroupEvent();
virtual ~GroupEvent(){};
virtual gd::GroupEvent* Clone() const { return new GroupEvent(*this); }
virtual bool IsExecutable() const { return true; }
/**
* \brief Get the name of the group.
*/
const gd::String& GetName() const { return name; }
/**
* \brief Change the name of the group.
*/
void SetName(const gd::String& name_) { name = name_; }
/**
* \brief Get the source of the group.
* \note The source is usually an URL from which
* the group and its events was downloaded.
*/
const gd::String& GetSource() const { return source; }
/**
* \brief Set the source of the group.
*/
void SetSource(const gd::String& source_) { source = source_; }
/**
* \brief Get the vector containing the parameters that have been used to
* create the group and its sub events.
* \note These parameters are optional and only used to remember how the
* group was created from an events template for example: if the user wants
* to update the group with a new version of the template, the parameters
* can be displayed again to easy the update.
*/
std::vector<gd::String>& GetCreationParameters() { return parameters; }
const std::vector<gd::String>& GetCreationParameters() const {
return parameters;
}
/**
* \brief Return the creation timestamp
* \return The timestamp, or 0 if not specified for the group.
*/
unsigned int GetCreationTimestamp() const { return creationTime; }
/**
* \brief Set timestamp of the creation of the group.
* \note This is purely optional and only used for checking for example if
* a new version of the group is available, if it has a source URL.
*/
void SetCreationTimestamp(unsigned int creationTime_) {
creationTime = creationTime_;
}
/**
* \brief Change the color of the group
*/
void SetBackgroundColor(unsigned int colorR,
unsigned int colorG,
unsigned int colorB);
/**
* \brief Get background color red component.
*/
unsigned int GetBackgroundColorR() const { return colorR; };
/**
* \brief Get background color green component.
*/
unsigned int GetBackgroundColorG() const { return colorG; };
/**
* \brief Get background color blue component.
*/
unsigned int GetBackgroundColorB() const { return colorB; };
virtual bool CanHaveSubEvents() const { return true; }
virtual const gd::EventsList& GetSubEvents() const { return events; };
virtual gd::EventsList& GetSubEvents() { return events; };
virtual void SerializeTo(SerializerElement& element) const;
virtual void UnserializeFrom(gd::Project& project,
const SerializerElement& element);
virtual gd::BaseEvent::EditEventReturnType EditEvent(
wxWindow* parent_,
gd::Project& project,
gd::Layout& scene,
gd::MainFrameWrapper& mainFrameWrapper);
/**
* Called by event editor to draw the event.
*/
virtual void Render(wxDC& dc,
int x,
int y,
unsigned int width,
gd::EventsEditorItemsAreas& areas,
gd::EventsEditorSelection& selection,
const gd::Platform& platform);
/**
* Must return the height of the event when rendered
*/
virtual unsigned int GetRenderedHeight(unsigned int width,
const gd::Platform& platform) const;
private:
EventsList events;
gd::String name; ///< Optional. A name displayed in the events editor.
gd::String source; ///< Optional. The source can contains the URL from which
///< the group was downloaded.
unsigned int creationTime; ///< Optional. The time when the group was created
///< from an event template.
std::vector<gd::String>
parameters; ///< Optional. Can be used to remember the parameters used if
///< the group was created from an events template.
unsigned int colorR;
unsigned int colorG;
unsigned int colorB;
};
} // namespace gd
#endif // GDCORE_GROUPEVENT_H
#endif

View File

@@ -1,246 +1,250 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include <iostream>
#include <fstream>
#include <iostream>
#if !defined(GD_NO_WX_GUI)
#include <wx/dcmemory.h>
#endif
#include "GDCore/IDE/wxTools/SkinHelper.h"
#include "GDCore/Serialization/SerializerElement.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsRenderingHelper.h"
#include "GDCore/Project/Object.h"
#include "GDCore/Project/Project.h"
#include "GDCore/Project/Layout.h"
#include "GDCore/Project/ExternalEvents.h"
#include "GDCore/CommonTools.h"
#include "GDCore/Events/Builtin/GroupEvent.h"
#include "GDCore/Events/Builtin/LinkEvent.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerationContext.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerator.h"
#include "GDCore/Events/Tools/EventsCodeNameMangler.h"
#include "GDCore/Events/Builtin/LinkEvent.h"
#include "GDCore/Events/Builtin/GroupEvent.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsRenderingHelper.h"
#include "GDCore/IDE/Dialogs/LinkEventEditor.h"
#include "GDCore/CommonTools.h"
#include "GDCore/IDE/wxTools/SkinHelper.h"
#include "GDCore/Project/ExternalEvents.h"
#include "GDCore/Project/Layout.h"
#include "GDCore/Project/Object.h"
#include "GDCore/Project/Project.h"
#include "GDCore/Serialization/SerializerElement.h"
using namespace std;
namespace gd
{
namespace gd {
const EventsList * LinkEvent::GetLinkedEvents(const gd::Project & project) const
{
const EventsList * events = nullptr;
const gd::ExternalEvents * linkedExternalEvents = nullptr;
if ( project.HasExternalEventsNamed(GetTarget()) )
{
linkedExternalEvents = &project.GetExternalEvents(GetTarget());
events = &project.GetExternalEvents(GetTarget()).GetEvents();
}
else if ( project.HasLayoutNamed(GetTarget()) )
events = &project.GetLayout(GetTarget()).GetEvents();
const EventsList* LinkEvent::GetLinkedEvents(const gd::Project& project) const {
const EventsList* events = nullptr;
const gd::ExternalEvents* linkedExternalEvents = nullptr;
if (project.HasExternalEventsNamed(GetTarget())) {
linkedExternalEvents = &project.GetExternalEvents(GetTarget());
events = &project.GetExternalEvents(GetTarget()).GetEvents();
} else if (project.HasLayoutNamed(GetTarget()))
events = &project.GetLayout(GetTarget()).GetEvents();
//If the link only includes an events group, search it inside the layout/external events
if( includeConfig == INCLUDE_EVENTS_GROUP )
{
std::size_t i = 0;
std::size_t eventsCount = events->GetEventsCount();
for( ; i < eventsCount; ++i )
{
std::shared_ptr<const GroupEvent> groupEvent = std::dynamic_pointer_cast<const GroupEvent>(events->GetEventSmartPtr(i));
if(groupEvent && groupEvent->GetName() == eventsGroupName)
{
//Get its sub-events
events = &groupEvent->GetSubEvents();
break;
}
}
if(i >= eventsCount) //We didn't find the events group, return nullptr
events = nullptr;
// If the link only includes an events group, search it inside the
// layout/external events
if (includeConfig == INCLUDE_EVENTS_GROUP) {
std::size_t i = 0;
std::size_t eventsCount = events->GetEventsCount();
for (; i < eventsCount; ++i) {
std::shared_ptr<const GroupEvent> groupEvent =
std::dynamic_pointer_cast<const GroupEvent>(
events->GetEventSmartPtr(i));
if (groupEvent && groupEvent->GetName() == eventsGroupName) {
// Get its sub-events
events = &groupEvent->GetSubEvents();
break;
}
}
return events;
if (i >= eventsCount) // We didn't find the events group, return nullptr
events = nullptr;
}
return events;
}
void LinkEvent::ReplaceLinkByLinkedEvents(const gd::Project & project, EventsList & eventList, std::size_t indexOfTheEventInThisList)
{
linkWasInvalid = false;
//Finding what to link to.
const EventsList * eventsToInclude = GetLinkedEvents(project);
if ( eventsToInclude != NULL )
{
std::size_t firstEvent = includeConfig == INCLUDE_BY_INDEX ? GetIncludeStart() : 0;
std::size_t lastEvent = includeConfig == INCLUDE_BY_INDEX ? GetIncludeEnd() : eventsToInclude->size() - 1;
void LinkEvent::ReplaceLinkByLinkedEvents(
const gd::Project& project,
EventsList& eventList,
std::size_t indexOfTheEventInThisList) {
linkWasInvalid = false;
// Finding what to link to.
const EventsList* eventsToInclude = GetLinkedEvents(project);
if (eventsToInclude != NULL) {
std::size_t firstEvent =
includeConfig == INCLUDE_BY_INDEX ? GetIncludeStart() : 0;
std::size_t lastEvent = includeConfig == INCLUDE_BY_INDEX
? GetIncludeEnd()
: eventsToInclude->size() - 1;
//Check bounds
if ( firstEvent >= eventsToInclude->size() )
{
std::cout << "Unable to get events from a link ( Invalid start )" << std::endl;
linkWasInvalid = true;
return;
}
if ( lastEvent >= eventsToInclude->size() )
{
std::cout << "Unable to get events from a link ( Invalid end )" << std::endl;
linkWasInvalid = true;
return;
}
if ( firstEvent > lastEvent )
{
std::cout << "Unable to get events from a link ( End is before start )" << std::endl;
linkWasInvalid = true;
return;
}
//Insert an empty event to replace the link event ( we'll delete the link event at the end )
//( If we just erase the link event without adding a blank event to replace it,
//the first event inserted by the link will not be preprocessed ( and it can be annoying if it require preprocessing, such as another link event ). )
gd::EmptyEvent emptyEvent;
eventList.InsertEvent(emptyEvent, indexOfTheEventInThisList);
eventList.InsertEvents(*eventsToInclude, firstEvent, lastEvent, indexOfTheEventInThisList+1);
//Delete the link event ( which is now at the end of the list of events we've just inserted )
eventList.RemoveEvent(indexOfTheEventInThisList + 1 + static_cast<unsigned>(lastEvent-firstEvent)+1);
// Check bounds
if (firstEvent >= eventsToInclude->size()) {
std::cout << "Unable to get events from a link ( Invalid start )"
<< std::endl;
linkWasInvalid = true;
return;
}
else
{
std::cout << "Unable to get events from a link." << std::endl;
linkWasInvalid = true;
//Delete the link event
eventList.RemoveEvent(indexOfTheEventInThisList);
return;
if (lastEvent >= eventsToInclude->size()) {
std::cout << "Unable to get events from a link ( Invalid end )"
<< std::endl;
linkWasInvalid = true;
return;
}
if (firstEvent > lastEvent) {
std::cout << "Unable to get events from a link ( End is before start )"
<< std::endl;
linkWasInvalid = true;
return;
}
// Insert an empty event to replace the link event ( we'll delete the link
// event at the end ) ( If we just erase the link event without adding a
// blank event to replace it, the first event inserted by the link will not
// be preprocessed ( and it can be annoying if it require preprocessing,
// such as another link event ). )
gd::EmptyEvent emptyEvent;
eventList.InsertEvent(emptyEvent, indexOfTheEventInThisList);
eventList.InsertEvents(
*eventsToInclude, firstEvent, lastEvent, indexOfTheEventInThisList + 1);
// Delete the link event ( which is now at the end of the list of events
// we've just inserted )
eventList.RemoveEvent(indexOfTheEventInThisList + 1 +
static_cast<unsigned>(lastEvent - firstEvent) + 1);
} else {
std::cout << "Unable to get events from a link." << std::endl;
linkWasInvalid = true;
// Delete the link event
eventList.RemoveEvent(indexOfTheEventInThisList);
return;
}
}
LinkEvent::~LinkEvent()
{
LinkEvent::~LinkEvent() {}
void LinkEvent::SerializeTo(SerializerElement& element) const {
SerializerElement& includeElement = element.AddChild("include").SetAttribute(
"includeConfig", static_cast<int>(GetIncludeConfig()));
if (GetIncludeConfig() == INCLUDE_EVENTS_GROUP) {
includeElement.SetAttribute("eventsGroup", GetEventsGroupName());
} else if (GetIncludeConfig() == INCLUDE_BY_INDEX) {
includeElement.SetAttribute("start", static_cast<int>(GetIncludeStart()));
includeElement.SetAttribute("end", static_cast<int>(GetIncludeEnd()));
}
element.AddChild("target").SetValue(GetTarget());
}
void LinkEvent::SerializeTo(SerializerElement & element) const
{
SerializerElement & includeElement = element.AddChild("include")
.SetAttribute("includeConfig", static_cast<int>(GetIncludeConfig()));
void LinkEvent::UnserializeFrom(gd::Project& project,
const SerializerElement& element) {
SerializerElement& includeElement = element.GetChild("include", 0, "Limites");
if(GetIncludeConfig() == INCLUDE_EVENTS_GROUP)
{
includeElement.SetAttribute("eventsGroup", GetEventsGroupName());
}
else if(GetIncludeConfig() == INCLUDE_BY_INDEX)
{
includeElement.SetAttribute("start", static_cast<int>(GetIncludeStart()));
includeElement.SetAttribute("end", static_cast<int>(GetIncludeEnd()));
}
SetTarget(element.GetChild("target", 0, "Scene").GetValue().GetString());
element.AddChild("target").SetValue(GetTarget());
if (includeElement.HasAttribute("includeAll")) {
// Compatibility with GDevelop <= 4.0.92
if (includeElement.GetBoolAttribute("includeAll", true)) {
SetIncludeAllEvents();
} else {
SetIncludeStartAndEnd(includeElement.GetIntAttribute("start"),
includeElement.GetIntAttribute("end"));
}
} else {
// GDevelop > 4.0.92
IncludeConfig config = static_cast<IncludeConfig>(
includeElement.GetIntAttribute("includeConfig", 0));
if (config == INCLUDE_ALL)
SetIncludeAllEvents();
else if (config == INCLUDE_EVENTS_GROUP)
SetIncludeEventsGroup(includeElement.GetStringAttribute("eventsGroup"));
else if (config == INCLUDE_BY_INDEX)
SetIncludeStartAndEnd(includeElement.GetIntAttribute("start"),
includeElement.GetIntAttribute("end"));
}
}
void LinkEvent::UnserializeFrom(gd::Project & project, const SerializerElement & element)
{
SerializerElement & includeElement = element.GetChild("include", 0, "Limites");
SetTarget(element.GetChild("target", 0, "Scene").GetValue().GetString());
if(includeElement.HasAttribute("includeAll"))
{
//Compatibility with GDevelop <= 4.0.92
if(includeElement.GetBoolAttribute("includeAll", true))
{
SetIncludeAllEvents();
}
else
{
SetIncludeStartAndEnd(includeElement.GetIntAttribute("start"),
includeElement.GetIntAttribute("end"));
}
}
else
{
//GDevelop > 4.0.92
IncludeConfig config = static_cast<IncludeConfig>(includeElement.GetIntAttribute("includeConfig", 0));
if(config == INCLUDE_ALL)
SetIncludeAllEvents();
else if(config == INCLUDE_EVENTS_GROUP)
SetIncludeEventsGroup(includeElement.GetStringAttribute("eventsGroup"));
else if(config == INCLUDE_BY_INDEX)
SetIncludeStartAndEnd(includeElement.GetIntAttribute("start"), includeElement.GetIntAttribute("end"));
}
}
gd::BaseEvent::EditEventReturnType LinkEvent::EditEvent(wxWindow* parent_, gd::Project & project, gd::Layout & scene_, gd::MainFrameWrapper & mainFrameWrapper_)
{
gd::BaseEvent::EditEventReturnType LinkEvent::EditEvent(
wxWindow* parent_,
gd::Project& project,
gd::Layout& scene_,
gd::MainFrameWrapper& mainFrameWrapper_) {
#if !defined(GD_NO_WX_GUI)
LinkEventEditor dialog(parent_, *this, project);
if ( dialog.ShowModal() == 0 ) return Cancelled;
LinkEventEditor dialog(parent_, *this, project);
if (dialog.ShowModal() == 0) return Cancelled;
#endif
return ChangesMade;
return ChangesMade;
}
/**
* Render the event in the bitmap
*/
void LinkEvent::Render(wxDC & dc, int x, int y, unsigned int width, gd::EventsEditorItemsAreas & areas, gd::EventsEditorSelection & selection, const gd::Platform & platform)
{
void LinkEvent::Render(wxDC& dc,
int x,
int y,
unsigned int width,
gd::EventsEditorItemsAreas& areas,
gd::EventsEditorSelection& selection,
const gd::Platform& platform) {
#if !defined(GD_NO_WX_GUI)
gd::EventsRenderingHelper * renderingHelper = gd::EventsRenderingHelper::Get();
gd::EventsRenderingHelper* renderingHelper = gd::EventsRenderingHelper::Get();
dc.SetBrush( wxBrush( wxColour( 255, 255, 255 ) ) );
dc.SetPen( wxPen( wxColour( 0, 0, 0 ), 1) );
wxRect rect(x+1, y, width-2, GetRenderedHeight(width, platform)-2);
dc.DrawRectangle(rect);
dc.SetBrush(wxBrush(wxColour(255, 255, 255)));
dc.SetPen(wxPen(wxColour(0, 0, 0), 1));
wxRect rect(x + 1, y, width - 2, GetRenderedHeight(width, platform) - 2);
dc.DrawRectangle(rect);
dc.DrawBitmap( gd::SkinHelper::GetIcon("events", 24), x+4, y + 1, true);
dc.DrawBitmap(gd::SkinHelper::GetIcon("events", 24), x + 4, y + 1, true);
dc.SetTextBackground( wxColour( 255, 255, 255 ) );
if ( !IsDisabled() )
dc.SetTextForeground( wxColour( 0, 0, 0 ) );
else
dc.SetTextForeground( wxColour( 160, 160, 160 ) );
dc.SetTextBackground(wxColour(255, 255, 255));
if (!IsDisabled())
dc.SetTextForeground(wxColour(0, 0, 0));
else
dc.SetTextForeground(wxColour(160, 160, 160));
dc.SetFont(renderingHelper->GetNiceFont());
dc.DrawText( _("Link to ")+GetTarget(), x+32, y + 3 );
dc.SetFont(renderingHelper->GetNiceFont());
dc.DrawText(_("Link to ") + GetTarget(), x + 32, y + 3);
if ( GetIncludeConfig() == INCLUDE_BY_INDEX )
{
wxRect textRect = dc.GetTextExtent(_("Link to ")+GetTarget());
dc.DrawText( _("Include only events ")+gd::String::From(GetIncludeStart()+1)+_(" to ")+gd::String::From(GetIncludeEnd()+1), x+textRect.GetWidth()+32+10, y + 5 );
}
else if ( GetIncludeConfig() == INCLUDE_EVENTS_GROUP )
{
wxRect textRect = dc.GetTextExtent(_("Link to ")+GetTarget());
dc.DrawText( _("Include only the events group named \"")+gd::String::From(GetEventsGroupName())+_("\""), x+textRect.GetWidth()+32+10, y + 5 );
}
if (GetIncludeConfig() == INCLUDE_BY_INDEX) {
wxRect textRect = dc.GetTextExtent(_("Link to ") + GetTarget());
dc.DrawText(_("Include only events ") +
gd::String::From(GetIncludeStart() + 1) + _(" to ") +
gd::String::From(GetIncludeEnd() + 1),
x + textRect.GetWidth() + 32 + 10,
y + 5);
} else if (GetIncludeConfig() == INCLUDE_EVENTS_GROUP) {
wxRect textRect = dc.GetTextExtent(_("Link to ") + GetTarget());
dc.DrawText(_("Include only the events group named \"") +
gd::String::From(GetEventsGroupName()) + _("\""),
x + textRect.GetWidth() + 32 + 10,
y + 5);
}
#endif
}
/**
* Precompute height for the link
*/
unsigned int LinkEvent::GetRenderedHeight(unsigned int width, const gd::Platform & platform) const
{
unsigned int LinkEvent::GetRenderedHeight(unsigned int width,
const gd::Platform& platform) const {
#if !defined(GD_NO_WX_GUI)
if ( eventHeightNeedUpdate )
{
gd::EventsRenderingHelper * renderingHelper = gd::EventsRenderingHelper::Get();
if (eventHeightNeedUpdate) {
gd::EventsRenderingHelper* renderingHelper =
gd::EventsRenderingHelper::Get();
wxMemoryDC dc;
wxBitmap fakeBmp(1,1);
dc.SelectObject(fakeBmp);
wxMemoryDC dc;
wxBitmap fakeBmp(1, 1);
dc.SelectObject(fakeBmp);
dc.SetFont(renderingHelper->GetNiceFont());
wxRect lien = dc.GetTextExtent(_("Link to "));
dc.SetFont(renderingHelper->GetNiceFont());
wxRect lien = dc.GetTextExtent(_("Link to "));
renderedHeight = lien.GetHeight()+15;
eventHeightNeedUpdate = false;
}
renderedHeight = lien.GetHeight() + 15;
eventHeightNeedUpdate = false;
}
return renderedHeight;
return renderedHeight;
#else
return 0;
return 0;
#endif
}
}
} // namespace gd

View File

@@ -1,123 +1,164 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_LINKEVENT_H
#define GDCORE_LINKEVENT_H
#include "GDCore/Events/Event.h"
#include "GDCore/String.h"
namespace gd
{
namespace gd {
/**
* \brief A link pointing to external events (or events of another layout) that should be included
* and run instead of the link.
* \brief A link pointing to external events (or events of another layout) that
* should be included and run instead of the link.
*/
class GD_CORE_API LinkEvent : public gd::BaseEvent
{
public:
enum IncludeConfig
{
INCLUDE_ALL = 0,
INCLUDE_EVENTS_GROUP = 1,
INCLUDE_BY_INDEX = 2 // Deprecated
};
class GD_CORE_API LinkEvent : public gd::BaseEvent {
public:
enum IncludeConfig {
INCLUDE_ALL = 0,
INCLUDE_EVENTS_GROUP = 1,
INCLUDE_BY_INDEX = 2 // Deprecated
};
LinkEvent() : BaseEvent(), includeConfig(INCLUDE_ALL), eventsGroupName(), includeStart(gd::String::npos), includeEnd(gd::String::npos), linkWasInvalid(false) {};
virtual ~LinkEvent();
virtual gd::LinkEvent * Clone() const { return new LinkEvent(*this); }
LinkEvent()
: BaseEvent(),
includeConfig(INCLUDE_ALL),
eventsGroupName(),
includeStart(gd::String::npos),
includeEnd(gd::String::npos),
linkWasInvalid(false){};
virtual ~LinkEvent();
virtual gd::LinkEvent* Clone() const { return new LinkEvent(*this); }
/**
* Get the link target (i.e. the scene or external events the link refers to).
*/
const gd::String & GetTarget() const { return target; };
/**
* Get the link target (i.e. the scene or external events the link refers to).
*/
const gd::String& GetTarget() const { return target; };
/**
* Change the link target (i.e. the scene or external events the link refers to).
*/
void SetTarget(const gd::String & target_) { target = target_; };
/**
* Change the link target (i.e. the scene or external events the link refers
* to).
*/
void SetTarget(const gd::String& target_) { target = target_; };
/**
* Return the include config.
*/
IncludeConfig GetIncludeConfig() const { return includeConfig; }
/**
* Return the include config.
*/
IncludeConfig GetIncludeConfig() const { return includeConfig; }
/**
* Return true if the link event must include all the events of the target.
*/
void SetIncludeAllEvents() { includeConfig = INCLUDE_ALL; }
/**
* Return true if the link event must include all the events of the target.
*/
void SetIncludeAllEvents() { includeConfig = INCLUDE_ALL; }
void SetIncludeEventsGroup(const gd::String& name) { includeConfig = INCLUDE_EVENTS_GROUP; eventsGroupName = name; }
void SetIncludeEventsGroup(const gd::String& name) {
includeConfig = INCLUDE_EVENTS_GROUP;
eventsGroupName = name;
}
/**
* Set the number of the first and last event to be included ( Meaningful only if includeAll was set to false, see SetIncludeAllEvents )
*/
void SetIncludeStartAndEnd(std::size_t includeStart_, std::size_t includeEnd_) { includeConfig = INCLUDE_BY_INDEX; includeStart = includeStart_; includeEnd = includeEnd_; }
/**
* Set the number of the first and last event to be included ( Meaningful only
* if includeAll was set to false, see SetIncludeAllEvents )
*/
void SetIncludeStartAndEnd(std::size_t includeStart_,
std::size_t includeEnd_) {
includeConfig = INCLUDE_BY_INDEX;
includeStart = includeStart_;
includeEnd = includeEnd_;
}
gd::String GetEventsGroupName() const { return eventsGroupName; }
gd::String GetEventsGroupName() const { return eventsGroupName; }
/**
* Get the number of the first event to be included. (Meaningful only if includeAll was set to false, see SetIncludeAllEvents)
*/
std::size_t GetIncludeStart() const { return includeStart; };
/**
* Get the number of the first event to be included. (Meaningful only if
* includeAll was set to false, see SetIncludeAllEvents)
*/
std::size_t GetIncludeStart() const { return includeStart; };
/**
* Get the number of the last event to be included. (Meaningful only if includeAll was set to false, see SetIncludeAllEvents)
*/
std::size_t GetIncludeEnd() const { return includeEnd; };
/**
* Get the number of the last event to be included. (Meaningful only if
* includeAll was set to false, see SetIncludeAllEvents)
*/
std::size_t GetIncludeEnd() const { return includeEnd; };
/**
* The link event must always be preprocessed.
*/
virtual bool MustBePreprocessed() { return true;}
/**
* The link event must always be preprocessed.
*/
virtual bool MustBePreprocessed() { return true; }
/**
* \brief Get a pointer to the list of events that are targeted by the link.
*
* @param project The project containing the link.
* @return NULL if nothing is found or a pointer to the list of events being linked.
*/
const EventsList * GetLinkedEvents(const gd::Project & project) const;
/**
* \brief Get a pointer to the list of events that are targeted by the link.
*
* @param project The project containing the link.
* @return NULL if nothing is found or a pointer to the list of events being
* linked.
*/
const EventsList* GetLinkedEvents(const gd::Project& project) const;
/**
* \brief Replace the link in the events list by the linked events.
* When implementing a platform with a link event, you should call this function when preprocessing the events
* (See gd::EventMetadata::codeGeneration).
*/
void ReplaceLinkByLinkedEvents(const gd::Project & project, EventsList & eventList, std::size_t indexOfTheEventInThisList);
/**
* \brief Replace the link in the events list by the linked events.
* When implementing a platform with a link event, you should call this
* function when preprocessing the events (See
* gd::EventMetadata::codeGeneration).
*/
void ReplaceLinkByLinkedEvents(const gd::Project& project,
EventsList& eventList,
std::size_t indexOfTheEventInThisList);
virtual bool IsExecutable() const { return true; };
virtual bool IsExecutable() const { return true; };
/**
* Called by event editor to draw the event.
*/
virtual void Render(wxDC & dc, int x, int y, unsigned int width, gd::EventsEditorItemsAreas & areas, gd::EventsEditorSelection & selection, const gd::Platform & platform);
/**
* Called by event editor to draw the event.
*/
virtual void Render(wxDC& dc,
int x,
int y,
unsigned int width,
gd::EventsEditorItemsAreas& areas,
gd::EventsEditorSelection& selection,
const gd::Platform& platform);
/**
* Must return the height of the event when rendered
*/
virtual unsigned int GetRenderedHeight(unsigned int width, const gd::Platform & platform) const;
/**
* Must return the height of the event when rendered
*/
virtual unsigned int GetRenderedHeight(unsigned int width,
const gd::Platform& platform) const;
virtual EditEventReturnType EditEvent(wxWindow* parent_, gd::Project & game_, gd::Layout & scene_, gd::MainFrameWrapper & mainFrameWrapper_);
virtual EditEventReturnType EditEvent(
wxWindow* parent_,
gd::Project& game_,
gd::Layout& scene_,
gd::MainFrameWrapper& mainFrameWrapper_);
virtual void SerializeTo(SerializerElement & element) const;
virtual void UnserializeFrom(gd::Project & project, const SerializerElement & element);
virtual void SerializeTo(SerializerElement& element) const;
virtual void UnserializeFrom(gd::Project& project,
const SerializerElement& element);
private:
gd::String target; ///< The name of the external events (or scene) to be included
private:
gd::String
target; ///< The name of the external events (or scene) to be included
IncludeConfig includeConfig; ///< Defines which events are included by this link
IncludeConfig
includeConfig; ///< Defines which events are included by this link
gd::String eventsGroupName; ///< If includeConfig is set to INCLUDE_EVENTS_GROUP, represents the name of the events group to be included.
gd::String eventsGroupName; ///< If includeConfig is set to
///< INCLUDE_EVENTS_GROUP, represents the name of
///< the events group to be included.
std::size_t includeStart; ///< If includeConfig is set to INCLUDE_BY_INDEX, represents the number of the first event of the target to included.
std::size_t includeEnd; ///< If includeConfig is set to INCLUDE_BY_INDEX, represents the number of the last event of the target to included.
std::size_t includeStart; ///< If includeConfig is set to INCLUDE_BY_INDEX,
///< represents the number of the first event of
///< the target to included.
std::size_t
includeEnd; ///< If includeConfig is set to INCLUDE_BY_INDEX, represents
///< the number of the last event of the target to included.
bool linkWasInvalid; ///< Set to true by Preprocess if the links was invalid the last time is was processed. Used to display a warning in the events editor.
bool linkWasInvalid; ///< Set to true by Preprocess if the links was invalid
///< the last time is was processed. Used to display a
///< warning in the events editor.
};
}
} // namespace gd
#endif // GDCORE_LINKEVENT_H
#endif // GDCORE_LINKEVENT_H

View File

@@ -1,166 +1,200 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "RepeatEvent.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerationContext.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerator.h"
#include "GDCore/Events/CodeGeneration/ExpressionsCodeGeneration.h"
#include "GDCore/Events/Serialization.h"
#include "GDCore/IDE/Dialogs/EditRepeatEvent.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsEditorItemsAreas.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsEditorSelection.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsRenderingHelper.h"
#include "GDCore/Events/Serialization.h"
#include "GDCore/Serialization/SerializerElement.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerator.h"
#include "GDCore/Events/CodeGeneration/ExpressionsCodeGeneration.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerationContext.h"
#include "GDCore/IDE/Dialogs/EditRepeatEvent.h"
using namespace std;
namespace gd
{
namespace gd {
RepeatEvent::RepeatEvent() :
BaseEvent(),
repeatNumberExpression(""),
repeatNumberExpressionSelected(false)
{
RepeatEvent::RepeatEvent()
: BaseEvent(),
repeatNumberExpression(""),
repeatNumberExpressionSelected(false) {}
vector<gd::InstructionsList*> RepeatEvent::GetAllConditionsVectors() {
vector<gd::InstructionsList*> allConditions;
allConditions.push_back(&conditions);
return allConditions;
}
vector<gd::InstructionsList*> RepeatEvent::GetAllActionsVectors() {
vector<gd::InstructionsList*> allActions;
allActions.push_back(&actions);
vector < gd::InstructionsList* > RepeatEvent::GetAllConditionsVectors()
{
vector < gd::InstructionsList* > allConditions;
allConditions.push_back(&conditions);
return allConditions;
return allActions;
}
vector < gd::InstructionsList* > RepeatEvent::GetAllActionsVectors()
{
vector < gd::InstructionsList* > allActions;
allActions.push_back(&actions);
vector<gd::Expression*> RepeatEvent::GetAllExpressions() {
vector<gd::Expression*> allExpressions;
allExpressions.push_back(&repeatNumberExpression);
return allActions;
return allExpressions;
}
vector < gd::Expression* > RepeatEvent::GetAllExpressions()
{
vector < gd::Expression* > allExpressions;
allExpressions.push_back(&repeatNumberExpression);
vector<const gd::InstructionsList*> RepeatEvent::GetAllConditionsVectors()
const {
vector<const gd::InstructionsList*> allConditions;
allConditions.push_back(&conditions);
return allExpressions;
return allConditions;
}
vector < const gd::InstructionsList* > RepeatEvent::GetAllConditionsVectors() const
{
vector < const gd::InstructionsList* > allConditions;
allConditions.push_back(&conditions);
vector<const gd::InstructionsList*> RepeatEvent::GetAllActionsVectors() const {
vector<const gd::InstructionsList*> allActions;
allActions.push_back(&actions);
return allConditions;
return allActions;
}
vector < const gd::InstructionsList* > RepeatEvent::GetAllActionsVectors() const
{
vector < const gd::InstructionsList* > allActions;
allActions.push_back(&actions);
vector<const gd::Expression*> RepeatEvent::GetAllExpressions() const {
vector<const gd::Expression*> allExpressions;
allExpressions.push_back(&repeatNumberExpression);
return allActions;
return allExpressions;
}
vector < const gd::Expression* > RepeatEvent::GetAllExpressions() const
{
vector < const gd::Expression* > allExpressions;
allExpressions.push_back(&repeatNumberExpression);
return allExpressions;
void RepeatEvent::SerializeTo(SerializerElement& element) const {
element.AddChild("repeatExpression")
.SetValue(repeatNumberExpression.GetPlainString());
gd::EventsListSerialization::SerializeInstructionsTo(
conditions, element.AddChild("conditions"));
gd::EventsListSerialization::SerializeInstructionsTo(
actions, element.AddChild("actions"));
gd::EventsListSerialization::SerializeEventsTo(events,
element.AddChild("events"));
}
void RepeatEvent::SerializeTo(SerializerElement & element) const
{
element.AddChild("repeatExpression").SetValue(repeatNumberExpression.GetPlainString());
gd::EventsListSerialization::SerializeInstructionsTo(conditions, element.AddChild("conditions"));
gd::EventsListSerialization::SerializeInstructionsTo(actions, element.AddChild("actions"));
gd::EventsListSerialization::SerializeEventsTo(events, element.AddChild("events"));
}
void RepeatEvent::UnserializeFrom(gd::Project & project, const SerializerElement & element)
{
repeatNumberExpression = gd::Expression(element.GetChild("repeatExpression", 0, "RepeatExpression").GetValue().GetString());
gd::EventsListSerialization::UnserializeInstructionsFrom(project, conditions, element.GetChild("conditions", 0, "Conditions"));
gd::EventsListSerialization::UnserializeInstructionsFrom(project, actions, element.GetChild("actions", 0, "Actions"));
gd::EventsListSerialization::UnserializeEventsFrom(project, events, element.GetChild("events", 0, "Events"));
void RepeatEvent::UnserializeFrom(gd::Project& project,
const SerializerElement& element) {
repeatNumberExpression =
gd::Expression(element.GetChild("repeatExpression", 0, "RepeatExpression")
.GetValue()
.GetString());
gd::EventsListSerialization::UnserializeInstructionsFrom(
project, conditions, element.GetChild("conditions", 0, "Conditions"));
gd::EventsListSerialization::UnserializeInstructionsFrom(
project, actions, element.GetChild("actions", 0, "Actions"));
gd::EventsListSerialization::UnserializeEventsFrom(
project, events, element.GetChild("events", 0, "Events"));
}
/**
* Render the event in the bitmap
*/
void RepeatEvent::Render(wxDC & dc, int x, int y, unsigned int width, gd::EventsEditorItemsAreas & areas, gd::EventsEditorSelection & selection, const gd::Platform & platform)
{
void RepeatEvent::Render(wxDC& dc,
int x,
int y,
unsigned int width,
gd::EventsEditorItemsAreas& areas,
gd::EventsEditorSelection& selection,
const gd::Platform& platform) {
#if !defined(GD_NO_WX_GUI)
gd::EventsRenderingHelper * renderingHelper = gd::EventsRenderingHelper::Get();
gd::EventsRenderingHelper* renderingHelper = gd::EventsRenderingHelper::Get();
int border = renderingHelper->instructionsListBorder;
const int repeatTextHeight = 20;
// Draw header rectangle
wxRect headerRect(x, y, width, repeatTextHeight);
renderingHelper->DrawNiceRectangle(dc, headerRect);
// Repeat text
dc.SetFont(renderingHelper->GetNiceFont().Bold());
if (!IsDisabled())
dc.SetTextForeground(wxColour(0, 0, 0));
else
dc.SetTextForeground(wxColour(160, 160, 160));
dc.DrawText(_("Repeat") + " " + repeatNumberExpression.GetPlainString() +
" " + _("times :"),
x + 4,
y + 3);
// Draw conditions rectangle
wxRect rect(x,
y + repeatTextHeight,
renderingHelper->GetConditionsColumnWidth() + border,
GetRenderedHeight(width, platform) - repeatTextHeight);
renderingHelper->DrawNiceRectangle(dc, rect);
// Draw actions and conditions
renderingHelper->DrawConditionsList(
conditions,
dc,
x + border,
y + repeatTextHeight + border,
renderingHelper->GetConditionsColumnWidth() - border,
this,
areas,
selection,
platform);
renderingHelper->DrawActionsList(
actions,
dc,
x + renderingHelper->GetConditionsColumnWidth() + border,
y + repeatTextHeight + border,
width - renderingHelper->GetConditionsColumnWidth() - border * 2,
this,
areas,
selection,
platform);
#endif
}
unsigned int RepeatEvent::GetRenderedHeight(
unsigned int width, const gd::Platform& platform) const {
#if !defined(GD_NO_WX_GUI)
if (eventHeightNeedUpdate) {
gd::EventsRenderingHelper* renderingHelper =
gd::EventsRenderingHelper::Get();
int border = renderingHelper->instructionsListBorder;
const int repeatTextHeight = 20;
//Draw header rectangle
wxRect headerRect(x, y, width, repeatTextHeight);
renderingHelper->DrawNiceRectangle(dc, headerRect);
// Get maximum height needed
int conditionsHeight = renderingHelper->GetRenderedConditionsListHeight(
conditions,
renderingHelper->GetConditionsColumnWidth() - border,
platform);
int actionsHeight = renderingHelper->GetRenderedActionsListHeight(
actions,
width - renderingHelper->GetConditionsColumnWidth() - border * 2,
platform);
//Repeat text
dc.SetFont( renderingHelper->GetNiceFont().Bold() );
if ( !IsDisabled() )
dc.SetTextForeground( wxColour( 0, 0, 0 ) );
else
dc.SetTextForeground( wxColour( 160, 160, 160 ) );
dc.DrawText( _("Repeat") + " " + repeatNumberExpression.GetPlainString() + " " + _("times :"), x + 4, y + 3 );
renderedHeight =
(conditionsHeight > actionsHeight ? conditionsHeight : actionsHeight) +
repeatTextHeight + border * 2;
eventHeightNeedUpdate = false;
}
//Draw conditions rectangle
wxRect rect(x, y+repeatTextHeight, renderingHelper->GetConditionsColumnWidth()+border, GetRenderedHeight(width, platform)-repeatTextHeight);
renderingHelper->DrawNiceRectangle(dc, rect);
//Draw actions and conditions
renderingHelper->DrawConditionsList(conditions, dc,
x+border,
y+repeatTextHeight+border,
renderingHelper->GetConditionsColumnWidth()-border, this, areas, selection, platform);
renderingHelper->DrawActionsList(actions, dc,
x+renderingHelper->GetConditionsColumnWidth()+border,
y+repeatTextHeight+border,
width-renderingHelper->GetConditionsColumnWidth()-border*2, this, areas, selection, platform);
#endif
}
unsigned int RepeatEvent::GetRenderedHeight(unsigned int width, const gd::Platform & platform) const
{
#if !defined(GD_NO_WX_GUI)
if ( eventHeightNeedUpdate )
{
gd::EventsRenderingHelper * renderingHelper = gd::EventsRenderingHelper::Get();
int border = renderingHelper->instructionsListBorder;
const int repeatTextHeight = 20;
//Get maximum height needed
int conditionsHeight = renderingHelper->GetRenderedConditionsListHeight(conditions, renderingHelper->GetConditionsColumnWidth()-border, platform);
int actionsHeight = renderingHelper->GetRenderedActionsListHeight(actions, width-renderingHelper->GetConditionsColumnWidth()-border*2, platform);
renderedHeight = ( conditionsHeight > actionsHeight ? conditionsHeight : actionsHeight ) + repeatTextHeight + border*2;
eventHeightNeedUpdate = false;
}
return renderedHeight;
return renderedHeight;
#else
return 0;
return 0;
#endif
}
gd::BaseEvent::EditEventReturnType RepeatEvent::EditEvent(wxWindow* parent_, gd::Project & game_, gd::Layout & scene_, gd::MainFrameWrapper & mainFrameWrapper_)
{
gd::BaseEvent::EditEventReturnType RepeatEvent::EditEvent(
wxWindow* parent_,
gd::Project& game_,
gd::Layout& scene_,
gd::MainFrameWrapper& mainFrameWrapper_) {
#if !defined(GD_NO_WX_GUI)
EditRepeatEvent dialog(parent_, *this, game_, scene_);
if ( dialog.ShowModal() == 0 ) return Cancelled;
EditRepeatEvent dialog(parent_, *this, game_, scene_);
if (dialog.ShowModal() == 0) return Cancelled;
#endif
return ChangesMade;
return ChangesMade;
}
}
} // namespace gd

View File

@@ -1,82 +1,105 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_REPEATEVENT_H
#define GDCORE_REPEATEVENT_H
#include "GDCore/Events/Event.h"
#include "GDCore/Events/EventsList.h"
namespace gd { class Instruction; }
namespace gd { class Project; }
namespace gd {
class Instruction;
}
namespace gd {
class Project;
}
class RuntimeScene;
class TiXmlElement;
namespace gd { class EventsEditorItemsAreas; }
namespace gd { class EventsEditorSelection; }
namespace gd {
class EventsEditorItemsAreas;
}
namespace gd {
class EventsEditorSelection;
}
namespace gd
{
namespace gd {
/**
* \brief Event being repeated a specified number of times.
*/
class GD_CORE_API RepeatEvent : public gd::BaseEvent
{
public:
RepeatEvent();
virtual ~RepeatEvent() {};
virtual gd::RepeatEvent * Clone() const { return new RepeatEvent(*this);}
class GD_CORE_API RepeatEvent : public gd::BaseEvent {
public:
RepeatEvent();
virtual ~RepeatEvent(){};
virtual gd::RepeatEvent* Clone() const { return new RepeatEvent(*this); }
virtual bool IsExecutable() const {return true;}
virtual bool IsExecutable() const { return true; }
virtual bool CanHaveSubEvents() const {return true;}
virtual const gd::EventsList & GetSubEvents() const {return events;};
virtual gd::EventsList & GetSubEvents() {return events;};
virtual bool CanHaveSubEvents() const { return true; }
virtual const gd::EventsList& GetSubEvents() const { return events; };
virtual gd::EventsList& GetSubEvents() { return events; };
const gd::InstructionsList & GetConditions() const { return conditions; };
gd::InstructionsList & GetConditions() { return conditions; };
const gd::InstructionsList& GetConditions() const { return conditions; };
gd::InstructionsList& GetConditions() { return conditions; };
const gd::InstructionsList & GetActions() const { return actions; };
gd::InstructionsList & GetActions() { return actions; };
const gd::InstructionsList& GetActions() const { return actions; };
gd::InstructionsList& GetActions() { return actions; };
const gd::String & GetRepeatExpression() const { return repeatNumberExpression.GetPlainString(); };
void SetRepeatExpression(gd::String repeatNumberExpression_) { repeatNumberExpression = gd::Expression(repeatNumberExpression_); };
const gd::String& GetRepeatExpression() const {
return repeatNumberExpression.GetPlainString();
};
void SetRepeatExpression(gd::String repeatNumberExpression_) {
repeatNumberExpression = gd::Expression(repeatNumberExpression_);
};
virtual std::vector < gd::InstructionsList* > GetAllConditionsVectors();
virtual std::vector < gd::InstructionsList* > GetAllActionsVectors();
virtual std::vector < gd::Expression* > GetAllExpressions();
virtual std::vector < const gd::InstructionsList* > GetAllConditionsVectors() const;
virtual std::vector < const gd::InstructionsList* > GetAllActionsVectors() const;
virtual std::vector < const gd::Expression* > GetAllExpressions() const;
virtual std::vector<gd::InstructionsList*> GetAllConditionsVectors();
virtual std::vector<gd::InstructionsList*> GetAllActionsVectors();
virtual std::vector<gd::Expression*> GetAllExpressions();
virtual std::vector<const gd::InstructionsList*> GetAllConditionsVectors()
const;
virtual std::vector<const gd::InstructionsList*> GetAllActionsVectors() const;
virtual std::vector<const gd::Expression*> GetAllExpressions() const;
virtual void SerializeTo(SerializerElement & element) const;
virtual void UnserializeFrom(gd::Project & project, const SerializerElement & element);
virtual void SerializeTo(SerializerElement& element) const;
virtual void UnserializeFrom(gd::Project& project,
const SerializerElement& element);
/**
* Called by event editor to draw the event.
*/
virtual void Render(wxDC & dc, int x, int y, unsigned int width, gd::EventsEditorItemsAreas & areas, gd::EventsEditorSelection & selection, const gd::Platform & platform);
/**
* Called by event editor to draw the event.
*/
virtual void Render(wxDC& dc,
int x,
int y,
unsigned int width,
gd::EventsEditorItemsAreas& areas,
gd::EventsEditorSelection& selection,
const gd::Platform& platform);
/**
* Must return the height of the event when rendered
*/
virtual unsigned int GetRenderedHeight(unsigned int width, const gd::Platform & platform) const;
/**
* Must return the height of the event when rendered
*/
virtual unsigned int GetRenderedHeight(unsigned int width,
const gd::Platform& platform) const;
/**
* Called when the user want to edit the event
*/
virtual EditEventReturnType EditEvent(wxWindow* parent_, gd::Project & game_, gd::Layout & scene_, gd::MainFrameWrapper & mainFrameWrapper_);
/**
* Called when the user want to edit the event
*/
virtual EditEventReturnType EditEvent(
wxWindow* parent_,
gd::Project& game_,
gd::Layout& scene_,
gd::MainFrameWrapper& mainFrameWrapper_);
private:
gd::Expression repeatNumberExpression;
gd::InstructionsList conditions;
gd::InstructionsList actions;
EventsList events;
private:
gd::Expression repeatNumberExpression;
gd::InstructionsList conditions;
gd::InstructionsList actions;
EventsList events;
bool repeatNumberExpressionSelected;
bool repeatNumberExpressionSelected;
};
}
} // namespace gd
#endif // GDCORE_REPEATEVENT_H
#endif // GDCORE_REPEATEVENT_H

View File

@@ -1,125 +1,152 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "StandardEvent.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsRenderingHelper.h"
#include "GDCore/CommonTools.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerationContext.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerator.h"
#include "GDCore/Events/Serialization.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsEditorItemsAreas.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsEditorSelection.h"
#include "GDCore/Events/Serialization.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsRenderingHelper.h"
#include "GDCore/Serialization/SerializerElement.h"
#include "GDCore/TinyXml/tinyxml.h"
#include "GDCore/CommonTools.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerator.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerationContext.h"
using namespace std;
namespace gd
{
namespace gd {
StandardEvent::StandardEvent() :
BaseEvent()
{
StandardEvent::StandardEvent() : BaseEvent() {}
StandardEvent::~StandardEvent(){};
vector<const gd::InstructionsList*> StandardEvent::GetAllConditionsVectors()
const {
vector<const gd::InstructionsList*> allConditions;
allConditions.push_back(&conditions);
return allConditions;
}
StandardEvent::~StandardEvent()
{
};
vector<const gd::InstructionsList*> StandardEvent::GetAllActionsVectors()
const {
vector<const gd::InstructionsList*> allActions;
allActions.push_back(&actions);
vector < const gd::InstructionsList* > StandardEvent::GetAllConditionsVectors() const
{
vector < const gd::InstructionsList* > allConditions;
allConditions.push_back(&conditions);
return allActions;
}
vector<gd::InstructionsList*> StandardEvent::GetAllConditionsVectors() {
vector<gd::InstructionsList*> allConditions;
allConditions.push_back(&conditions);
return allConditions;
return allConditions;
}
vector < const gd::InstructionsList* > StandardEvent::GetAllActionsVectors() const
{
vector < const gd::InstructionsList* > allActions;
allActions.push_back(&actions);
vector<gd::InstructionsList*> StandardEvent::GetAllActionsVectors() {
vector<gd::InstructionsList*> allActions;
allActions.push_back(&actions);
return allActions;
}
vector < gd::InstructionsList* > StandardEvent::GetAllConditionsVectors()
{
vector < gd::InstructionsList* > allConditions;
allConditions.push_back(&conditions);
return allConditions;
return allActions;
}
vector < gd::InstructionsList* > StandardEvent::GetAllActionsVectors()
{
vector < gd::InstructionsList* > allActions;
allActions.push_back(&actions);
return allActions;
void StandardEvent::SerializeTo(SerializerElement& element) const {
gd::EventsListSerialization::SerializeInstructionsTo(
conditions, element.AddChild("conditions"));
gd::EventsListSerialization::SerializeInstructionsTo(
actions, element.AddChild("actions"));
gd::EventsListSerialization::SerializeEventsTo(events,
element.AddChild("events"));
}
void StandardEvent::SerializeTo(SerializerElement & element) const
{
gd::EventsListSerialization::SerializeInstructionsTo(conditions, element.AddChild("conditions"));
gd::EventsListSerialization::SerializeInstructionsTo(actions, element.AddChild("actions"));
gd::EventsListSerialization::SerializeEventsTo(events, element.AddChild("events"));
}
void StandardEvent::UnserializeFrom(gd::Project & project, const SerializerElement & element)
{
gd::EventsListSerialization::UnserializeInstructionsFrom(project, conditions, element.GetChild("conditions", 0, "Conditions"));
gd::EventsListSerialization::UnserializeInstructionsFrom(project, actions, element.GetChild("actions", 0, "Actions"));
gd::EventsListSerialization::UnserializeEventsFrom(project, events, element.GetChild("events", 0, "Events"));
void StandardEvent::UnserializeFrom(gd::Project& project,
const SerializerElement& element) {
gd::EventsListSerialization::UnserializeInstructionsFrom(
project, conditions, element.GetChild("conditions", 0, "Conditions"));
gd::EventsListSerialization::UnserializeInstructionsFrom(
project, actions, element.GetChild("actions", 0, "Actions"));
gd::EventsListSerialization::UnserializeEventsFrom(
project, events, element.GetChild("events", 0, "Events"));
}
/**
* Render the event in the bitmap
*/
void StandardEvent::Render(wxDC & dc, int x, int y, unsigned int width, gd::EventsEditorItemsAreas & areas, gd::EventsEditorSelection & selection, const gd::Platform & platform)
{
void StandardEvent::Render(wxDC& dc,
int x,
int y,
unsigned int width,
gd::EventsEditorItemsAreas& areas,
gd::EventsEditorSelection& selection,
const gd::Platform& platform) {
#if !defined(GD_NO_WX_GUI)
gd::EventsRenderingHelper * renderingHelper = gd::EventsRenderingHelper::Get();
gd::EventsRenderingHelper* renderingHelper = gd::EventsRenderingHelper::Get();
int border = renderingHelper->instructionsListBorder;
// Draw event rectangle
wxRect rect(x,
y,
renderingHelper->GetConditionsColumnWidth() + border,
GetRenderedHeight(width, platform));
renderingHelper->DrawNiceRectangle(dc, rect);
renderingHelper->DrawConditionsList(
conditions,
dc,
x + border,
y + border,
renderingHelper->GetConditionsColumnWidth() - border,
this,
areas,
selection,
platform);
renderingHelper->DrawActionsList(
actions,
dc,
x + renderingHelper->GetConditionsColumnWidth() + border,
y + border,
width - renderingHelper->GetConditionsColumnWidth() - border * 2,
this,
areas,
selection,
platform);
// Make sure that Render is rendering an event with the same height as
// GetRenderedHeight : Use same values for border and similar calls to compute
// heights
#endif
}
unsigned int StandardEvent::GetRenderedHeight(
unsigned int width, const gd::Platform& platform) const {
#if !defined(GD_NO_WX_GUI)
if (eventHeightNeedUpdate) {
gd::EventsRenderingHelper* renderingHelper =
gd::EventsRenderingHelper::Get();
int border = renderingHelper->instructionsListBorder;
//Draw event rectangle
wxRect rect(x, y, renderingHelper->GetConditionsColumnWidth()+border, GetRenderedHeight(width, platform));
renderingHelper->DrawNiceRectangle(dc, rect);
// Get maximum height needed
int conditionsHeight = renderingHelper->GetRenderedConditionsListHeight(
conditions,
renderingHelper->GetConditionsColumnWidth() - border * 2,
platform);
int actionsHeight = renderingHelper->GetRenderedActionsListHeight(
actions,
width - renderingHelper->GetConditionsColumnWidth() - border * 2,
platform);
renderingHelper->DrawConditionsList(conditions, dc,
x+border,
y+border,
renderingHelper->GetConditionsColumnWidth()-border, this, areas, selection, platform);
renderingHelper->DrawActionsList(actions, dc,
x+renderingHelper->GetConditionsColumnWidth()+border,
y+border,
width-renderingHelper->GetConditionsColumnWidth()-border*2, this, areas, selection, platform);
renderedHeight =
(conditionsHeight > actionsHeight ? conditionsHeight : actionsHeight) +
border * 2;
eventHeightNeedUpdate = false;
}
//Make sure that Render is rendering an event with the same height as GetRenderedHeight : Use same values for border and similar calls to compute heights
#endif
}
unsigned int StandardEvent::GetRenderedHeight(unsigned int width, const gd::Platform & platform) const
{
#if !defined(GD_NO_WX_GUI)
if ( eventHeightNeedUpdate )
{
gd::EventsRenderingHelper * renderingHelper = gd::EventsRenderingHelper::Get();
int border = renderingHelper->instructionsListBorder;
//Get maximum height needed
int conditionsHeight = renderingHelper->GetRenderedConditionsListHeight(conditions, renderingHelper->GetConditionsColumnWidth()-border*2, platform);
int actionsHeight = renderingHelper->GetRenderedActionsListHeight(actions, width-renderingHelper->GetConditionsColumnWidth()-border*2, platform);
renderedHeight = (conditionsHeight > actionsHeight ? conditionsHeight : actionsHeight)+border*2;
eventHeightNeedUpdate = false;
}
return renderedHeight;
return renderedHeight;
#else
return 0;
return 0;
#endif
}
}
} // namespace gd

View File

@@ -1,74 +1,89 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#if defined(GD_IDE_ONLY)
#ifndef GDCORE_STANDARDEVENT_H
#define GDCORE_STANDARDEVENT_H
#include "GDCore/Events/Event.h"
#include "GDCore/Events/EventsList.h"
#include "GDCore/Events/Instruction.h"
#include "GDCore/Events/InstructionsList.h"
#include "GDCore/Events/EventsList.h"
namespace gd { class Instruction; }
namespace gd { class Project; }
namespace gd {
class Instruction;
}
namespace gd {
class Project;
}
class RuntimeScene;
class TiXmlElement;
class EventsCodeGenerationContext;
namespace gd { class EventsEditorItemsAreas; }
namespace gd { class EventsEditorSelection; }
namespace gd {
class EventsEditorItemsAreas;
}
namespace gd {
class EventsEditorSelection;
}
namespace gd
{
namespace gd {
/**
* \brief Standard event, with conditions, actions and support for sub events.
*/
class GD_CORE_API StandardEvent : public gd::BaseEvent
{
public:
StandardEvent();
virtual ~StandardEvent();
virtual gd::StandardEvent * Clone() const { return new StandardEvent(*this);}
class GD_CORE_API StandardEvent : public gd::BaseEvent {
public:
StandardEvent();
virtual ~StandardEvent();
virtual gd::StandardEvent* Clone() const { return new StandardEvent(*this); }
virtual bool IsExecutable() const {return true;}
virtual bool IsExecutable() const { return true; }
virtual bool CanHaveSubEvents() const {return true;}
virtual const gd::EventsList & GetSubEvents() const {return events;};
virtual gd::EventsList & GetSubEvents() {return events;};
virtual bool CanHaveSubEvents() const { return true; }
virtual const gd::EventsList& GetSubEvents() const { return events; };
virtual gd::EventsList& GetSubEvents() { return events; };
const gd::InstructionsList & GetConditions() const { return conditions; };
gd::InstructionsList & GetConditions() { return conditions; };
const gd::InstructionsList& GetConditions() const { return conditions; };
gd::InstructionsList& GetConditions() { return conditions; };
const gd::InstructionsList & GetActions() const { return actions; };
gd::InstructionsList & GetActions() { return actions; };
const gd::InstructionsList& GetActions() const { return actions; };
gd::InstructionsList& GetActions() { return actions; };
virtual std::vector < const gd::InstructionsList* > GetAllConditionsVectors() const;
virtual std::vector < const gd::InstructionsList* > GetAllActionsVectors() const;
virtual std::vector < gd::InstructionsList* > GetAllConditionsVectors();
virtual std::vector < gd::InstructionsList* > GetAllActionsVectors();
virtual std::vector<const gd::InstructionsList*> GetAllConditionsVectors()
const;
virtual std::vector<const gd::InstructionsList*> GetAllActionsVectors() const;
virtual std::vector<gd::InstructionsList*> GetAllConditionsVectors();
virtual std::vector<gd::InstructionsList*> GetAllActionsVectors();
virtual void SerializeTo(SerializerElement & element) const;
virtual void UnserializeFrom(gd::Project & project, const SerializerElement & element);
virtual void SerializeTo(SerializerElement& element) const;
virtual void UnserializeFrom(gd::Project& project,
const SerializerElement& element);
/**
* Called by event editor to draw the event.
*/
virtual void Render(wxDC & dc, int x, int y, unsigned int width, gd::EventsEditorItemsAreas & areas, gd::EventsEditorSelection & selection, const gd::Platform & platform);
/**
* Called by event editor to draw the event.
*/
virtual void Render(wxDC& dc,
int x,
int y,
unsigned int width,
gd::EventsEditorItemsAreas& areas,
gd::EventsEditorSelection& selection,
const gd::Platform& platform);
/**
* Must return the height of the event when rendered
*/
virtual unsigned int GetRenderedHeight(unsigned int width, const gd::Platform & platform) const;
/**
* Must return the height of the event when rendered
*/
virtual unsigned int GetRenderedHeight(unsigned int width,
const gd::Platform& platform) const;
private:
gd::InstructionsList conditions;
gd::InstructionsList actions;
EventsList events;
private:
gd::InstructionsList conditions;
gd::InstructionsList actions;
EventsList events;
};
}
} // namespace gd
#endif // GDCORE_STANDARDEVENT_H
#endif // GDCORE_STANDARDEVENT_H
#endif

View File

@@ -1,7 +1,7 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#if defined(GD_IDE_ONLY)
@@ -10,177 +10,238 @@
#include <wx/msgdlg.h>
#include "GDCore/IDE/wxTools/CommonBitmapProvider.h"
#endif
#include "GDCore/TinyXml/tinyxml.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerationContext.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerator.h"
#include "GDCore/Events/CodeGeneration/ExpressionsCodeGeneration.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsRenderingHelper.h"
#include "GDCore/Events/Serialization.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsEditorItemsAreas.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsEditorSelection.h"
#include "GDCore/IDE/Dialogs/EventsEditor/EventsRenderingHelper.h"
#include "GDCore/Serialization/SerializerElement.h"
#include "GDCore/Events/Serialization.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerationContext.h"
#include "GDCore/TinyXml/tinyxml.h"
using namespace std;
namespace gd
{
namespace gd {
vector < gd::InstructionsList* > WhileEvent::GetAllConditionsVectors()
{
vector < gd::InstructionsList* > allConditions;
allConditions.push_back(&whileConditions);
allConditions.push_back(&conditions);
vector<gd::InstructionsList*> WhileEvent::GetAllConditionsVectors() {
vector<gd::InstructionsList*> allConditions;
allConditions.push_back(&whileConditions);
allConditions.push_back(&conditions);
return allConditions;
return allConditions;
}
vector < gd::InstructionsList* > WhileEvent::GetAllActionsVectors()
{
vector < gd::InstructionsList* > allActions;
allActions.push_back(&actions);
vector<gd::InstructionsList*> WhileEvent::GetAllActionsVectors() {
vector<gd::InstructionsList*> allActions;
allActions.push_back(&actions);
return allActions;
return allActions;
}
vector < const gd::InstructionsList* > WhileEvent::GetAllConditionsVectors() const
{
vector < const gd::InstructionsList* > allConditions;
allConditions.push_back(&whileConditions);
allConditions.push_back(&conditions);
vector<const gd::InstructionsList*> WhileEvent::GetAllConditionsVectors()
const {
vector<const gd::InstructionsList*> allConditions;
allConditions.push_back(&whileConditions);
allConditions.push_back(&conditions);
return allConditions;
return allConditions;
}
vector < const gd::InstructionsList* > WhileEvent::GetAllActionsVectors() const
{
vector < const gd::InstructionsList* > allActions;
allActions.push_back(&actions);
vector<const gd::InstructionsList*> WhileEvent::GetAllActionsVectors() const {
vector<const gd::InstructionsList*> allActions;
allActions.push_back(&actions);
return allActions;
return allActions;
}
void WhileEvent::SerializeTo(SerializerElement & element) const
{
element.SetAttribute("infiniteLoopWarning", infiniteLoopWarning);
gd::EventsListSerialization::SerializeInstructionsTo(whileConditions, element.AddChild("whileConditions"));
gd::EventsListSerialization::SerializeInstructionsTo(conditions, element.AddChild("conditions"));
gd::EventsListSerialization::SerializeInstructionsTo(actions, element.AddChild("actions"));
gd::EventsListSerialization::SerializeEventsTo(events, element.AddChild("events"));
void WhileEvent::SerializeTo(SerializerElement& element) const {
element.SetAttribute("infiniteLoopWarning", infiniteLoopWarning);
gd::EventsListSerialization::SerializeInstructionsTo(
whileConditions, element.AddChild("whileConditions"));
gd::EventsListSerialization::SerializeInstructionsTo(
conditions, element.AddChild("conditions"));
gd::EventsListSerialization::SerializeInstructionsTo(
actions, element.AddChild("actions"));
gd::EventsListSerialization::SerializeEventsTo(events,
element.AddChild("events"));
}
void WhileEvent::UnserializeFrom(gd::Project & project, const SerializerElement & element)
{
justCreatedByTheUser = false;
infiniteLoopWarning = element.GetBoolAttribute("infiniteLoopWarning");
gd::EventsListSerialization::UnserializeInstructionsFrom(project, whileConditions, element.GetChild("whileConditions", 0, "WhileConditions"));
gd::EventsListSerialization::UnserializeInstructionsFrom(project, conditions, element.GetChild("conditions", 0, "Conditions"));
gd::EventsListSerialization::UnserializeInstructionsFrom(project, actions, element.GetChild("actions", 0, "Actions"));
gd::EventsListSerialization::UnserializeEventsFrom(project, events, element.GetChild("events", 0, "Events"));
void WhileEvent::UnserializeFrom(gd::Project& project,
const SerializerElement& element) {
justCreatedByTheUser = false;
infiniteLoopWarning = element.GetBoolAttribute("infiniteLoopWarning");
gd::EventsListSerialization::UnserializeInstructionsFrom(
project,
whileConditions,
element.GetChild("whileConditions", 0, "WhileConditions"));
gd::EventsListSerialization::UnserializeInstructionsFrom(
project, conditions, element.GetChild("conditions", 0, "Conditions"));
gd::EventsListSerialization::UnserializeInstructionsFrom(
project, actions, element.GetChild("actions", 0, "Actions"));
gd::EventsListSerialization::UnserializeEventsFrom(
project, events, element.GetChild("events", 0, "Events"));
}
/**
* Render the event in the bitmap
*/
void WhileEvent::Render(wxDC & dc, int x, int y, unsigned int width, gd::EventsEditorItemsAreas & areas, gd::EventsEditorSelection & selection, const gd::Platform & platform)
{
void WhileEvent::Render(wxDC& dc,
int x,
int y,
unsigned int width,
gd::EventsEditorItemsAreas& areas,
gd::EventsEditorSelection& selection,
const gd::Platform& platform) {
#if !defined(GD_NO_WX_GUI)
gd::EventsRenderingHelper * renderingHelper = gd::EventsRenderingHelper::Get();
gd::EventsRenderingHelper* renderingHelper = gd::EventsRenderingHelper::Get();
int border = renderingHelper->instructionsListBorder;
const int repeatHeight = 20;
// Draw header rectangle
int whileConditionsHeight =
renderingHelper->GetRenderedConditionsListHeight(
whileConditions, width - 80 - border * 2, platform) +
border * 2;
if (!infiniteLoopWarning && whileConditionsHeight < 32)
whileConditionsHeight = 32;
wxRect headerRect(x, y, width, whileConditionsHeight + repeatHeight);
renderingHelper->DrawNiceRectangle(dc, headerRect);
// While text
dc.SetFont(renderingHelper->GetNiceFont().Bold());
if (!IsDisabled())
dc.SetTextForeground(wxColour(0, 0, 0));
else
dc.SetTextForeground(wxColour(160, 160, 160));
dc.DrawText(_("While :"), x + 5, y + 5);
// Draw icon if infinite loop warning is deactivated.
if (!infiniteLoopWarning) {
if (gd::CommonBitmapProvider::Get()->noProtection.IsOk())
dc.DrawBitmap(gd::CommonBitmapProvider::Get()->noProtection,
wxPoint(x + 5, y + 5 + 18),
/*useMask=*/true);
}
// Draw "while conditions"
renderingHelper->DrawConditionsList(whileConditions,
dc,
x + 80 + border,
y + border,
width - 80 - border * 2,
this,
areas,
selection,
platform);
dc.SetFont(renderingHelper->GetNiceFont().Bold());
if (!IsDisabled())
dc.SetTextForeground(wxColour(0, 0, 0));
else
dc.SetTextForeground(wxColour(160, 160, 160));
dc.DrawText(_("Repeat :"), x + 4, y + whileConditionsHeight + 3);
whileConditionsHeight += repeatHeight;
// Draw conditions rectangle
wxRect rect(x,
y + whileConditionsHeight,
renderingHelper->GetConditionsColumnWidth() + border,
GetRenderedHeight(width, platform) - whileConditionsHeight);
renderingHelper->DrawNiceRectangle(dc, rect);
renderingHelper->DrawConditionsList(
conditions,
dc,
x + border,
y + whileConditionsHeight + border,
renderingHelper->GetConditionsColumnWidth() - border,
this,
areas,
selection,
platform);
renderingHelper->DrawActionsList(
actions,
dc,
x + renderingHelper->GetConditionsColumnWidth() + border,
y + whileConditionsHeight + border,
width - renderingHelper->GetConditionsColumnWidth() - border * 2,
this,
areas,
selection,
platform);
#endif
}
unsigned int WhileEvent::GetRenderedHeight(unsigned int width,
const gd::Platform& platform) const {
#if !defined(GD_NO_WX_GUI)
if (eventHeightNeedUpdate) {
gd::EventsRenderingHelper* renderingHelper =
gd::EventsRenderingHelper::Get();
int border = renderingHelper->instructionsListBorder;
const int repeatHeight = 20;
//Draw header rectangle
int whileConditionsHeight = renderingHelper->GetRenderedConditionsListHeight(whileConditions, width-80-border*2, platform)+border*2;
if (!infiniteLoopWarning && whileConditionsHeight < 32 ) whileConditionsHeight = 32;
wxRect headerRect(x, y, width, whileConditionsHeight+repeatHeight);
renderingHelper->DrawNiceRectangle(dc, headerRect);
// Get maximum height needed
int whileConditionsHeight =
renderingHelper->GetRenderedConditionsListHeight(
whileConditions, width - 80 - border * 2, platform);
if (!infiniteLoopWarning && whileConditionsHeight < 32)
whileConditionsHeight = 32;
int conditionsHeight = renderingHelper->GetRenderedConditionsListHeight(
conditions,
renderingHelper->GetConditionsColumnWidth() - border,
platform);
int actionsHeight = renderingHelper->GetRenderedActionsListHeight(
actions,
width - renderingHelper->GetConditionsColumnWidth() - border * 2,
platform);
//While text
dc.SetFont( renderingHelper->GetNiceFont().Bold() );
if ( !IsDisabled() )
dc.SetTextForeground( wxColour( 0, 0, 0 ) );
else
dc.SetTextForeground( wxColour( 160, 160, 160 ) );
dc.DrawText( _("While :"), x+5, y+5 );
renderedHeight =
((conditionsHeight > actionsHeight ? conditionsHeight : actionsHeight) +
whileConditionsHeight + repeatHeight) +
border * 2 + border * 2;
eventHeightNeedUpdate = false;
}
//Draw icon if infinite loop warning is deactivated.
if (!infiniteLoopWarning)
{
if ( gd::CommonBitmapProvider::Get()->noProtection.IsOk() )
dc.DrawBitmap(gd::CommonBitmapProvider::Get()->noProtection, wxPoint(x+5,y+5+18), /*useMask=*/true);
}
//Draw "while conditions"
renderingHelper->DrawConditionsList(whileConditions, dc, x+80+border, y+border, width-80-border*2, this, areas, selection, platform);
dc.SetFont( renderingHelper->GetNiceFont().Bold() );
if ( !IsDisabled() )
dc.SetTextForeground( wxColour( 0, 0, 0 ) );
else
dc.SetTextForeground( wxColour( 160, 160, 160 ) );
dc.DrawText( _("Repeat :"), x+4, y+whileConditionsHeight+3);
whileConditionsHeight += repeatHeight;
//Draw conditions rectangle
wxRect rect(x, y+whileConditionsHeight, renderingHelper->GetConditionsColumnWidth()+border, GetRenderedHeight(width, platform)-whileConditionsHeight);
renderingHelper->DrawNiceRectangle(dc, rect);
renderingHelper->DrawConditionsList(conditions, dc,
x+border,
y+whileConditionsHeight+border,
renderingHelper->GetConditionsColumnWidth()-border, this, areas, selection, platform);
renderingHelper->DrawActionsList(actions, dc,
x+renderingHelper->GetConditionsColumnWidth()+border,
y+whileConditionsHeight+border,
width-renderingHelper->GetConditionsColumnWidth()-border*2, this, areas, selection, platform);
#endif
}
unsigned int WhileEvent::GetRenderedHeight(unsigned int width, const gd::Platform & platform) const
{
#if !defined(GD_NO_WX_GUI)
if ( eventHeightNeedUpdate )
{
gd::EventsRenderingHelper * renderingHelper = gd::EventsRenderingHelper::Get();
int border = renderingHelper->instructionsListBorder;
const int repeatHeight = 20;
//Get maximum height needed
int whileConditionsHeight = renderingHelper->GetRenderedConditionsListHeight(whileConditions, width-80-border*2, platform);
if (!infiniteLoopWarning && whileConditionsHeight < 32 ) whileConditionsHeight = 32;
int conditionsHeight = renderingHelper->GetRenderedConditionsListHeight(conditions, renderingHelper->GetConditionsColumnWidth()-border, platform);
int actionsHeight = renderingHelper->GetRenderedActionsListHeight(actions, width-renderingHelper->GetConditionsColumnWidth()-border*2, platform);
renderedHeight = (( conditionsHeight > actionsHeight ? conditionsHeight : actionsHeight ) + whileConditionsHeight + repeatHeight)+border*2+border*2;
eventHeightNeedUpdate = false;
}
return renderedHeight;
return renderedHeight;
#else
return 0;
return 0;
#endif
}
gd::BaseEvent::EditEventReturnType WhileEvent::EditEvent(wxWindow* parent_, gd::Project & game_, gd::Layout & scene_, gd::MainFrameWrapper & mainFrameWrapper_)
{
gd::BaseEvent::EditEventReturnType WhileEvent::EditEvent(
wxWindow* parent_,
gd::Project& game_,
gd::Layout& scene_,
gd::MainFrameWrapper& mainFrameWrapper_) {
#if !defined(GD_NO_WX_GUI)
if ( !justCreatedByTheUser )
{
wxMessageDialog dialog(parent_, _("Do you want to activate the display of a message if the event is repeated 100000 times? This message prevent the software from being frozen if you accidentally create an infinite loop ( by letting the conditions empty for example )."),
_("Protection against infinite loops."),
wxYES_NO|wxCANCEL|wxICON_INFORMATION);
if (!justCreatedByTheUser) {
wxMessageDialog dialog(
parent_,
_("Do you want to activate the display of a message if the event is "
"repeated 100000 times? This message prevent the software from being "
"frozen if you accidentally create an infinite loop ( by letting the "
"conditions empty for example )."),
_("Protection against infinite loops."),
wxYES_NO | wxCANCEL | wxICON_INFORMATION);
dialog.SetExtendedMessage(_("This message is activated by default for \"While\" events in the IDE, and is deactivated when the game is compiled to an executable."));
dialog.SetYesNoCancelLabels(_("Activate"), _("Deactivate"), _("Cancel"));
dialog.SetExtendedMessage(_(
"This message is activated by default for \"While\" events in the IDE, "
"and is deactivated when the game is compiled to an executable."));
dialog.SetYesNoCancelLabels(_("Activate"), _("Deactivate"), _("Cancel"));
int answer = dialog.ShowModal();
if ( answer == wxID_YES ) infiniteLoopWarning = true;
else if ( answer == wxID_NO ) infiniteLoopWarning = false;
}
justCreatedByTheUser = false; //Show Message dialog next time.
int answer = dialog.ShowModal();
if (answer == wxID_YES)
infiniteLoopWarning = true;
else if (answer == wxID_NO)
infiniteLoopWarning = false;
}
justCreatedByTheUser = false; // Show Message dialog next time.
#endif
return ChangesMade;
return ChangesMade;
}
}
} // namespace gd
#endif

View File

@@ -1,92 +1,120 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_WHILEEVENT_H
#define GDCORE_WHILEEVENT_H
#include "GDCore/Events/EventsList.h"
#include "GDCore/Events/Event.h"
namespace gd { class Instruction; }
namespace gd { class Project; }
#include "GDCore/Events/EventsList.h"
namespace gd {
class Instruction;
}
namespace gd {
class Project;
}
class RuntimeScene;
class TiXmlElement;
namespace gd { class EventsEditorItemsAreas; }
namespace gd { class EventsEditorSelection; }
namespace gd
{
/**
* \brief While event is a standard event that is repeated while some conditions are true
*
* \note The platforms are required to warn the user about a possible infinite loop if the iteration count reach 100 000
* and if HasInfiniteLoopWarning() returns true.
*/
class GD_CORE_API WhileEvent : public gd::BaseEvent
{
public:
WhileEvent() : infiniteLoopWarning(true), justCreatedByTheUser(true) {};
virtual ~WhileEvent() {};
virtual gd::WhileEvent * Clone() const { return new WhileEvent(*this);}
virtual bool IsExecutable() const {return true;}
virtual bool CanHaveSubEvents() const {return true;}
virtual const gd::EventsList & GetSubEvents() const {return events;};
virtual gd::EventsList & GetSubEvents() {return events;};
const gd::InstructionsList & GetConditions() const { return conditions; };
gd::InstructionsList & GetConditions() { return conditions; };
const gd::InstructionsList & GetActions() const { return actions; };
gd::InstructionsList & GetActions() { return actions; };
const gd::InstructionsList & GetWhileConditions() const { return whileConditions; };
gd::InstructionsList & GetWhileConditions() { return whileConditions; };
void SetWhileConditions(gd::InstructionsList & whileConditions_) { whileConditions = whileConditions_; };
bool HasInfiniteLoopWarning() const { return infiniteLoopWarning; }
virtual std::vector < gd::InstructionsList* > GetAllConditionsVectors();
virtual std::vector < gd::InstructionsList* > GetAllActionsVectors();
virtual std::vector < const gd::InstructionsList* > GetAllConditionsVectors() const;
virtual std::vector < const gd::InstructionsList* > GetAllActionsVectors() const;
virtual void SerializeTo(SerializerElement & element) const;
virtual void UnserializeFrom(gd::Project & project, const SerializerElement & element);
/**
* Called by event editor to draw the event.
*/
virtual void Render(wxDC & dc, int x, int y, unsigned int width, gd::EventsEditorItemsAreas & areas, gd::EventsEditorSelection & selection, const gd::Platform & platform);
/**
* Must return the height of the event when rendered
*/
virtual unsigned int GetRenderedHeight(unsigned int width, const gd::Platform & platform) const;
/**
* Called when the user want to edit the event
*/
virtual EditEventReturnType EditEvent(wxWindow* parent_, gd::Project & game_, gd::Layout & scene_, gd::MainFrameWrapper & mainFrameWrapper_);
private:
gd::InstructionsList whileConditions;
gd::InstructionsList conditions;
gd::InstructionsList actions;
EventsList events;
bool infiniteLoopWarning; ///< If true, code will be generated to warn the developer against an infinite loop.
bool justCreatedByTheUser; ///< Used so as not to show message box to de/activate infinite loop warning when the user create the event
mutable unsigned int whileConditionsHeight;
int GetConditionsHeight() const;
int GetActionsHeight() const;
int GetWhileConditionsHeight() const;
};
namespace gd {
class EventsEditorItemsAreas;
}
namespace gd {
class EventsEditorSelection;
}
#endif // GDCORE_WHILEEVENT_H
namespace gd {
/**
* \brief While event is a standard event that is repeated while some conditions
* are true
*
* \note The platforms are required to warn the user about a possible infinite
* loop if the iteration count reach 100 000 and if HasInfiniteLoopWarning()
* returns true.
*/
class GD_CORE_API WhileEvent : public gd::BaseEvent {
public:
WhileEvent() : infiniteLoopWarning(true), justCreatedByTheUser(true){};
virtual ~WhileEvent(){};
virtual gd::WhileEvent* Clone() const { return new WhileEvent(*this); }
virtual bool IsExecutable() const { return true; }
virtual bool CanHaveSubEvents() const { return true; }
virtual const gd::EventsList& GetSubEvents() const { return events; };
virtual gd::EventsList& GetSubEvents() { return events; };
const gd::InstructionsList& GetConditions() const { return conditions; };
gd::InstructionsList& GetConditions() { return conditions; };
const gd::InstructionsList& GetActions() const { return actions; };
gd::InstructionsList& GetActions() { return actions; };
const gd::InstructionsList& GetWhileConditions() const {
return whileConditions;
};
gd::InstructionsList& GetWhileConditions() { return whileConditions; };
void SetWhileConditions(gd::InstructionsList& whileConditions_) {
whileConditions = whileConditions_;
};
bool HasInfiniteLoopWarning() const { return infiniteLoopWarning; }
virtual std::vector<gd::InstructionsList*> GetAllConditionsVectors();
virtual std::vector<gd::InstructionsList*> GetAllActionsVectors();
virtual std::vector<const gd::InstructionsList*> GetAllConditionsVectors()
const;
virtual std::vector<const gd::InstructionsList*> GetAllActionsVectors() const;
virtual void SerializeTo(SerializerElement& element) const;
virtual void UnserializeFrom(gd::Project& project,
const SerializerElement& element);
/**
* Called by event editor to draw the event.
*/
virtual void Render(wxDC& dc,
int x,
int y,
unsigned int width,
gd::EventsEditorItemsAreas& areas,
gd::EventsEditorSelection& selection,
const gd::Platform& platform);
/**
* Must return the height of the event when rendered
*/
virtual unsigned int GetRenderedHeight(unsigned int width,
const gd::Platform& platform) const;
/**
* Called when the user want to edit the event
*/
virtual EditEventReturnType EditEvent(
wxWindow* parent_,
gd::Project& game_,
gd::Layout& scene_,
gd::MainFrameWrapper& mainFrameWrapper_);
private:
gd::InstructionsList whileConditions;
gd::InstructionsList conditions;
gd::InstructionsList actions;
EventsList events;
bool infiniteLoopWarning; ///< If true, code will be generated to warn the
///< developer against an infinite loop.
bool justCreatedByTheUser; ///< Used so as not to show message box to
///< de/activate infinite loop warning when the
///< user create the event
mutable unsigned int whileConditionsHeight;
int GetConditionsHeight() const;
int GetActionsHeight() const;
int GetWhileConditionsHeight() const;
};
} // namespace gd
#endif // GDCORE_WHILEEVENT_H

View File

@@ -1,80 +1,92 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "GDCore/Events/CodeGeneration/EventsCodeGenerationContext.h"
#include "GDCore/Events/Tools/EventsCodeNameMangler.h"
#include <set>
#include "GDCore/CommonTools.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerator.h"
#include <set>
#include "GDCore/Events/Tools/EventsCodeNameMangler.h"
using namespace std;
namespace gd
{
namespace gd {
void EventsCodeGenerationContext::InheritsFrom(const EventsCodeGenerationContext & parent_)
{
parent = &parent_;
void EventsCodeGenerationContext::InheritsFrom(
const EventsCodeGenerationContext& parent_) {
parent = &parent_;
//Objects lists declared by parent became "already declared" in the child context.
alreadyDeclaredObjectsLists = parent_.alreadyDeclaredObjectsLists;
std::copy( parent_.objectsListsToBeDeclared.begin(), parent_.objectsListsToBeDeclared.end(), std::inserter( alreadyDeclaredObjectsLists, alreadyDeclaredObjectsLists.begin() ) );
std::copy( parent_.emptyObjectsListsToBeDeclared.begin(), parent_.emptyObjectsListsToBeDeclared.end(), std::inserter( alreadyDeclaredObjectsLists, alreadyDeclaredObjectsLists.begin() ) );
// Objects lists declared by parent became "already declared" in the child
// context.
alreadyDeclaredObjectsLists = parent_.alreadyDeclaredObjectsLists;
std::copy(parent_.objectsListsToBeDeclared.begin(),
parent_.objectsListsToBeDeclared.end(),
std::inserter(alreadyDeclaredObjectsLists,
alreadyDeclaredObjectsLists.begin()));
std::copy(parent_.emptyObjectsListsToBeDeclared.begin(),
parent_.emptyObjectsListsToBeDeclared.end(),
std::inserter(alreadyDeclaredObjectsLists,
alreadyDeclaredObjectsLists.begin()));
depthOfLastUse = parent_.depthOfLastUse;
customConditionDepth = parent_.customConditionDepth;
contextDepth = parent_.GetContextDepth()+1;
if ( parent_.maxDepthLevel )
{
maxDepthLevel = parent_.maxDepthLevel;
*maxDepthLevel = std::max(*maxDepthLevel, contextDepth);
}
depthOfLastUse = parent_.depthOfLastUse;
customConditionDepth = parent_.customConditionDepth;
contextDepth = parent_.GetContextDepth() + 1;
if (parent_.maxDepthLevel) {
maxDepthLevel = parent_.maxDepthLevel;
*maxDepthLevel = std::max(*maxDepthLevel, contextDepth);
}
}
void EventsCodeGenerationContext::Reuse(const EventsCodeGenerationContext & parent_)
{
InheritsFrom(parent_);
if (parent_.CanReuse())
contextDepth = parent_.GetContextDepth(); // Keep same context depth
void EventsCodeGenerationContext::Reuse(
const EventsCodeGenerationContext& parent_) {
InheritsFrom(parent_);
if (parent_.CanReuse())
contextDepth = parent_.GetContextDepth(); // Keep same context depth
}
void EventsCodeGenerationContext::ObjectsListNeeded(const gd::String & objectName)
{
if ( emptyObjectsListsToBeDeclared.find(objectName) == emptyObjectsListsToBeDeclared.end() )
objectsListsToBeDeclared.insert(objectName);
void EventsCodeGenerationContext::ObjectsListNeeded(
const gd::String& objectName) {
if (emptyObjectsListsToBeDeclared.find(objectName) ==
emptyObjectsListsToBeDeclared.end())
objectsListsToBeDeclared.insert(objectName);
depthOfLastUse[objectName] = GetContextDepth();
depthOfLastUse[objectName] = GetContextDepth();
}
void EventsCodeGenerationContext::EmptyObjectsListNeeded(const gd::String & objectName)
{
if ( objectsListsToBeDeclared.find(objectName) == objectsListsToBeDeclared.end() )
emptyObjectsListsToBeDeclared.insert(objectName);
void EventsCodeGenerationContext::EmptyObjectsListNeeded(
const gd::String& objectName) {
if (objectsListsToBeDeclared.find(objectName) ==
objectsListsToBeDeclared.end())
emptyObjectsListsToBeDeclared.insert(objectName);
depthOfLastUse[objectName] = GetContextDepth();
depthOfLastUse[objectName] = GetContextDepth();
}
std::set<gd::String> EventsCodeGenerationContext::GetAllObjectsToBeDeclared() const
{
std::set <gd::String> allObjectListsToBeDeclared(objectsListsToBeDeclared.begin(), objectsListsToBeDeclared.end());
allObjectListsToBeDeclared.insert(emptyObjectsListsToBeDeclared.begin(), emptyObjectsListsToBeDeclared.end());
std::set<gd::String> EventsCodeGenerationContext::GetAllObjectsToBeDeclared()
const {
std::set<gd::String> allObjectListsToBeDeclared(
objectsListsToBeDeclared.begin(), objectsListsToBeDeclared.end());
allObjectListsToBeDeclared.insert(emptyObjectsListsToBeDeclared.begin(),
emptyObjectsListsToBeDeclared.end());
return allObjectListsToBeDeclared;
return allObjectListsToBeDeclared;
}
unsigned int EventsCodeGenerationContext::GetLastDepthObjectListWasNeeded(const gd::String & name) const
{
if ( depthOfLastUse.count(name) != 0 )
return depthOfLastUse.find(name)->second;
unsigned int EventsCodeGenerationContext::GetLastDepthObjectListWasNeeded(
const gd::String& name) const {
if (depthOfLastUse.count(name) != 0) return depthOfLastUse.find(name)->second;
std::cout << "WARNING: During code generation, the last depth of an object list was 0." << std::endl;
return 0;
std::cout << "WARNING: During code generation, the last depth of an object "
"list was 0."
<< std::endl;
return 0;
}
bool EventsCodeGenerationContext::IsSameObjectsList(const gd::String & objectName, const EventsCodeGenerationContext & otherContext) const
{
return GetLastDepthObjectListWasNeeded(objectName) == otherContext.GetLastDepthObjectListWasNeeded(objectName);
bool EventsCodeGenerationContext::IsSameObjectsList(
const gd::String& objectName,
const EventsCodeGenerationContext& otherContext) const {
return GetLastDepthObjectListWasNeeded(objectName) ==
otherContext.GetLastDepthObjectListWasNeeded(objectName);
}
}
} // namespace gd

View File

@@ -1,192 +1,241 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef EVENTSCODEGENERATIONCONTEXT_H
#define EVENTSCODEGENERATIONCONTEXT_H
#include "GDCore/String.h"
#include <set>
#include <map>
#include <memory>
namespace gd { class Layout; }
#include <set>
#include "GDCore/String.h"
namespace gd {
class Layout;
}
namespace gd
{
namespace gd {
/**
* \brief Used to manage the context when generating code for events.
*
* The context refers to :
* - The objects lists being available.
* - The "current object", i.e the object being used by an action or a condition.
* - If conditions are being generated, the context keeps track of the depth of the conditions ( see GetCurrentConditionDepth )
* - The "current object", i.e the object being used by an action or a
* condition.
* - If conditions are being generated, the context keeps track of the depth of
* the conditions ( see GetCurrentConditionDepth )
* - You can also get the context depth of the last use of an object list.
*/
class GD_CORE_API EventsCodeGenerationContext
{
friend class EventsCodeGenerator;
public:
/**
* Default constructor. You may want to call InheritsFrom just after.
* \param maxDepthLevel Optional pointer to an unsigned integer that will be updated to contain the maximal scope depth reached.
*/
EventsCodeGenerationContext(unsigned int * maxDepthLevel_ = nullptr) :
contextDepth(0),
class GD_CORE_API EventsCodeGenerationContext {
friend class EventsCodeGenerator;
public:
/**
* Default constructor. You may want to call InheritsFrom just after.
* \param maxDepthLevel Optional pointer to an unsigned integer that will be
* updated to contain the maximal scope depth reached.
*/
EventsCodeGenerationContext(unsigned int* maxDepthLevel_ = nullptr)
: contextDepth(0),
customConditionDepth(0),
maxDepthLevel(maxDepthLevel_),
parent(NULL),
reuseExplicitlyForbidden(false)
{};
virtual ~EventsCodeGenerationContext() {};
reuseExplicitlyForbidden(false){};
virtual ~EventsCodeGenerationContext(){};
/**
* Call this method to make an EventsCodeGenerationContext as a "child" of another one.
* The child will then for example not declare again objects already declared by its parent.
*/
void InheritsFrom(const EventsCodeGenerationContext & parent);
/**
* Call this method to make an EventsCodeGenerationContext as a "child" of
* another one. The child will then for example not declare again objects
* already declared by its parent.
*/
void InheritsFrom(const EventsCodeGenerationContext& parent);
/**
* \brief As InheritsFrom, mark the context as being the child of another one, but enabling
* the child context to use the same object lists.
*
* Used for example for optimizing the last event of a list.
*/
void Reuse(const EventsCodeGenerationContext & parent);
/**
* \brief As InheritsFrom, mark the context as being the child of another one,
* but enabling the child context to use the same object lists.
*
* Used for example for optimizing the last event of a list.
*/
void Reuse(const EventsCodeGenerationContext& parent);
/**
* \brief Forbid any optimization that would reuse and modify the object list from this context
* in children context.
*
* Used in while/for each/repeat or any event that have a loop and must ensure that
* the list of objects stay clean.
*/
void ForbidReuse() { reuseExplicitlyForbidden = true; }
/**
* \brief Forbid any optimization that would reuse and modify the object list
* from this context in children context.
*
* Used in while/for each/repeat or any event that have a loop and must ensure
* that the list of objects stay clean.
*/
void ForbidReuse() { reuseExplicitlyForbidden = true; }
/**
* \brief Return false if the object lists of the context can not be reused in a child context.
*/
bool CanReuse() const { return !reuseExplicitlyForbidden && parent != nullptr; }
/**
* \brief Return false if the object lists of the context can not be reused in
* a child context.
*/
bool CanReuse() const {
return !reuseExplicitlyForbidden && parent != nullptr;
}
/**
* \brief Returns the depth of the inheritance of the context.
*
* A context created from scratch will returns 0, and a context inheriting from a context with depth n will returns n+1.
*/
size_t GetContextDepth() const { return contextDepth; }
/**
* \brief Returns the depth of the inheritance of the context.
*
* A context created from scratch will returns 0, and a context inheriting
* from a context with depth n will returns n+1.
*/
size_t GetContextDepth() const { return contextDepth; }
/**
* \brief Get the parent context, if any.
* \return A pointer to the parent context, or NULL if the context has no parent.
*/
const EventsCodeGenerationContext * GetParentContext() const { return parent; }
/**
* \brief Get the parent context, if any.
* \return A pointer to the parent context, or NULL if the context has no
* parent.
*/
const EventsCodeGenerationContext* GetParentContext() const { return parent; }
/**
* Mark the object has being the object being handled by the instruction
*/
void SetCurrentObject(const gd::String & objectName) { currentObject = objectName; };
/**
* Mark the object has being the object being handled by the instruction
*/
void SetCurrentObject(const gd::String& objectName) {
currentObject = objectName;
};
/**
* Set that no particular object is being handled by an instruction
*/
void SetNoCurrentObject() { currentObject = ""; };
/**
* Set that no particular object is being handled by an instruction
*/
void SetNoCurrentObject() { currentObject = ""; };
/**
* Get the object being handled by the instruction
*/
const gd::String & GetCurrentObject() const { return currentObject; };
/**
* Get the object being handled by the instruction
*/
const gd::String& GetCurrentObject() const { return currentObject; };
/**
* \brief Call this when an instruction in the event need an object list.
*
* The list will be filled with objects from the scene if it is the first time it is requested, unless there is
* already an object list with this name ( i.e. ObjectAlreadyDeclared(objectName) returns true ).
*/
void ObjectsListNeeded(const gd::String & objectName);
/**
* \brief Call this when an instruction in the event need an object list.
*
* The list will be filled with objects from the scene if it is the first time
* it is requested, unless there is already an object list with this name (
* i.e. ObjectAlreadyDeclared(objectName) returns true ).
*/
void ObjectsListNeeded(const gd::String& objectName);
/**
* Call this when an instruction in the event need an object list.
* An empty event list will be declared, without filling it with objects from the scene. If there is already an object
* list with this name, no new list will be declared again.
*/
void EmptyObjectsListNeeded(const gd::String & objectName);
/**
* Call this when an instruction in the event need an object list.
* An empty event list will be declared, without filling it with objects from
* the scene. If there is already an object list with this name, no new list
* will be declared again.
*/
void EmptyObjectsListNeeded(const gd::String& objectName);
/**
* Return true if an object list has already been declared (or is going to be declared).
*/
bool ObjectAlreadyDeclared(const gd::String & objectName) const { return (alreadyDeclaredObjectsLists.find(objectName) != alreadyDeclaredObjectsLists.end()); };
/**
* Return true if an object list has already been declared (or is going to be
* declared).
*/
bool ObjectAlreadyDeclared(const gd::String& objectName) const {
return (alreadyDeclaredObjectsLists.find(objectName) !=
alreadyDeclaredObjectsLists.end());
};
/**
* \brief Consider that \a objectName is now declared in the context.
*/
void SetObjectDeclared(const gd::String & objectName) { alreadyDeclaredObjectsLists.insert(objectName); }
/**
* \brief Consider that \a objectName is now declared in the context.
*/
void SetObjectDeclared(const gd::String& objectName) {
alreadyDeclaredObjectsLists.insert(objectName);
}
/**
* Return all the objects lists which will be declared by the current context
* ( the non empty as well as the empty objects lists )
*/
std::set<gd::String> GetAllObjectsToBeDeclared() const;
/**
* Return all the objects lists which will be declared by the current context
* ( the non empty as well as the empty objects lists )
*/
std::set<gd::String> GetAllObjectsToBeDeclared() const;
/**
* Return the objects lists which will be declared by the current context
*/
const std::set<gd::String> & GetObjectsListsToBeDeclared() const { return objectsListsToBeDeclared; };
/**
* Return the objects lists which will be declared by the current context
*/
const std::set<gd::String>& GetObjectsListsToBeDeclared() const {
return objectsListsToBeDeclared;
};
/**
* Return the objects lists which will be declared, but no filled, by the current context
*/
const std::set<gd::String> & GetObjectsListsToBeDeclaredEmpty() const { return emptyObjectsListsToBeDeclared; };
/**
* Return the objects lists which will be declared, but no filled, by the
* current context
*/
const std::set<gd::String>& GetObjectsListsToBeDeclaredEmpty() const {
return emptyObjectsListsToBeDeclared;
};
/**
* Return the objects lists which are already declared and can be used in the current context without declaration.
*/
const std::set<gd::String> & GetObjectsListsAlreadyDeclared() const { return alreadyDeclaredObjectsLists; };
/**
* Return the objects lists which are already declared and can be used in the
* current context without declaration.
*/
const std::set<gd::String>& GetObjectsListsAlreadyDeclared() const {
return alreadyDeclaredObjectsLists;
};
/**
* \brief Get the depth of the context that was in effect when \a objectName was needed.
*
* If \a objectName is needed in this context, it will return the depth of this context.
*/
unsigned int GetLastDepthObjectListWasNeeded(const gd::String & objectName) const;
/**
* \brief Get the depth of the context that was in effect when \a objectName
* was needed.
*
* If \a objectName is needed in this context, it will return the depth of
* this context.
*/
unsigned int GetLastDepthObjectListWasNeeded(
const gd::String& objectName) const;
/**
* \brief Check if twos context have the same list for an object.
*
* This can be the case when a context is reusing the lists of another (see gd::EventsCodeGenerationContext::Reuse).
*/
bool IsSameObjectsList(const gd::String & objectName, const EventsCodeGenerationContext & otherContext) const;
/**
* \brief Check if twos context have the same list for an object.
*
* This can be the case when a context is reusing the lists of another (see
* gd::EventsCodeGenerationContext::Reuse).
*/
bool IsSameObjectsList(const gd::String& objectName,
const EventsCodeGenerationContext& otherContext) const;
/**
* \brief Called when a custom condition code is generated.
*/
void EnterCustomCondition() { customConditionDepth++; };
/**
* \brief Called when a custom condition code is generated.
*/
void EnterCustomCondition() { customConditionDepth++; };
/**
* \brief Called when a custom condition code generation is over.
*/
void LeaveCustomCondition() { customConditionDepth--; };
/**
* \brief Called when a custom condition code generation is over.
*/
void LeaveCustomCondition() { customConditionDepth--; };
/**
* \brief Get the current condition depth : The depth is increased each time a custom condition code is generated,
* and decreased when the condition generation is done.
*
* This can be useful to generate sub conditions booleans with a different name than the parent's conditions.
*/
size_t GetCurrentConditionDepth() const { return customConditionDepth; }
/**
* \brief Get the current condition depth : The depth is increased each time a
* custom condition code is generated, and decreased when the condition
* generation is done.
*
* This can be useful to generate sub conditions booleans with a different
* name than the parent's conditions.
*/
size_t GetCurrentConditionDepth() const { return customConditionDepth; }
private:
std::set<gd::String> alreadyDeclaredObjectsLists; ///< Objects lists already needed in a parent context.
std::set<gd::String> objectsListsToBeDeclared; ///< Objects lists that will be declared in this context.
std::set<gd::String> emptyObjectsListsToBeDeclared; ///< Objects lists that will be declared in this context, but not filled with scene's objects.
std::map<gd::String, unsigned int> depthOfLastUse; ///< The context depth when an object was last used.
gd::String currentObject; ///< The object being used by an action or condition.
unsigned int contextDepth; ///< The depth of the context : 0 for a newly created context, n+1 for any context inheriting from context with depth n.
unsigned int customConditionDepth; ///< The depth of the conditions being generated.
unsigned int * maxDepthLevel; ///< A pointer to a unsigned int updated with the maximum depth reached.
const EventsCodeGenerationContext * parent; ///< The parent of the current context. Can be NULL.
bool reuseExplicitlyForbidden; ///< If set to true, forbid children context to reuse this one without inheriting.
private:
std::set<gd::String>
alreadyDeclaredObjectsLists; ///< Objects lists already needed in a
///< parent context.
std::set<gd::String>
objectsListsToBeDeclared; ///< Objects lists that will be declared in
///< this context.
std::set<gd::String>
emptyObjectsListsToBeDeclared; ///< Objects lists that will be declared
///< in this context, but not filled with
///< scene's objects.
std::map<gd::String, unsigned int>
depthOfLastUse; ///< The context depth when an object was last used.
gd::String
currentObject; ///< The object being used by an action or condition.
unsigned int contextDepth; ///< The depth of the context : 0 for a newly
///< created context, n+1 for any context
///< inheriting from context with depth n.
unsigned int
customConditionDepth; ///< The depth of the conditions being generated.
unsigned int* maxDepthLevel; ///< A pointer to a unsigned int updated with
///< the maximum depth reached.
const EventsCodeGenerationContext*
parent; ///< The parent of the current context. Can be NULL.
bool reuseExplicitlyForbidden; ///< If set to true, forbid children context
///< to reuse this one without inheriting.
};
}
#endif // EVENTSCODEGENERATIONCONTEXT_H
} // namespace gd
#endif // EVENTSCODEGENERATIONCONTEXT_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,200 +1,229 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "ExpressionsCodeGeneration.h"
#include "GDCore/Project/Project.h"
#include "GDCore/Project/Layout.h"
#include "GDCore/CommonTools.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerationContext.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerator.h"
#include "GDCore/Events/Parsers/ExpressionParser.h"
#include "GDCore/Events/Tools/EventsCodeNameMangler.h"
#include "GDCore/Extensions/Metadata/BehaviorMetadata.h"
#include "GDCore/Extensions/Metadata/ExpressionMetadata.h"
#include "GDCore/Extensions/Metadata/MetadataProvider.h"
#include "GDCore/Extensions/Metadata/ObjectMetadata.h"
#include "GDCore/Extensions/Platform.h"
#include "GDCore/Extensions/PlatformExtension.h"
#include "GDCore/Extensions/Metadata/MetadataProvider.h"
#include "GDCore/Events/Parsers/ExpressionParser.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerator.h"
#include "GDCore/Events/Tools/EventsCodeNameMangler.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerationContext.h"
#include "GDCore/Extensions/Metadata/ExpressionMetadata.h"
#include "GDCore/Extensions/Metadata/ObjectMetadata.h"
#include "GDCore/Extensions/Metadata/BehaviorMetadata.h"
#include "GDCore/CommonTools.h"
#include "GDCore/Project/Layout.h"
#include "GDCore/Project/Project.h"
using namespace std;
namespace gd
{
namespace gd {
CallbacksForGeneratingExpressionCode::CallbacksForGeneratingExpressionCode(gd::String & plainExpression_,
EventsCodeGenerator & codeGenerator_,
EventsCodeGenerationContext & context_) :
plainExpression(plainExpression_),
codeGenerator(codeGenerator_),
context(context_)
{
CallbacksForGeneratingExpressionCode::CallbacksForGeneratingExpressionCode(
gd::String& plainExpression_,
EventsCodeGenerator& codeGenerator_,
EventsCodeGenerationContext& context_)
: plainExpression(plainExpression_),
codeGenerator(codeGenerator_),
context(context_) {}
}
void CallbacksForGeneratingExpressionCode::OnConstantToken(gd::String text)
{
plainExpression += text;
void CallbacksForGeneratingExpressionCode::OnConstantToken(gd::String text) {
plainExpression += text;
};
void CallbacksForGeneratingExpressionCode::OnStaticFunction(gd::String functionName, const std::vector<gd::Expression> & parameters, const gd::ExpressionMetadata & expressionInfo)
{
codeGenerator.AddIncludeFiles(expressionInfo.codeExtraInformation.GetIncludeFiles());
void CallbacksForGeneratingExpressionCode::OnStaticFunction(
gd::String functionName,
const std::vector<gd::Expression>& parameters,
const gd::ExpressionMetadata& expressionInfo) {
codeGenerator.AddIncludeFiles(
expressionInfo.codeExtraInformation.GetIncludeFiles());
//Launch custom code generator if needed
if (expressionInfo.codeExtraInformation.HasCustomCodeGenerator())
{
plainExpression += expressionInfo.codeExtraInformation.customCodeGenerator(parameters, codeGenerator, context);
return;
}
// Launch custom code generator if needed
if (expressionInfo.codeExtraInformation.HasCustomCodeGenerator()) {
plainExpression += expressionInfo.codeExtraInformation.customCodeGenerator(
parameters, codeGenerator, context);
return;
}
//Special case: For strings expressions, function without name is a string.
if ( GetReturnType() == "string" && functionName.empty() )
{
if ( parameters.empty() ) return;
plainExpression += codeGenerator.ConvertToStringExplicit(parameters[0].GetPlainString());
// Special case: For strings expressions, function without name is a string.
if (GetReturnType() == "string" && functionName.empty()) {
if (parameters.empty()) return;
plainExpression +=
codeGenerator.ConvertToStringExplicit(parameters[0].GetPlainString());
return;
}
return;
}
//Prepare parameters
std::vector<gd::String> parametersCode = codeGenerator.GenerateParametersCodes(parameters, expressionInfo.parameters, context);
gd::String parametersStr;
for (std::size_t i = 0;i<parametersCode.size();++i)
{
if ( i != 0 ) parametersStr += ", ";
parametersStr += parametersCode[i];
}
// Prepare parameters
std::vector<gd::String> parametersCode =
codeGenerator.GenerateParametersCodes(
parameters, expressionInfo.parameters, context);
gd::String parametersStr;
for (std::size_t i = 0; i < parametersCode.size(); ++i) {
if (i != 0) parametersStr += ", ";
parametersStr += parametersCode[i];
}
plainExpression += expressionInfo.codeExtraInformation.functionCallName+"("+parametersStr+")";
plainExpression += expressionInfo.codeExtraInformation.functionCallName +
"(" + parametersStr + ")";
};
void CallbacksForGeneratingExpressionCode::OnObjectFunction(gd::String functionName, const std::vector<gd::Expression> & parameters, const gd::ExpressionMetadata & expressionInfo)
{
const gd::Project & project = codeGenerator.GetProject();
const gd::Layout & scene = codeGenerator.GetLayout();
void CallbacksForGeneratingExpressionCode::OnObjectFunction(
gd::String functionName,
const std::vector<gd::Expression>& parameters,
const gd::ExpressionMetadata& expressionInfo) {
const gd::Project& project = codeGenerator.GetProject();
const gd::Layout& scene = codeGenerator.GetLayout();
codeGenerator.AddIncludeFiles(expressionInfo.codeExtraInformation.GetIncludeFiles());
if ( parameters.empty() ) return;
codeGenerator.AddIncludeFiles(
expressionInfo.codeExtraInformation.GetIncludeFiles());
if (parameters.empty()) return;
//Launch custom code generator if needed
if ( expressionInfo.codeExtraInformation.HasCustomCodeGenerator() )
{
plainExpression += expressionInfo.codeExtraInformation.customCodeGenerator(parameters, codeGenerator, context);
return;
}
// Launch custom code generator if needed
if (expressionInfo.codeExtraInformation.HasCustomCodeGenerator()) {
plainExpression += expressionInfo.codeExtraInformation.customCodeGenerator(
parameters, codeGenerator, context);
return;
}
//Prepare parameters
std::vector<gd::String> parametersCode = codeGenerator.GenerateParametersCodes(parameters, expressionInfo.parameters, context);
gd::String parametersStr;
for (std::size_t i = 1;i<parametersCode.size();++i)
{
if ( i != 1 ) parametersStr += ", ";
parametersStr += parametersCode[i];
}
// Prepare parameters
std::vector<gd::String> parametersCode =
codeGenerator.GenerateParametersCodes(
parameters, expressionInfo.parameters, context);
gd::String parametersStr;
for (std::size_t i = 1; i < parametersCode.size(); ++i) {
if (i != 1) parametersStr += ", ";
parametersStr += parametersCode[i];
}
gd::String output = GetReturnType() == "string" ? "\"\"" : "0";
gd::String output = GetReturnType() == "string" ? "\"\"" : "0";
//Get object(s) concerned by function call
std::vector<gd::String> realObjects = codeGenerator. ExpandObjectsName(parameters[0].GetPlainString(), context);
for (std::size_t i = 0;i<realObjects.size();++i)
{
context.ObjectsListNeeded(realObjects[i]);
// Get object(s) concerned by function call
std::vector<gd::String> realObjects =
codeGenerator.ExpandObjectsName(parameters[0].GetPlainString(), context);
for (std::size_t i = 0; i < realObjects.size(); ++i) {
context.ObjectsListNeeded(realObjects[i]);
gd::String objectType = gd::GetTypeOfObject(project, scene, realObjects[i]);
const ObjectMetadata & objInfo = MetadataProvider::GetObjectMetadata(codeGenerator.GetPlatform(), objectType);
gd::String objectType = gd::GetTypeOfObject(project, scene, realObjects[i]);
const ObjectMetadata& objInfo = MetadataProvider::GetObjectMetadata(
codeGenerator.GetPlatform(), objectType);
//Build gd::String to access the object
codeGenerator.AddIncludeFiles(objInfo.includeFiles);
output = codeGenerator.GenerateObjectFunctionCall(realObjects[i], objInfo, expressionInfo.codeExtraInformation, parametersStr, output, context);
}
// Build gd::String to access the object
codeGenerator.AddIncludeFiles(objInfo.includeFiles);
output = codeGenerator.GenerateObjectFunctionCall(
realObjects[i],
objInfo,
expressionInfo.codeExtraInformation,
parametersStr,
output,
context);
}
plainExpression += output;
plainExpression += output;
};
void CallbacksForGeneratingExpressionCode::OnObjectBehaviorFunction(gd::String functionName, const std::vector<gd::Expression> & parameters, const gd::ExpressionMetadata & expressionInfo)
{
const gd::Project & project = codeGenerator.GetProject();
const gd::Layout & scene = codeGenerator.GetLayout();
void CallbacksForGeneratingExpressionCode::OnObjectBehaviorFunction(
gd::String functionName,
const std::vector<gd::Expression>& parameters,
const gd::ExpressionMetadata& expressionInfo) {
const gd::Project& project = codeGenerator.GetProject();
const gd::Layout& scene = codeGenerator.GetLayout();
codeGenerator.AddIncludeFiles(expressionInfo.codeExtraInformation.GetIncludeFiles());
if ( parameters.size() < 2 ) return;
codeGenerator.AddIncludeFiles(
expressionInfo.codeExtraInformation.GetIncludeFiles());
if (parameters.size() < 2) return;
//Launch custom code generator if needed
if ( expressionInfo.codeExtraInformation.HasCustomCodeGenerator() )
{
plainExpression += expressionInfo.codeExtraInformation.customCodeGenerator(parameters, codeGenerator, context);
return;
}
// Launch custom code generator if needed
if (expressionInfo.codeExtraInformation.HasCustomCodeGenerator()) {
plainExpression += expressionInfo.codeExtraInformation.customCodeGenerator(
parameters, codeGenerator, context);
return;
}
//Prepare parameters
std::vector<gd::String> parametersCode = codeGenerator.GenerateParametersCodes(parameters, expressionInfo.parameters, context);
gd::String parametersStr;
for (std::size_t i = 2;i<parametersCode.size();++i)
{
if ( i != 2 ) parametersStr += ", ";
parametersStr += parametersCode[i];
}
// Prepare parameters
std::vector<gd::String> parametersCode =
codeGenerator.GenerateParametersCodes(
parameters, expressionInfo.parameters, context);
gd::String parametersStr;
for (std::size_t i = 2; i < parametersCode.size(); ++i) {
if (i != 2) parametersStr += ", ";
parametersStr += parametersCode[i];
}
//Get object(s) concerned by function call
std::vector<gd::String> realObjects = codeGenerator. ExpandObjectsName(parameters[0].GetPlainString(), context);
// Get object(s) concerned by function call
std::vector<gd::String> realObjects =
codeGenerator.ExpandObjectsName(parameters[0].GetPlainString(), context);
gd::String output = GetReturnType() == "string" ? "\"\"" : "0";
for (std::size_t i = 0;i<realObjects.size();++i)
{
context.ObjectsListNeeded(realObjects[i]);
gd::String output = GetReturnType() == "string" ? "\"\"" : "0";
for (std::size_t i = 0; i < realObjects.size(); ++i) {
context.ObjectsListNeeded(realObjects[i]);
//Cast the object if needed
gd::String behaviorType = gd::GetTypeOfBehavior(project, scene, parameters[1].GetPlainString());
const BehaviorMetadata & autoInfo = MetadataProvider::GetBehaviorMetadata(codeGenerator.GetPlatform(), behaviorType);
// Cast the object if needed
gd::String behaviorType =
gd::GetTypeOfBehavior(project, scene, parameters[1].GetPlainString());
const BehaviorMetadata& autoInfo = MetadataProvider::GetBehaviorMetadata(
codeGenerator.GetPlatform(), behaviorType);
//Build gd::String to access the behavior
codeGenerator.AddIncludeFiles(autoInfo.includeFiles);
output = codeGenerator.GenerateObjectBehaviorFunctionCall(realObjects[i], parameters[1].GetPlainString(), autoInfo, expressionInfo.codeExtraInformation, parametersStr, output, context);
}
// Build gd::String to access the behavior
codeGenerator.AddIncludeFiles(autoInfo.includeFiles);
output = codeGenerator.GenerateObjectBehaviorFunctionCall(
realObjects[i],
parameters[1].GetPlainString(),
autoInfo,
expressionInfo.codeExtraInformation,
parametersStr,
output,
context);
}
plainExpression += output;
plainExpression += output;
};
bool CallbacksForGeneratingExpressionCode::OnSubMathExpression(const gd::Platform & platform, const gd::Project & project, const gd::Layout & layout, gd::Expression & expression)
{
gd::String newExpression;
bool CallbacksForGeneratingExpressionCode::OnSubMathExpression(
const gd::Platform& platform,
const gd::Project& project,
const gd::Layout& layout,
gd::Expression& expression) {
gd::String newExpression;
CallbacksForGeneratingExpressionCode callbacks(newExpression, codeGenerator, context);
CallbacksForGeneratingExpressionCode callbacks(
newExpression, codeGenerator, context);
gd::ExpressionParser parser(expression.GetPlainString());
if ( !parser.ParseMathExpression(platform, project, layout, callbacks) )
{
#if defined(GD_IDE_ONLY)
firstErrorStr = callbacks.GetFirstError();
firstErrorPos = callbacks.GetFirstErrorPosition();
#endif
return false;
}
gd::ExpressionParser parser(expression.GetPlainString());
if (!parser.ParseMathExpression(platform, project, layout, callbacks)) {
#if defined(GD_IDE_ONLY)
firstErrorStr = callbacks.GetFirstError();
firstErrorPos = callbacks.GetFirstErrorPosition();
#endif
return false;
}
return true;
return true;
}
bool CallbacksForGeneratingExpressionCode::OnSubTextExpression(const gd::Platform & platform, const gd::Project & project, const gd::Layout & layout, gd::Expression & expression)
{
gd::String newExpression;
bool CallbacksForGeneratingExpressionCode::OnSubTextExpression(
const gd::Platform& platform,
const gd::Project& project,
const gd::Layout& layout,
gd::Expression& expression) {
gd::String newExpression;
CallbacksForGeneratingExpressionCode callbacks(newExpression, codeGenerator, context);
CallbacksForGeneratingExpressionCode callbacks(
newExpression, codeGenerator, context);
gd::ExpressionParser parser(expression.GetPlainString());
if ( !parser.ParseStringExpression(platform, project, layout, callbacks) )
{
#if defined(GD_IDE_ONLY)
firstErrorStr = callbacks.GetFirstError();
firstErrorPos = callbacks.GetFirstErrorPosition();
#endif
return false;
}
gd::ExpressionParser parser(expression.GetPlainString());
if (!parser.ParseStringExpression(platform, project, layout, callbacks)) {
#if defined(GD_IDE_ONLY)
firstErrorStr = callbacks.GetFirstError();
firstErrorPos = callbacks.GetFirstErrorPosition();
#endif
return false;
}
return true;
return true;
}
}
} // namespace gd

View File

@@ -1,24 +1,37 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef EXPRESSIONSCODEGENERATION_H
#define EXPRESSIONSCODEGENERATION_H
#include <vector>
#include "GDCore/String.h"
#include "GDCore/Events/Parsers/ExpressionParser.h"
namespace gd { class ExpressionMetadata; }
namespace gd { class Expression; }
namespace gd { class Project; }
namespace gd { class Layout; }
namespace gd { class Layout; }
namespace gd { class EventsCodeGenerationContext; }
namespace gd { class EventsCodeGenerator; }
#include "GDCore/String.h"
namespace gd {
class ExpressionMetadata;
}
namespace gd {
class Expression;
}
namespace gd {
class Project;
}
namespace gd {
class Layout;
}
namespace gd {
class Layout;
}
namespace gd {
class EventsCodeGenerationContext;
}
namespace gd {
class EventsCodeGenerator;
}
namespace gd
{
namespace gd {
/**
* \brief Used to generate code from expressions.
@@ -27,33 +40,48 @@ namespace gd
* \code
* gd::String expressionOutputCppCode;
*
* CallbacksForGeneratingExpressionCode callbacks(expressionOutputCppCode, codeGenerator, context);
* gd::ExpressionParser parser(theOriginalGameDevelopExpression);
* CallbacksForGeneratingExpressionCode callbacks(expressionOutputCppCode,
* codeGenerator, context); gd::ExpressionParser
* parser(theOriginalGameDevelopExpression);
* parser.ParseStringExpression(platform, project, scene, callbacks);
*
* if (expressionOutputCppCode.empty()) expressionOutputCppCode = "\"\""; //If generation failed, we make sure output code is not empty.
* \endcode
* \see EventsCodeGenerator
* if (expressionOutputCppCode.empty()) expressionOutputCppCode = "\"\""; //If
* generation failed, we make sure output code is not empty. \endcode \see
* EventsCodeGenerator
*/
class GD_CORE_API CallbacksForGeneratingExpressionCode : public gd::ParserCallbacks
{
public:
CallbacksForGeneratingExpressionCode(gd::String & output, EventsCodeGenerator & codeGenerator_, EventsCodeGenerationContext & context_);
virtual ~CallbacksForGeneratingExpressionCode() {};
class GD_CORE_API CallbacksForGeneratingExpressionCode
: public gd::ParserCallbacks {
public:
CallbacksForGeneratingExpressionCode(gd::String& output,
EventsCodeGenerator& codeGenerator_,
EventsCodeGenerationContext& context_);
virtual ~CallbacksForGeneratingExpressionCode(){};
void OnConstantToken(gd::String text);
void OnStaticFunction(gd::String functionName, const std::vector<gd::Expression> & parameters, const gd::ExpressionMetadata & expressionInfo);
void OnObjectFunction(gd::String functionName, const std::vector<gd::Expression> & parameters, const gd::ExpressionMetadata & expressionInfo);
void OnObjectBehaviorFunction(gd::String functionName, const std::vector<gd::Expression> & parameters, const gd::ExpressionMetadata & expressionInfo);
bool OnSubMathExpression(const gd::Platform & platform, const gd::Project & project, const gd::Layout & layout, gd::Expression & expression);
bool OnSubTextExpression(const gd::Platform & platform, const gd::Project & project, const gd::Layout & layout, gd::Expression & expression);
void OnConstantToken(gd::String text);
void OnStaticFunction(gd::String functionName,
const std::vector<gd::Expression>& parameters,
const gd::ExpressionMetadata& expressionInfo);
void OnObjectFunction(gd::String functionName,
const std::vector<gd::Expression>& parameters,
const gd::ExpressionMetadata& expressionInfo);
void OnObjectBehaviorFunction(gd::String functionName,
const std::vector<gd::Expression>& parameters,
const gd::ExpressionMetadata& expressionInfo);
bool OnSubMathExpression(const gd::Platform& platform,
const gd::Project& project,
const gd::Layout& layout,
gd::Expression& expression);
bool OnSubTextExpression(const gd::Platform& platform,
const gd::Project& project,
const gd::Layout& layout,
gd::Expression& expression);
private:
gd::String & plainExpression;
EventsCodeGenerator & codeGenerator;
EventsCodeGenerationContext & context;
private:
gd::String& plainExpression;
EventsCodeGenerator& codeGenerator;
EventsCodeGenerationContext& context;
};
}
} // namespace gd
#endif // EXPRESSIONSCODEGENERATION_H
#endif // EXPRESSIONSCODEGENERATION_H

View File

@@ -1,120 +1,120 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "GDCore/Events/Event.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerator.h"
#include "GDCore/Events/EventsList.h"
#include "GDCore/Extensions/Platform.h"
#include "GDCore/Extensions/PlatformExtension.h"
#include "GDCore/Events/CodeGeneration/EventsCodeGenerator.h"
namespace gd
{
namespace gd {
EventsList BaseEvent::badSubEvents;
std::vector< gd::String > BaseEvent::emptyDependencies;
std::vector<gd::String> BaseEvent::emptyDependencies;
gd::String BaseEvent::emptySourceFile;
BaseEvent::BaseEvent() :
eventHeightNeedUpdate(true),
totalTimeDuringLastSession(0),
percentDuringLastSession(0),
disabled(false),
folded(false)
{
}
BaseEvent::BaseEvent()
: eventHeightNeedUpdate(true),
totalTimeDuringLastSession(0),
percentDuringLastSession(0),
disabled(false),
folded(false) {}
bool BaseEvent::HasSubEvents() const
{
return !GetSubEvents().IsEmpty();
}
bool BaseEvent::HasSubEvents() const { return !GetSubEvents().IsEmpty(); }
gd::String BaseEvent::GenerateEventCode(gd::EventsCodeGenerator & codeGenerator, gd::EventsCodeGenerationContext & context)
{
if ( IsDisabled() ) return "";
gd::String BaseEvent::GenerateEventCode(
gd::EventsCodeGenerator& codeGenerator,
gd::EventsCodeGenerationContext& context) {
if (IsDisabled()) return "";
try
{
if ( type.empty() ) return "";
try {
if (type.empty()) return "";
const gd::Platform & platform = codeGenerator.GetPlatform();
const gd::Platform& platform = codeGenerator.GetPlatform();
//First try to guess the extension used
gd::String eventNamespace = type.substr(0, type.find("::"));
std::shared_ptr<gd::PlatformExtension> guessedExtension = platform.GetExtension(eventNamespace);
if ( guessedExtension )
{
std::map<gd::String, gd::EventMetadata > & allEvents = guessedExtension->GetAllEvents();
if ( allEvents.find(type) != allEvents.end() )
return allEvents[type].codeGeneration(*this, codeGenerator, context);
}
//Else make a search in all the extensions
for (std::size_t i = 0; i < platform.GetAllPlatformExtensions().size(); ++i)
{
std::shared_ptr<gd::PlatformExtension> extension = platform.GetAllPlatformExtensions()[i];
if ( !extension ) continue;
std::map<gd::String, gd::EventMetadata > & allEvents = extension->GetAllEvents();
if ( allEvents.find(type) != allEvents.end() )
return allEvents[type].codeGeneration(*this, codeGenerator, context);
}
}
catch(...)
{
std::cout << "ERROR: Exception caught during code generation for event \"" << type <<"\"." << std::endl;
// First try to guess the extension used
gd::String eventNamespace = type.substr(0, type.find("::"));
std::shared_ptr<gd::PlatformExtension> guessedExtension =
platform.GetExtension(eventNamespace);
if (guessedExtension) {
std::map<gd::String, gd::EventMetadata>& allEvents =
guessedExtension->GetAllEvents();
if (allEvents.find(type) != allEvents.end())
return allEvents[type].codeGeneration(*this, codeGenerator, context);
}
return "";
}
// Else make a search in all the extensions
for (std::size_t i = 0; i < platform.GetAllPlatformExtensions().size();
++i) {
std::shared_ptr<gd::PlatformExtension> extension =
platform.GetAllPlatformExtensions()[i];
if (!extension) continue;
void BaseEvent::Preprocess(gd::EventsCodeGenerator & codeGenerator, gd::EventsList & eventList, std::size_t indexOfTheEventInThisList)
{
if ( IsDisabled() || !MustBePreprocessed() ) return;
try
{
if ( type.empty() ) return;
const gd::Platform & platform = codeGenerator.GetPlatform();
//First try to guess the extension used
gd::String eventNamespace = type.substr(0, type.find("::"));
std::shared_ptr<gd::PlatformExtension> guessedExtension = platform.GetExtension(eventNamespace);
if ( guessedExtension )
{
std::map<gd::String, gd::EventMetadata > & allEvents = guessedExtension->GetAllEvents();
if ( allEvents.find(type) != allEvents.end() )
return allEvents[type].preprocessing(*this, codeGenerator, eventList, indexOfTheEventInThisList);
}
//Else make a search in all the extensions
for (std::size_t i = 0;i<platform.GetAllPlatformExtensions().size();++i)
{
std::shared_ptr<gd::PlatformExtension> extension = platform.GetAllPlatformExtensions()[i];
if ( !extension ) continue;
std::map<gd::String, gd::EventMetadata > & allEvents = extension->GetAllEvents();
if ( allEvents.find(type) != allEvents.end() )
return allEvents[type].preprocessing(*this, codeGenerator, eventList, indexOfTheEventInThisList);
}
std::map<gd::String, gd::EventMetadata>& allEvents =
extension->GetAllEvents();
if (allEvents.find(type) != allEvents.end())
return allEvents[type].codeGeneration(*this, codeGenerator, context);
}
catch(...)
{
std::cout << "ERROR: Exception caught during preprocessing of event \"" << type <<"\"." << std::endl;
} catch (...) {
std::cout << "ERROR: Exception caught during code generation for event \""
<< type << "\"." << std::endl;
}
return "";
}
void BaseEvent::Preprocess(gd::EventsCodeGenerator& codeGenerator,
gd::EventsList& eventList,
std::size_t indexOfTheEventInThisList) {
if (IsDisabled() || !MustBePreprocessed()) return;
try {
if (type.empty()) return;
const gd::Platform& platform = codeGenerator.GetPlatform();
// First try to guess the extension used
gd::String eventNamespace = type.substr(0, type.find("::"));
std::shared_ptr<gd::PlatformExtension> guessedExtension =
platform.GetExtension(eventNamespace);
if (guessedExtension) {
std::map<gd::String, gd::EventMetadata>& allEvents =
guessedExtension->GetAllEvents();
if (allEvents.find(type) != allEvents.end())
return allEvents[type].preprocessing(
*this, codeGenerator, eventList, indexOfTheEventInThisList);
}
// Else make a search in all the extensions
for (std::size_t i = 0; i < platform.GetAllPlatformExtensions().size();
++i) {
std::shared_ptr<gd::PlatformExtension> extension =
platform.GetAllPlatformExtensions()[i];
if (!extension) continue;
std::map<gd::String, gd::EventMetadata>& allEvents =
extension->GetAllEvents();
if (allEvents.find(type) != allEvents.end())
return allEvents[type].preprocessing(
*this, codeGenerator, eventList, indexOfTheEventInThisList);
}
} catch (...) {
std::cout << "ERROR: Exception caught during preprocessing of event \""
<< type << "\"." << std::endl;
}
}
BaseEventSPtr GD_CORE_API CloneRememberingOriginalEvent(BaseEventSPtr event)
{
gd::BaseEventSPtr copy(event->Clone());
//Original event is either the original event of the copied event, or the event copied.
copy->originalEvent = event->originalEvent.expired() ? event : event->originalEvent;
BaseEventSPtr GD_CORE_API CloneRememberingOriginalEvent(BaseEventSPtr event) {
gd::BaseEventSPtr copy(event->Clone());
// Original event is either the original event of the copied event, or the
// event copied.
copy->originalEvent =
event->originalEvent.expired() ? event : event->originalEvent;
return copy;
return copy;
}
}
} // namespace gd

View File

@@ -1,36 +1,55 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#if defined(GD_IDE_ONLY)
#ifndef GDCORE_EVENT_H
#define GDCORE_EVENT_H
#include <iostream>
#include <vector>
#include "GDCore/String.h"
#include <vector>
#include <memory>
#include <memory>
#include <vector>
#include "GDCore/Events/Instruction.h"
#include "GDCore/Events/InstructionsList.h"
namespace gd { class EventsList; }
namespace gd { class MainFrameWrapper; }
namespace gd { class Project; }
namespace gd { class Layout; }
namespace gd { class EventsCodeGenerator; }
namespace gd { class EventsCodeGenerationContext; }
namespace gd { class Platform; }
#include "GDCore/String.h"
namespace gd {
class EventsList;
}
namespace gd {
class MainFrameWrapper;
}
namespace gd {
class Project;
}
namespace gd {
class Layout;
}
namespace gd {
class EventsCodeGenerator;
}
namespace gd {
class EventsCodeGenerationContext;
}
namespace gd {
class Platform;
}
class wxWindow;
namespace gd { class EventsEditorItemsAreas; }
namespace gd { class EventsEditorSelection; }
namespace gd { class SerializerElement; }
namespace gd { class Instruction; }
namespace gd {
class EventsEditorItemsAreas;
}
namespace gd {
class EventsEditorSelection;
}
namespace gd {
class SerializerElement;
}
namespace gd {
class Instruction;
}
class wxDC;
namespace gd
{
namespace gd {
class BaseEvent;
typedef std::shared_ptr<BaseEvent> BaseEventSPtr;
@@ -38,256 +57,326 @@ typedef std::shared_ptr<BaseEvent> BaseEventSPtr;
/**
* \brief Base class defining an event.
*
* Events are usually not instance of Base Event, but instance of a derived class.
* Events are usually not instance of Base Event, but instance of a derived
* class.
*
* \ingroup Events
*/
class GD_CORE_API BaseEvent
{
public:
BaseEvent();
virtual ~BaseEvent() {};
class GD_CORE_API BaseEvent {
public:
BaseEvent();
virtual ~BaseEvent(){};
/**
* Must return a pointer to a copy of the event.
* A such method is needed as the IDE may want to store copies of some events and so need a way to do polymorphic copies.
*
* Typical implementation example:
* \code
* return new MyEventClass(*this);
* \endcode
*/
virtual gd::BaseEvent * Clone() const { return new BaseEvent(*this);}
/**
* Must return a pointer to a copy of the event.
* A such method is needed as the IDE may want to store copies of some events
* and so need a way to do polymorphic copies.
*
* Typical implementation example:
* \code
* return new MyEventClass(*this);
* \endcode
*/
virtual gd::BaseEvent* Clone() const { return new BaseEvent(*this); }
/** \name Event properties
* Members functions to be overridden by derived classes to expose the event properties
*/
///@{
/** \name Event properties
* Members functions to be overridden by derived classes to expose the event
* properties
*/
///@{
/**
* Derived class have to redefine this function, so as to return true, if they are executable.
*/
virtual bool IsExecutable() const {return false;};
/**
* Derived class have to redefine this function, so as to return true, if they
* are executable.
*/
virtual bool IsExecutable() const { return false; };
/**
* Derived class have to redefine this function, so as to return true, if they have sub events.
*/
virtual bool CanHaveSubEvents() const {return false;}
/**
* Derived class have to redefine this function, so as to return true, if they
* have sub events.
*/
virtual bool CanHaveSubEvents() const { return false; }
/**
* Return the sub events, if applicable.
*/
virtual const gd::EventsList & GetSubEvents() const {return badSubEvents;};
/**
* Return the sub events, if applicable.
*/
virtual const gd::EventsList& GetSubEvents() const { return badSubEvents; };
/**
* Return the sub events, if applicable.
*/
virtual gd::EventsList & GetSubEvents() {return badSubEvents;};
/**
* Return the sub events, if applicable.
*/
virtual gd::EventsList& GetSubEvents() { return badSubEvents; };
/**
* \brief Return true if the events has sub events.
* \warning This is only applicable when CanHaveSubEvents() return true.
*/
bool HasSubEvents() const;
/**
* \brief Return true if the events has sub events.
* \warning This is only applicable when CanHaveSubEvents() return true.
*/
bool HasSubEvents() const;
/**
* Event must be able to return all conditions std::vector they have.
* Used to preprocess the conditions.
*/
virtual std::vector < gd::InstructionsList* > GetAllConditionsVectors() { std::vector < gd::InstructionsList* > noConditions; return noConditions; };
virtual std::vector < const gd::InstructionsList* > GetAllConditionsVectors() const { std::vector < const gd::InstructionsList* > noConditions; return noConditions; };
/**
* Event must be able to return all conditions std::vector they have.
* Used to preprocess the conditions.
*/
virtual std::vector<gd::InstructionsList*> GetAllConditionsVectors() {
std::vector<gd::InstructionsList*> noConditions;
return noConditions;
};
virtual std::vector<const gd::InstructionsList*> GetAllConditionsVectors()
const {
std::vector<const gd::InstructionsList*> noConditions;
return noConditions;
};
/**
* Event must be able to return all actions std::vector they have.
* Used to preprocess the actions.
*/
virtual std::vector < gd::InstructionsList* > GetAllActionsVectors() { std::vector < gd::InstructionsList* > noActions; return noActions; };
virtual std::vector < const gd::InstructionsList* > GetAllActionsVectors() const { std::vector < const gd::InstructionsList* > noActions; return noActions; };
/**
* Event must be able to return all actions std::vector they have.
* Used to preprocess the actions.
*/
virtual std::vector<gd::InstructionsList*> GetAllActionsVectors() {
std::vector<gd::InstructionsList*> noActions;
return noActions;
};
virtual std::vector<const gd::InstructionsList*> GetAllActionsVectors()
const {
std::vector<const gd::InstructionsList*> noActions;
return noActions;
};
/**
* Event must be able to return all expressions they have.
* Used to preprocess the expressions.
*/
virtual std::vector < gd::Expression* > GetAllExpressions() { std::vector < gd::Expression* > noExpr; return noExpr;};
virtual std::vector < const gd::Expression* > GetAllExpressions() const { std::vector < const gd::Expression* > noExpr; return noExpr;};
/**
* Event must be able to return all expressions they have.
* Used to preprocess the expressions.
*/
virtual std::vector<gd::Expression*> GetAllExpressions() {
std::vector<gd::Expression*> noExpr;
return noExpr;
};
virtual std::vector<const gd::Expression*> GetAllExpressions() const {
std::vector<const gd::Expression*> noExpr;
return noExpr;
};
/**
* \brief Returns the dependencies on source files of the project.
* \note Default implementation returns an empty list of dependencies. This is fine for most events that
* are not related to adding custom user source code.
*/
virtual const std::vector<gd::String> & GetSourceFileDependencies() const { return emptyDependencies; };
/**
* \brief Returns the dependencies on source files of the project.
* \note Default implementation returns an empty list of dependencies. This is
* fine for most events that are not related to adding custom user source
* code.
*/
virtual const std::vector<gd::String>& GetSourceFileDependencies() const {
return emptyDependencies;
};
/**
* \brief Returns the name of the source file associated with the event
* \note Default implementation returns an empty string. This is fine for most events that
* are not related to adding custom user source code.
*/
virtual const gd::String & GetAssociatedGDManagedSourceFile(gd::Project & project) const { return emptySourceFile; };
///@}
/**
* \brief Returns the name of the source file associated with the event
* \note Default implementation returns an empty string. This is fine for most
* events that are not related to adding custom user source code.
*/
virtual const gd::String& GetAssociatedGDManagedSourceFile(
gd::Project& project) const {
return emptySourceFile;
};
///@}
/** \name Code generation
* Members functions used to generate code from the event
*/
///@{
/** \name Code generation
* Members functions used to generate code from the event
*/
///@{
/**
* \brief Generate the code event: the platform provided by \a codeGenerator is asked for the EventMetadata associated to the event,
* which is then used to generate the code event.
*
* \warning Even if this method is virtual, you should never redefine it: always provide the code generation using gd::EventMetadata.
* This method is virtual as some platforms could have hidden events ( such as profiling events ) needing code generation without declaring
* the event as a part of an extension.
*
* \see gd::EventMetadata
*/
virtual gd::String GenerateEventCode(gd::EventsCodeGenerator & codeGenerator, gd::EventsCodeGenerationContext & context);
/**
* \brief Generate the code event: the platform provided by \a codeGenerator
* is asked for the EventMetadata associated to the event, which is then used
* to generate the code event.
*
* \warning Even if this method is virtual, you should never redefine it:
* always provide the code generation using gd::EventMetadata. This method is
* virtual as some platforms could have hidden events ( such as profiling
* events ) needing code generation without declaring the event as a part of
* an extension.
*
* \see gd::EventMetadata
*/
virtual gd::String GenerateEventCode(
gd::EventsCodeGenerator& codeGenerator,
gd::EventsCodeGenerationContext& context);
/**
* Called before events are compiled: the platform provided by \a codeGenerator is asked for the EventMetadata associated to the event,
* which is then used to preprocess the event.
*
* This is only done if the event MustBePreprocessed() return true.
*
* \warning Be careful if you're iterating over a list of event, a call to Preprocess can remove the event from the list!
*
* \see gd::EventMetadata
* \see gd::BaseEvent::MustBePreprocessed
*/
virtual void Preprocess(gd::EventsCodeGenerator & codeGenerator, gd::EventsList & eventList, std::size_t indexOfTheEventInThisList);
/**
* Called before events are compiled: the platform provided by \a
* codeGenerator is asked for the EventMetadata associated to the event, which
* is then used to preprocess the event.
*
* This is only done if the event MustBePreprocessed() return true.
*
* \warning Be careful if you're iterating over a list of event, a call to
* Preprocess can remove the event from the list!
*
* \see gd::EventMetadata
* \see gd::BaseEvent::MustBePreprocessed
*/
virtual void Preprocess(gd::EventsCodeGenerator& codeGenerator,
gd::EventsList& eventList,
std::size_t indexOfTheEventInThisList);
/**
* \brief If MustBePreprocessed is redefined to return true, the gd::EventMetadata::preprocessing associated to the event will be called
* to preprocess the event.
*
* \see gd::BaseEvent::Preprocess
* \see gd::EventMetadata
*/
virtual bool MustBePreprocessed() { return false;}
///@}
/**
* \brief If MustBePreprocessed is redefined to return true, the
* gd::EventMetadata::preprocessing associated to the event will be called to
* preprocess the event.
*
* \see gd::BaseEvent::Preprocess
* \see gd::EventMetadata
*/
virtual bool MustBePreprocessed() { return false; }
///@}
/** \name Serialization
*/
///@{
/**
* \brief Serialize event.
*/
virtual void SerializeTo(SerializerElement & element) const {};
/** \name Serialization
*/
///@{
/**
* \brief Serialize event.
*/
virtual void SerializeTo(SerializerElement& element) const {};
/**
* \brief Unserialize the event.
*/
virtual void UnserializeFrom(gd::Project & project, const SerializerElement & element) {};
///@}
/**
* \brief Unserialize the event.
*/
virtual void UnserializeFrom(gd::Project& project,
const SerializerElement& element){};
///@}
/** \name Common properties
* Common method shared by all events. ( No need for them to be overridden by derived classes ).
*/
///@{
/** \name Common properties
* Common method shared by all events. ( No need for them to be overridden by
* derived classes ).
*/
///@{
/**
* \brief Return the event type
*/
const gd::String & GetType() const { return type; };
/**
* \brief Return the event type
*/
const gd::String& GetType() const { return type; };
/**
* \brief Change the event type
*/
void SetType(gd::String type_) { type = type_; };
/**
* \brief Change the event type
*/
void SetType(gd::String type_) { type = type_; };
/**
* \brief Set if the event if disabled or not
*/
void SetDisabled(bool disable = true) { disabled = disable; }
/**
* \brief Set if the event if disabled or not
*/
void SetDisabled(bool disable = true) { disabled = disable; }
/**
* \brief True if event is disabled
*/
bool IsDisabled() const { return disabled; }
/**
* \brief True if event is disabled
*/
bool IsDisabled() const { return disabled; }
/**
* \brief Set if the event must be folded (i.e: sub events must
* be hidden in the events editor).
*/
void SetFolded(bool fold = true) { folded = fold; }
/**
* \brief Set if the event must be folded (i.e: sub events must
* be hidden in the events editor).
*/
void SetFolded(bool fold = true) { folded = fold; }
/**
* \brief True if the event should be folded in the events editor.
*/
bool IsFolded() const { return folded; }
/**
* \brief True if the event should be folded in the events editor.
*/
bool IsFolded() const { return folded; }
///@}
///@}
/** \name Event rendering
* Method and members used to render the event
*/
///@{
/** \name Event rendering
* Method and members used to render the event
*/
///@{
/**
* Redefine this method to draw the event.
*
* \param dc The wxWidgets drawing context to be used.
* \param x The x position where the events must be drawn.
* \param y The y position where the events must be drawn.
* \param width The width available for drawing.
* \param areas Use this object to indicate the areas where items have been drawn
* \param selection Give access to the current selection(s), to draw for example hovering or selecting effects.
*
* \note The height of the drawing must be the same as the height returned by BaseEvent::GetRenderedHeight
*
* \see gd::EventsRenderingHelper
* \see EventsEditorSelection
* \see EventsEditorItemsAreas
*/
virtual void Render(wxDC & dc, int x, int y, unsigned int width, gd::EventsEditorItemsAreas & areas, gd::EventsEditorSelection & selection, const gd::Platform & platform) {return;}
/**
* Redefine this method to draw the event.
*
* \param dc The wxWidgets drawing context to be used.
* \param x The x position where the events must be drawn.
* \param y The y position where the events must be drawn.
* \param width The width available for drawing.
* \param areas Use this object to indicate the areas where items have been
* drawn \param selection Give access to the current selection(s), to draw for
* example hovering or selecting effects.
*
* \note The height of the drawing must be the same as the height returned by
* BaseEvent::GetRenderedHeight
*
* \see gd::EventsRenderingHelper
* \see EventsEditorSelection
* \see EventsEditorItemsAreas
*/
virtual void Render(wxDC& dc,
int x,
int y,
unsigned int width,
gd::EventsEditorItemsAreas& areas,
gd::EventsEditorSelection& selection,
const gd::Platform& platform) {
return;
}
/**
* Must return the height of the event when rendered.
*
* \note The height of the drawing must be the same as the height of the drawing made by BaseEvent::Render
*/
virtual unsigned int GetRenderedHeight(unsigned int width, const gd::Platform & platform) const {return 0;};
/**
* Must return the height of the event when rendered.
*
* \note The height of the drawing must be the same as the height of the
* drawing made by BaseEvent::Render
*/
virtual unsigned int GetRenderedHeight(unsigned int width,
const gd::Platform& platform) const {
return 0;
};
/**
* Used by EditEvent to describe what sort of changes have been made to the event.
* \see BaseEvent::EditEvent
*/
enum EditEventReturnType
{
ChangesMade,
Cancelled,
ChangesMadeButNoNeedForEventsRecompilation
};
/**
* Used by EditEvent to describe what sort of changes have been made to the
* event. \see BaseEvent::EditEvent
*/
enum EditEventReturnType {
ChangesMade,
Cancelled,
ChangesMadeButNoNeedForEventsRecompilation
};
/**
* Called when the user want to edit the event.
*/
virtual EditEventReturnType EditEvent(wxWindow* parent_, gd::Project & game_, gd::Layout & scene_, gd::MainFrameWrapper & mainFrameWrapper_) { return ChangesMade; };
/**
* Called when the user want to edit the event.
*/
virtual EditEventReturnType EditEvent(
wxWindow* parent_,
gd::Project& game_,
gd::Layout& scene_,
gd::MainFrameWrapper& mainFrameWrapper_) {
return ChangesMade;
};
///@}
///@}
mutable bool eventHeightNeedUpdate; ///<Automatically set to true/false by the events editor
mutable bool eventHeightNeedUpdate; ///< Automatically set to true/false by
///< the events editor
std::weak_ptr<gd::BaseEvent> originalEvent; ///< Pointer only used for profiling events, so as to remember the original event from which it has been copied.
signed long long totalTimeDuringLastSession; ///< Total time, in microseconds, used by the event during the last run. Used for profiling.
float percentDuringLastSession; ///< Total time used by the event during the last run. Used for profiling.
std::weak_ptr<gd::BaseEvent>
originalEvent; ///< Pointer only used for profiling events, so as to
///< remember the original event from which it has been
///< copied.
signed long long
totalTimeDuringLastSession; ///< Total time, in microseconds, used by the
///< event during the last run. Used for
///< profiling.
float percentDuringLastSession; ///< Total time used by the event during the
///< last run. Used for profiling.
protected:
mutable unsigned int renderedHeight;
protected:
mutable unsigned int renderedHeight;
private:
bool folded; ///< True if the subevents should be hidden in the events editor
bool disabled; ///<True if the event is disabled and must not be executed
gd::String type; ///<Type of the event. Must be assigned at the creation. Used for saving the event for instance.
private:
bool folded; ///< True if the subevents should be hidden in the events editor
bool disabled; ///< True if the event is disabled and must not be executed
gd::String type; ///< Type of the event. Must be assigned at the creation.
///< Used for saving the event for instance.
static gd::EventsList badSubEvents;
static std::vector< gd::String > emptyDependencies;
static gd::String emptySourceFile;
static gd::EventsList badSubEvents;
static std::vector<gd::String> emptyDependencies;
static gd::String emptySourceFile;
};
/**
* Clone an event and insert a reference to the original event into the newly created event.
* Used for profiling events for example.
* Clone an event and insert a reference to the original event into the newly
* created event. Used for profiling events for example.
*
* \see BaseEvent
* \ingroup Events
@@ -298,14 +387,13 @@ BaseEventSPtr GD_CORE_API CloneRememberingOriginalEvent(BaseEventSPtr event);
* \brief Empty event doing nothing.
* \see gd::BaseEvent
*/
class EmptyEvent : public BaseEvent
{
public:
EmptyEvent() : BaseEvent() {};
virtual ~EmptyEvent() {};
class EmptyEvent : public BaseEvent {
public:
EmptyEvent() : BaseEvent(){};
virtual ~EmptyEvent(){};
};
}
} // namespace gd
#endif // GDCORE_EVENT_H
#endif // GDCORE_EVENT_H
#endif

View File

@@ -1,127 +1,116 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "EventsList.h"
#include "GDCore/Events/Event.h"
#include "GDCore/Tools/Log.h"
#include "GDCore/Project/Project.h"
#include "GDCore/Tools/Log.h"
#include "Serialization.h"
namespace gd
{
namespace gd {
EventsList::EventsList()
{
}
EventsList::EventsList() {}
void EventsList::InsertEvents(const EventsList& otherEvents,
size_t begin,
size_t end,
size_t position) {
if (begin >= otherEvents.size()) return;
if (end < begin) return;
if (end >= otherEvents.size()) end = otherEvents.size() - 1;
void EventsList::InsertEvents(const EventsList & otherEvents, size_t begin, size_t end, size_t position)
{
if (begin >= otherEvents.size()) return;
if (end < begin) return;
if (end >= otherEvents.size()) end = otherEvents.size()-1;
for (std::size_t insertPos = 0;insertPos <= (end-begin);insertPos++)
{
if (position != (size_t)-1 && position+insertPos < events.size())
events.insert(events.begin()+position+insertPos, CloneRememberingOriginalEvent(otherEvents.events[begin+insertPos]));
else
events.push_back(CloneRememberingOriginalEvent(otherEvents.events[begin+insertPos]));
}
}
gd::BaseEvent & EventsList::InsertEvent(const gd::BaseEvent & evt, size_t position)
{
std::shared_ptr<gd::BaseEvent> event(evt.Clone());
if (position<events.size())
events.insert(events.begin()+position, event);
for (std::size_t insertPos = 0; insertPos <= (end - begin); insertPos++) {
if (position != (size_t)-1 && position + insertPos < events.size())
events.insert(
events.begin() + position + insertPos,
CloneRememberingOriginalEvent(otherEvents.events[begin + insertPos]));
else
events.push_back(event);
return *event;
events.push_back(
CloneRememberingOriginalEvent(otherEvents.events[begin + insertPos]));
}
}
void EventsList::InsertEvent(std::shared_ptr<gd::BaseEvent> event, size_t position)
{
if (position<events.size())
events.insert(events.begin()+position, event);
else
events.push_back(event);
gd::BaseEvent& EventsList::InsertEvent(const gd::BaseEvent& evt,
size_t position) {
std::shared_ptr<gd::BaseEvent> event(evt.Clone());
if (position < events.size())
events.insert(events.begin() + position, event);
else
events.push_back(event);
return *event;
}
gd::BaseEvent & EventsList::InsertNewEvent(gd::Project & project, const gd::String & eventType, size_t position)
{
gd::BaseEventSPtr event = project.CreateEvent(eventType);
if ( event == std::shared_ptr<gd::BaseEvent>())
{
std::cout << "Unknown event of type " << eventType;
event = std::make_shared<EmptyEvent>();
void EventsList::InsertEvent(std::shared_ptr<gd::BaseEvent> event,
size_t position) {
if (position < events.size())
events.insert(events.begin() + position, event);
else
events.push_back(event);
}
gd::BaseEvent& EventsList::InsertNewEvent(gd::Project& project,
const gd::String& eventType,
size_t position) {
gd::BaseEventSPtr event = project.CreateEvent(eventType);
if (event == std::shared_ptr<gd::BaseEvent>()) {
std::cout << "Unknown event of type " << eventType;
event = std::make_shared<EmptyEvent>();
}
InsertEvent(event, position);
return *event;
}
void EventsList::RemoveEvent(size_t index) {
events.erase(events.begin() + index);
}
void EventsList::RemoveEvent(const gd::BaseEvent& event) {
for (size_t i = 0; i < events.size(); ++i) {
if (events[i].get() == &event) {
events.erase(events.begin() + i);
return;
}
InsertEvent(event, position);
return *event;
}
}
void EventsList::RemoveEvent(size_t index)
{
events.erase(events.begin()+index);
void EventsList::SerializeTo(SerializerElement& element) const {
EventsListSerialization::SerializeEventsTo(*this, element);
}
void EventsList::RemoveEvent(const gd::BaseEvent & event)
{
for (size_t i = 0; i < events.size(); ++i)
{
if (events[i].get() == &event)
{
events.erase(events.begin()+i);
return;
}
}
void EventsList::UnserializeFrom(gd::Project& project,
const SerializerElement& element) {
EventsListSerialization::UnserializeEventsFrom(project, *this, element);
}
void EventsList::SerializeTo(SerializerElement & element) const
{
EventsListSerialization::SerializeEventsTo(*this, element);
bool EventsList::Contains(const gd::BaseEvent& eventToSearch,
bool recursive) const {
for (std::size_t i = 0; i < GetEventsCount(); ++i) {
if (&GetEvent(i) == &eventToSearch) return true;
if (recursive && GetEvent(i).CanHaveSubEvents() &&
GetEvent(i).GetSubEvents().Contains(eventToSearch))
return true;
}
return false;
}
void EventsList::UnserializeFrom(gd::Project & project, const SerializerElement & element)
{
EventsListSerialization::UnserializeEventsFrom(project, *this, element);
EventsList::EventsList(const EventsList& other) { Init(other); }
EventsList& EventsList::operator=(const EventsList& other) {
if (this != &other) Init(other);
return *this;
}
bool EventsList::Contains(const gd::BaseEvent & eventToSearch, bool recursive) const
{
for (std::size_t i = 0;i<GetEventsCount();++i)
{
if ( &GetEvent(i) == &eventToSearch) return true;
if ( recursive && GetEvent(i).CanHaveSubEvents() && GetEvent(i).GetSubEvents().Contains(eventToSearch) )
return true;
}
return false;
void EventsList::Init(const gd::EventsList& other) {
events.clear();
for (size_t i = 0; i < other.events.size(); ++i)
events.push_back(CloneRememberingOriginalEvent(other.events[i]));
}
EventsList::EventsList(const EventsList & other)
{
Init(other);
}
EventsList & EventsList::operator=(const EventsList & other)
{
if ( this != &other )
Init(other);
return *this;
}
void EventsList::Init(const gd::EventsList & other)
{
events.clear();
for(size_t i = 0;i<other.events.size();++i)
events.push_back(CloneRememberingOriginalEvent(other.events[i]));
}
}
} // namespace gd

View File

@@ -1,23 +1,28 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#if defined(GD_IDE_ONLY)
#ifndef GDCORE_EVENTSLIST_H
#define GDCORE_EVENTSLIST_H
#include <vector>
#include <memory>
#include <vector>
#include "GDCore/String.h"
namespace gd { class Project; }
namespace gd { class BaseEvent; }
namespace gd { class SerializerElement; }
namespace gd {
class Project;
}
namespace gd {
class BaseEvent;
}
namespace gd {
class SerializerElement;
}
class TiXmlElement;
#undef CreateEvent
namespace gd
{
namespace gd {
/**
* \brief A list of events.
@@ -25,154 +30,174 @@ namespace gd
* \see BaseEvent
* \ingroup Events
*/
class GD_CORE_API EventsList
{
public:
EventsList();
EventsList(const EventsList&);
virtual ~EventsList() {};
EventsList& operator=(const EventsList & rhs);
class GD_CORE_API EventsList {
public:
EventsList();
EventsList(const EventsList&);
virtual ~EventsList(){};
EventsList& operator=(const EventsList& rhs);
/**
* \brief Insert the specified event to the list
* \note The event passed by parameter is copied.
* \param event The event that must be copied and inserted into the list
* \param position Insertion position. If the position is invalid, the object is inserted at the end of the objects list.
* \return A reference to the event in the list
*/
gd::BaseEvent & InsertEvent(const gd::BaseEvent & event, size_t position = (size_t)-1);
/**
* \brief Insert the specified event to the list
* \note The event passed by parameter is copied.
* \param event The event that must be copied and inserted into the list
* \param position Insertion position. If the position is invalid, the object
* is inserted at the end of the objects list. \return A reference to the
* event in the list
*/
gd::BaseEvent& InsertEvent(const gd::BaseEvent& event,
size_t position = (size_t)-1);
/**
* \brief Insert the specified event to the list.
* \note The event passed by parameter is not copied.
* \param event The smart pointer to the event that must be inserted into the list
* \param position Insertion position. If the position is invalid, the object is inserted at the end of the objects list.
*/
void InsertEvent(std::shared_ptr<gd::BaseEvent> event, size_t position = (size_t)-1);
/**
* \brief Insert the specified event to the list.
* \note The event passed by parameter is not copied.
* \param event The smart pointer to the event that must be inserted into the
* list \param position Insertion position. If the position is invalid, the
* object is inserted at the end of the objects list.
*/
void InsertEvent(std::shared_ptr<gd::BaseEvent> event,
size_t position = (size_t)-1);
/**
* \brief Insert a new event to the list.
* \note The event is created using the project current platform.
* \param project The project the events list belongs to.
* \param eventType The type of the event
* \param position Insertion position. If the position is invalid, the object is inserted at the end of the objects list.
*/
gd::BaseEvent & InsertNewEvent(gd::Project & project, const gd::String & eventType, size_t position = (size_t)-1);
/**
* \brief Insert a new event to the list.
* \note The event is created using the project current platform.
* \param project The project the events list belongs to.
* \param eventType The type of the event
* \param position Insertion position. If the position is invalid, the object
* is inserted at the end of the objects list.
*/
gd::BaseEvent& InsertNewEvent(gd::Project& project,
const gd::String& eventType,
size_t position = (size_t)-1);
/**
* \brief Copy events from another list
*/
void InsertEvents(const EventsList & otherEvents, size_t begin, size_t end, size_t position = (size_t)-1);
/**
* \brief Copy events from another list
*/
void InsertEvents(const EventsList& otherEvents,
size_t begin,
size_t end,
size_t position = (size_t)-1);
/**
* \brief Return the number of events.
*/
size_t GetEventsCount() const { return events.size(); };
/**
* \brief Return the number of events.
*/
size_t GetEventsCount() const { return events.size(); };
/**
* \brief Return the smart pointer to the event at position \a index in the events list.
*/
std::shared_ptr<BaseEvent> GetEventSmartPtr(size_t index) { return events[index]; };
/**
* \brief Return the smart pointer to the event at position \a index in the
* events list.
*/
std::shared_ptr<BaseEvent> GetEventSmartPtr(size_t index) {
return events[index];
};
/**
* \brief Return the smart pointer to the event at position \a index in the events list.
*/
std::shared_ptr<const BaseEvent> GetEventSmartPtr(size_t index) const { return events[index]; };
/**
* \brief Return the smart pointer to the event at position \a index in the
* events list.
*/
std::shared_ptr<const BaseEvent> GetEventSmartPtr(size_t index) const {
return events[index];
};
/**
* \brief Return a reference to the event at position \a index in the events list.
*/
gd::BaseEvent & GetEvent(size_t index) { return *events[index]; };
/**
* \brief Return a reference to the event at position \a index in the events
* list.
*/
gd::BaseEvent& GetEvent(size_t index) { return *events[index]; };
/**
* \brief Return a reference to the event at position \a index in the events list.
*/
const gd::BaseEvent & GetEvent(size_t index) const { return *events[index]; };
/**
* \brief Return a reference to the event at position \a index in the events
* list.
*/
const gd::BaseEvent& GetEvent(size_t index) const { return *events[index]; };
/**
* \brief Remove the specified event.
*/
void RemoveEvent(const gd::BaseEvent & event);
/**
* \brief Remove the specified event.
*/
void RemoveEvent(const gd::BaseEvent& event);
/**
* \brief Remove the event at the specified index in the list.
*/
void RemoveEvent(size_t index);
/**
* \brief Remove the event at the specified index in the list.
*/
void RemoveEvent(size_t index);
/**
* \brief Return true if there isn't any event in the list
*/
bool IsEmpty() const { return events.empty(); };
/**
* \brief Return true if there isn't any event in the list
*/
bool IsEmpty() const { return events.empty(); };
/**
* \brief Clear the list of events.
*/
void Clear() { return events.clear(); };
/**
* \brief Clear the list of events.
*/
void Clear() { return events.clear(); };
/** \name Utilities
* Utility methods
*/
///@{
/**
* Return true if the specified event exists in the list.
* \param event The event to searched for
* \param recursive Set it to false to prevent sub events to be inspected.
*/
bool Contains(const gd::BaseEvent & eventToSearch, bool recursive = true) const;
///@}
/** \name Utilities
* Utility methods
*/
///@{
/**
* Return true if the specified event exists in the list.
* \param event The event to searched for
* \param recursive Set it to false to prevent sub events to be inspected.
*/
bool Contains(const gd::BaseEvent& eventToSearch,
bool recursive = true) const;
///@}
/** \name std::vector API compatibility
* These functions ensure that the class can be used just like a std::vector.
*/
///@{
/** \name std::vector API compatibility
* These functions ensure that the class can be used just like a std::vector.
*/
///@{
/**
* \brief Alias for GetEventsCount()
* \see EventsList::GetEventsCount.
*/
size_t size() const { return GetEventsCount(); }
/**
* \brief Alias for GetEventsCount()
* \see EventsList::GetEventsCount.
*/
size_t size() const { return GetEventsCount(); }
/**
* \brief Alias for GetEvent()
* \see EventsList::GetEvent.
*/
gd::BaseEvent & operator[](size_t index) { return GetEvent(index); };
/**
* \brief Alias for GetEvent()
* \see EventsList::GetEvent.
*/
gd::BaseEvent& operator[](size_t index) { return GetEvent(index); };
/**
* \brief Alias for GetEvent()
* \see EventsList::GetEvent.
*/
const gd::BaseEvent & operator[](size_t index) const { return GetEvent(index); };
///@}
/**
* \brief Alias for GetEvent()
* \see EventsList::GetEvent.
*/
const gd::BaseEvent& operator[](size_t index) const {
return GetEvent(index);
};
///@}
/** \name Saving and loading
* Members functions related to saving and loading the events list.
*/
///@{
/**
* \brief Serialize the events to the specified element
* \see EventsListSerialization
*/
void SerializeTo(SerializerElement & element) const;
/** \name Saving and loading
* Members functions related to saving and loading the events list.
*/
///@{
/**
* \brief Serialize the events to the specified element
* \see EventsListSerialization
*/
void SerializeTo(SerializerElement& element) const;
/**
* \brief Load the events from the specified element
* \see EventsListSerialization
*/
void UnserializeFrom(gd::Project & project, const SerializerElement & element);
///@}
/**
* \brief Load the events from the specified element
* \see EventsListSerialization
*/
void UnserializeFrom(gd::Project& project, const SerializerElement& element);
///@}
private:
std::vector< std::shared_ptr<BaseEvent> > events;
private:
std::vector<std::shared_ptr<BaseEvent> > events;
/**
* Initialize from another list of events, copying events. Used by copy-ctor and assign-op.
* Don't forget to update me if members were changed!
*/
void Init(const gd::EventsList & other);
/**
* Initialize from another list of events, copying events. Used by copy-ctor
* and assign-op. Don't forget to update me if members were changed!
*/
void Init(const gd::EventsList& other);
};
}
} // namespace gd
#endif
#endif

View File

@@ -1,60 +1,57 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_EXPRESSION_H
#define GDCORE_EXPRESSION_H
#include "GDCore/String.h"
namespace gd
{
namespace gd {
/**
* \brief Class representing an expression used as a parameter of a gd::Instruction.
* This class is nothing more than a wrapper around a gd::String.
* \brief Class representing an expression used as a parameter of a
* gd::Instruction. This class is nothing more than a wrapper around a
* gd::String.
*
* \see gd::Instruction
*
* \ingroup Events
*/
class GD_CORE_API Expression
{
public:
class GD_CORE_API Expression {
public:
/**
* \brief Construct an empty expression
*/
Expression(){};
/**
* \brief Construct an empty expression
*/
Expression() {};
/**
* \brief Construct an expression from a string
*/
Expression(gd::String plainString_) : plainString(plainString_){};
/**
* \brief Construct an expression from a string
*/
Expression(gd::String plainString_) : plainString(plainString_) {};
/**
* \brief Construct an expression from a const char *
*/
Expression(const char* plainString_) : plainString(plainString_){};
/**
* \brief Construct an expression from a const char *
*/
Expression(const char * plainString_) : plainString(plainString_) {};
/**
* \brief Get the plain string representing the expression
*/
inline const gd::String& GetPlainString() const { return plainString; };
/**
* \brief Get the plain string representing the expression
*/
inline const gd::String & GetPlainString() const { return plainString; };
/**
* \brief Mimics std::string::c_str
*/
inline const char* c_str() const { return plainString.c_str(); };
/**
* \brief Mimics std::string::c_str
*/
inline const char * c_str() const { return plainString.c_str(); };
virtual ~Expression(){};
virtual ~Expression() {};
private:
gd::String plainString; ///<The expression string
private:
gd::String plainString; ///< The expression string
};
}
} // namespace gd
#endif // GDCORE_EXPRESSION_H
#endif // GDCORE_EXPRESSION_H

View File

@@ -1,74 +1,66 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "GDCore/Events/Instruction.h"
#include "GDCore/Events/InstructionsList.h"
#include "GDCore/Events/Expression.h"
#include "GDCore/String.h"
#include <assert.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include "GDCore/Events/Expression.h"
#include "GDCore/Events/InstructionsList.h"
#include "GDCore/String.h"
namespace gd
{
namespace gd {
gd::Expression Instruction::badExpression("");
Instruction::Instruction(gd::String type_) :
renderedHeightNeedUpdate(true),
renderedHeight(0),
selected(false),
type(type_),
inverted(false)
{
//ctor
parameters.reserve(8);
Instruction::Instruction(gd::String type_)
: renderedHeightNeedUpdate(true),
renderedHeight(0),
selected(false),
type(type_),
inverted(false) {
// ctor
parameters.reserve(8);
}
Instruction::Instruction(gd::String type_, const std::vector<gd::Expression> & parameters_, bool inverted_) :
renderedHeightNeedUpdate(true),
renderedHeight(0),
selected(false),
type(type_),
inverted(inverted_),
parameters(parameters_)
{
parameters.reserve(8);
Instruction::Instruction(gd::String type_,
const std::vector<gd::Expression>& parameters_,
bool inverted_)
: renderedHeightNeedUpdate(true),
renderedHeight(0),
selected(false),
type(type_),
inverted(inverted_),
parameters(parameters_) {
parameters.reserve(8);
}
const gd::Expression & Instruction::GetParameter(std::size_t index) const
{
if ( index >= parameters.size() ) return badExpression;
const gd::Expression& Instruction::GetParameter(std::size_t index) const {
if (index >= parameters.size()) return badExpression;
return parameters[index];
return parameters[index];
}
gd::Expression & Instruction::GetParameter(std::size_t index)
{
if ( index >= parameters.size() ) return badExpression;
gd::Expression& Instruction::GetParameter(std::size_t index) {
if (index >= parameters.size()) return badExpression;
return parameters[index];
return parameters[index];
}
void Instruction::SetParametersCount(std::size_t size)
{
while(size < parameters.size())
parameters.erase(parameters.begin()+parameters.size()-1);
while(size > parameters.size())
parameters.push_back(gd::Expression(""));
void Instruction::SetParametersCount(std::size_t size) {
while (size < parameters.size())
parameters.erase(parameters.begin() + parameters.size() - 1);
while (size > parameters.size()) parameters.push_back(gd::Expression(""));
}
void Instruction::SetParameter(std::size_t nb, const gd::Expression & val)
{
if ( nb >= parameters.size() )
{
std::cout << "Trying to write an out of bound parameter.\n\n" << std::endl;
return;
}
parameters[nb] = val;
void Instruction::SetParameter(std::size_t nb, const gd::Expression& val) {
if (nb >= parameters.size()) {
std::cout << "Trying to write an out of bound parameter.\n\n" << std::endl;
return;
}
parameters[nb] = val;
}
}
} // namespace gd

View File

@@ -1,149 +1,161 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef INSTRUCTION_H
#define INSTRUCTION_H
#include "GDCore/String.h"
#include <vector>
#include "GDCore/Events/Expression.h"
#include "GDCore/Events/InstructionsList.h"
#include "GDCore/String.h"
namespace gd
{
namespace gd {
/**
* \brief An instruction is a member of an event: It can be a condition or an action.
* \brief An instruction is a member of an event: It can be a condition or an
* action.
*
* An instruction has a type, which define what it does, and some parameters. It can also be set as inverted ( when the instruction is a condition ) and
* it can have sub instructions.
* This class does nothing particular except storing these data.
* An instruction has a type, which define what it does, and some parameters. It
* can also be set as inverted ( when the instruction is a condition ) and it
* can have sub instructions. This class does nothing particular except storing
* these data.
*
* \see gd::BaseEvent
*
* \ingroup Events
*/
class GD_CORE_API Instruction
{
public:
class GD_CORE_API Instruction {
public:
/**
* \brief Default constructor
* \param type The type of the instruction
*/
Instruction(gd::String type_ = "");
/**
* \brief Default constructor
* \param type The type of the instruction
*/
Instruction(gd::String type_ = "");
/**
* \brief Constructor
* \param type The type of the instruction
* \param parameters A vector containing the parameters of the instruction
* \param inverted true to set the instruction as inverted (used for condition
* instructions).
*/
Instruction(gd::String type_,
const std::vector<gd::Expression>& parameters_,
bool inverted = false);
/**
* \brief Constructor
* \param type The type of the instruction
* \param parameters A vector containing the parameters of the instruction
* \param inverted true to set the instruction as inverted (used for condition instructions).
*/
Instruction(gd::String type_, const std::vector <gd::Expression> & parameters_, bool inverted = false);
virtual ~Instruction(){};
virtual ~Instruction() {};
/**
* \brief Return the type of the instruction.
* \return The type of the instruction
*/
const gd::String& GetType() const { return type; }
/**
* \brief Return the type of the instruction.
* \return The type of the instruction
*/
const gd::String & GetType() const { return type; }
/**
* \brief Change the instruction type
* \param val The new type of the instruction
*/
void SetType(const gd::String& newType) { type = newType; }
/**
* \brief Change the instruction type
* \param val The new type of the instruction
*/
void SetType(const gd::String & newType) { type = newType; }
/**
* \brief Return true if the condition is inverted
* \return true if the condition is inverted
*/
bool IsInverted() const { return inverted; }
/**
* \brief Return true if the condition is inverted
* \return true if the condition is inverted
*/
bool IsInverted() const { return inverted; }
/**
* \brief Set if the instruction is inverted or not.
* \param inverted true if the condition must be set as inverted
*/
void SetInverted(bool inverted_) { inverted = inverted_; }
/**
* \brief Set if the instruction is inverted or not.
* \param inverted true if the condition must be set as inverted
*/
void SetInverted(bool inverted_) { inverted = inverted_; }
/**
* \brief Return the number of parameters of the instruction.
*/
std::size_t GetParametersCount() const { return parameters.size(); }
/**
* \brief Return the number of parameters of the instruction.
*/
std::size_t GetParametersCount() const { return parameters.size(); }
/**
* \brief Change the number of parameter of the instruction.
*
* If the new size if larger than the previous, new blank parameters are
* added.
*/
void SetParametersCount(std::size_t size);
/**
* \brief Change the number of parameter of the instruction.
*
* If the new size if larger than the previous, new blank parameters are added.
*/
void SetParametersCount(std::size_t size);
/**
* \brief Get the value of a parameter.
*
* Return an empty expression if the parameter requested does not exists.
* \return The current value of the parameter.
*/
const gd::Expression& GetParameter(std::size_t index) const;
/**
* \brief Get the value of a parameter.
*
* Return an empty expression if the parameter requested does not exists.
* \return The current value of the parameter.
*/
const gd::Expression & GetParameter(std::size_t index) const;
/**
* \brief Get the value of a parameter.
*
* Return an empty expression if the parameter requested does not exists.
* \return The current value of the parameter.
*/
gd::Expression& GetParameter(std::size_t index);
/**
* \brief Get the value of a parameter.
*
* Return an empty expression if the parameter requested does not exists.
* \return The current value of the parameter.
*/
gd::Expression & GetParameter(std::size_t index);
/** Change the specified parameter
* \param nb The parameter number
* \param val The new value of the parameter
*/
void SetParameter(std::size_t nb, const gd::Expression& val);
/** Change the specified parameter
* \param nb The parameter number
* \param val The new value of the parameter
*/
void SetParameter(std::size_t nb, const gd::Expression & val);
/** \brief Get a reference to the std::vector containing the parameters.
* \return A std::vector containing the parameters
*/
inline const std::vector<gd::Expression>& GetParameters() const {
return parameters;
}
/** \brief Get a reference to the std::vector containing the parameters.
* \return A std::vector containing the parameters
*/
inline const std::vector < gd::Expression > & GetParameters() const { return parameters; }
/** \brief Replace all the parameters by new ones.
* \param val A vector containing the new parameters.
*/
inline void SetParameters(const std::vector<gd::Expression>& val) {
parameters = val;
}
/** \brief Replace all the parameters by new ones.
* \param val A vector containing the new parameters.
*/
inline void SetParameters(const std::vector < gd::Expression > & val) { parameters = val; }
/**
* \brief Return a reference to the vector containing sub instructions
*/
inline const gd::InstructionsList& GetSubInstructions() const {
return subInstructions;
};
/**
* \brief Return a reference to the vector containing sub instructions
*/
inline const gd::InstructionsList & GetSubInstructions() const { return subInstructions; };
/**
* \brief Return a reference to the vector containing sub instructions
*/
inline gd::InstructionsList& GetSubInstructions() { return subInstructions; };
/**
* \brief Return a reference to the vector containing sub instructions
*/
inline gd::InstructionsList & GetSubInstructions() { return subInstructions; };
/** \name Rendering
* Members related to the instruction rendering in an event editor.
*/
///@{
/** \name Rendering
* Members related to the instruction rendering in an event editor.
*/
///@{
mutable bool
renderedHeightNeedUpdate; ///< True if the instruction height may have
///< changed and must be computed again.
mutable unsigned int renderedHeight; ///< Height of the instruction rendered
///< in an event editor.
mutable bool selected; ///< True if selected in an event editor.
mutable bool renderedHeightNeedUpdate; ///< True if the instruction height may have changed and must be computed again.
mutable unsigned int renderedHeight; ///<Height of the instruction rendered in an event editor.
mutable bool selected; ///<True if selected in an event editor.
///@}
///@}
private:
gd::String type; ///< Instruction type
bool inverted; ///< True if the instruction if inverted. Only applicable for
///< instruction used as conditions by events
mutable std::vector<gd::Expression>
parameters; ///< Vector containing the parameters
gd::InstructionsList subInstructions; ///< Sub instructions, if applicable.
private:
gd::String type; ///< Instruction type
bool inverted; ///< True if the instruction if inverted. Only applicable for instruction used as conditions by events
mutable std::vector < gd::Expression > parameters; ///< Vector containing the parameters
gd::InstructionsList subInstructions; ///< Sub instructions, if applicable.
static gd::Expression badExpression;
static gd::Expression badExpression;
};
}
} // namespace gd
#endif // INSTRUCTION_H
#endif // INSTRUCTION_H

View File

@@ -1,42 +1,43 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "InstructionsList.h"
#include "GDCore/Project/Project.h"
#include "GDCore/Events/Instruction.h"
#include "GDCore/Project/Project.h"
#include "Serialization.h"
namespace gd
{
namespace gd {
void InstructionsList::InsertInstructions(const InstructionsList & list, size_t begin, size_t end, size_t position)
{
if (begin >= list.size()) return;
if (end < begin) return;
if (end >= list.size()) end = list.size()-1;
void InstructionsList::InsertInstructions(const InstructionsList& list,
size_t begin,
size_t end,
size_t position) {
if (begin >= list.size()) return;
if (end < begin) return;
if (end >= list.size()) end = list.size() - 1;
for (std::size_t insertPos = 0;insertPos <= (end-begin);insertPos++)
{
const Instruction & instruction = *list.elements[begin+insertPos];
std::shared_ptr<Instruction> copiedInstruction = std::make_shared<Instruction>(instruction);
if (position != (size_t)-1 && position+insertPos < elements.size())
elements.insert(elements.begin()+position+insertPos, copiedInstruction);
else
elements.push_back(copiedInstruction);
}
for (std::size_t insertPos = 0; insertPos <= (end - begin); insertPos++) {
const Instruction& instruction = *list.elements[begin + insertPos];
std::shared_ptr<Instruction> copiedInstruction =
std::make_shared<Instruction>(instruction);
if (position != (size_t)-1 && position + insertPos < elements.size())
elements.insert(elements.begin() + position + insertPos,
copiedInstruction);
else
elements.push_back(copiedInstruction);
}
}
void InstructionsList::SerializeTo(SerializerElement & element) const
{
EventsListSerialization::SerializeInstructionsTo(*this, element);
void InstructionsList::SerializeTo(SerializerElement& element) const {
EventsListSerialization::SerializeInstructionsTo(*this, element);
}
void InstructionsList::UnserializeFrom(gd::Project & project, const SerializerElement & element)
{
EventsListSerialization::UnserializeInstructionsFrom(project, *this, element);
void InstructionsList::UnserializeFrom(gd::Project& project,
const SerializerElement& element) {
EventsListSerialization::UnserializeInstructionsFrom(project, *this, element);
}
}
} // namespace gd

View File

@@ -9,35 +9,43 @@
#include <memory>
#include <vector>
#include "GDCore/Tools/SPtrList.h"
namespace gd { class Instruction; }
namespace gd { class Project; }
namespace gd { class SerializerElement; }
namespace gd
{
class InstructionsList : public SPtrList<gd::Instruction> {
public:
void InsertInstructions(const InstructionsList & list, size_t begin, size_t end, size_t position = (size_t)-1);
/** \name Serialization
*/
///@{
/**
* \brief Serialize the instructions to the specified element
* \see EventsListSerialization
*/
void SerializeTo(gd::SerializerElement & element) const;
/**
* \brief Load the instructions from the specified element
* \see EventsListSerialization
*/
void UnserializeFrom(gd::Project & project, const gd::SerializerElement & element);
///@}
};
namespace gd {
class Instruction;
}
namespace gd {
class Project;
}
namespace gd {
class SerializerElement;
}
namespace gd {
class InstructionsList : public SPtrList<gd::Instruction> {
public:
void InsertInstructions(const InstructionsList& list,
size_t begin,
size_t end,
size_t position = (size_t)-1);
/** \name Serialization
*/
///@{
/**
* \brief Serialize the instructions to the specified element
* \see EventsListSerialization
*/
void SerializeTo(gd::SerializerElement& element) const;
/**
* \brief Load the instructions from the specified element
* \see EventsListSerialization
*/
void UnserializeFrom(gd::Project& project,
const gd::SerializerElement& element);
///@}
};
} // namespace gd
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,144 +1,192 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_EXPRESSIONPARSER_H
#define GDCORE_EXPRESSIONPARSER_H
#include "GDCore/String.h"
#include <vector>
namespace gd { class Expression; }
namespace gd { class ParserCallbacks; }
namespace gd { class Layout; }
namespace gd { class Project; }
namespace gd { class Platform; }
namespace gd { class ParameterMetadata; }
namespace gd { class ExpressionMetadata; }
#include "GDCore/String.h"
namespace gd {
class Expression;
}
namespace gd {
class ParserCallbacks;
}
namespace gd {
class Layout;
}
namespace gd {
class Project;
}
namespace gd {
class Platform;
}
namespace gd {
class ParameterMetadata;
}
namespace gd {
class ExpressionMetadata;
}
namespace gd
{
namespace gd {
/** \brief Parse an expression
*
* Parse an expression, calling callbacks when a token is reached
* \see gd::ParserCallbacks
*/
class GD_CORE_API ExpressionParser
{
public:
ExpressionParser(const gd::String & expressionPlainString_);
virtual ~ExpressionParser() {};
class GD_CORE_API ExpressionParser {
public:
ExpressionParser(const gd::String &expressionPlainString_);
virtual ~ExpressionParser(){};
/**
* \brief Parse the expression, calling each functor when necessary
* \return True if expression was correctly parsed.
*/
bool ParseMathExpression(const gd::Platform & platform, const gd::Project & project, const gd::Layout & layout, gd::ParserCallbacks & callbacks);
/**
* \brief Parse the expression, calling each functor when necessary
* \return True if expression was correctly parsed.
*/
bool ParseMathExpression(const gd::Platform &platform,
const gd::Project &project,
const gd::Layout &layout,
gd::ParserCallbacks &callbacks);
/**
* \brief Parse the expression, calling each functor when necessary
* \return True if expression was correctly parsed.
*/
bool ParseStringExpression(const gd::Platform & platform, const gd::Project & project, const gd::Layout & layout, gd::ParserCallbacks & callbacks);
/**
* \brief Parse the expression, calling each functor when necessary
* \return True if expression was correctly parsed.
*/
bool ParseStringExpression(const gd::Platform &platform,
const gd::Project &project,
const gd::Layout &layout,
gd::ParserCallbacks &callbacks);
/**
* \brief Return the description of the error that was found
*/
const gd::String & GetFirstError() { return firstErrorStr; }
/**
* \brief Return the description of the error that was found
*/
const gd::String &GetFirstError() { return firstErrorStr; }
/**
* \brief Return the position of the error that was found
* \return The position, or gd::String::npos if no error is found
*/
size_t GetFirstErrorPosition() { return firstErrorPos; }
/**
* \brief Return the position of the error that was found
* \return The position, or gd::String::npos if no error is found
*/
size_t GetFirstErrorPosition() { return firstErrorPos; }
private:
gd::String firstErrorStr;
size_t firstErrorPos;
private:
gd::String firstErrorStr;
size_t firstErrorPos;
/**
* Tool function to add a parameter
*/
bool AddParameterToList(const gd::Project & project, const gd::Layout & layout, ParserCallbacks &, std::vector < gd::Expression > & parameters, gd::String parameterStr, std::vector < gd::ParameterMetadata > parametersInfos, const size_t positionInExpression);
/**
* Tool function to add a parameter
*/
bool AddParameterToList(const gd::Project &project,
const gd::Layout &layout,
ParserCallbacks &,
std::vector<gd::Expression> &parameters,
gd::String parameterStr,
std::vector<gd::ParameterMetadata> parametersInfos,
const size_t positionInExpression);
/**
* Tool function to prepare a parameter
*/
bool PrepareParameter(const gd::Platform & platform,const gd::Project & project, const gd::Layout & layout, ParserCallbacks &, gd::Expression & parameter, const gd::ParameterMetadata & parametersInfo, const size_t positionInExpression);
/**
* Tool function to prepare a parameter
*/
bool PrepareParameter(const gd::Platform &platform,
const gd::Project &project,
const gd::Layout &layout,
ParserCallbacks &,
gd::Expression &parameter,
const gd::ParameterMetadata &parametersInfo,
const size_t positionInExpression);
/**
* Return the minimal number of parameters which can be used when calling an expression ( i.e. ParametersCount-OptionalParameters-CodeOnlyParameters )
*/
size_t GetMinimalParametersNumber(const std::vector < gd::ParameterMetadata > & parametersInfos);
/**
* Return the minimal number of parameters which can be used when calling an
* expression ( i.e. ParametersCount-OptionalParameters-CodeOnlyParameters )
*/
size_t GetMinimalParametersNumber(
const std::vector<gd::ParameterMetadata> &parametersInfos);
/**
* Return the maximal number of parameters which can be used when calling an expression ( i.e. ParametersCount-CodeOnlyParameters )
*/
size_t GetMaximalParametersNumber(const std::vector < gd::ParameterMetadata > & parametersInfos);
/**
* Return the maximal number of parameters which can be used when calling an
* expression ( i.e. ParametersCount-CodeOnlyParameters )
*/
size_t GetMaximalParametersNumber(
const std::vector<gd::ParameterMetadata> &parametersInfos);
bool ValidSyntax(const gd::String & str);
bool ValidSyntax(const gd::String &str);
gd::String expressionPlainString;
static gd::String parserSeparators;
gd::String expressionPlainString;
static gd::String parserSeparators;
};
/** \brief Callbacks called by parser during parsing
*
* Parser will call the appropriate functions during parsing, allowing to do special works.
* \see gd::ExpressionParser
* Parser will call the appropriate functions during parsing, allowing to do
* special works. \see gd::ExpressionParser
*/
class GD_CORE_API ParserCallbacks
{
friend class ExpressionParser;
public:
class GD_CORE_API ParserCallbacks {
friend class ExpressionParser;
ParserCallbacks() : returnType("expression") {};
virtual ~ParserCallbacks() {};
public:
ParserCallbacks() : returnType("expression"){};
virtual ~ParserCallbacks(){};
/**
* \brief Get the type of the expression for which callbacks are used:
* "expression" or "string".
*/
const gd::String & GetReturnType() { return returnType; }
/**
* \brief Get the type of the expression for which callbacks are used:
* "expression" or "string".
*/
const gd::String &GetReturnType() { return returnType; }
virtual void OnConstantToken(gd::String text) = 0;
virtual void OnConstantToken(gd::String text) = 0;
virtual void OnStaticFunction(gd::String functionName, const std::vector<gd::Expression> & parameters, const gd::ExpressionMetadata & expressionInfo) = 0;
virtual void OnStaticFunction(
gd::String functionName,
const std::vector<gd::Expression> &parameters,
const gd::ExpressionMetadata &expressionInfo) = 0;
virtual void OnObjectFunction(gd::String functionName, const std::vector<gd::Expression> & parameters, const gd::ExpressionMetadata & expressionInfo) = 0;
virtual void OnObjectFunction(
gd::String functionName,
const std::vector<gd::Expression> &parameters,
const gd::ExpressionMetadata &expressionInfo) = 0;
virtual void OnObjectBehaviorFunction(gd::String functionName, const std::vector<gd::Expression> & parameters, const gd::ExpressionMetadata & expressionInfo) = 0;
virtual void OnObjectBehaviorFunction(
gd::String functionName,
const std::vector<gd::Expression> &parameters,
const gd::ExpressionMetadata &expressionInfo) = 0;
virtual bool OnSubMathExpression(const gd::Platform & platform, const gd::Project & project, const gd::Layout & layout, gd::Expression & expression) = 0;
virtual bool OnSubTextExpression(const gd::Platform & platform, const gd::Project & project, const gd::Layout & layout, gd::Expression & expression) = 0;
virtual bool OnSubMathExpression(const gd::Platform &platform,
const gd::Project &project,
const gd::Layout &layout,
gd::Expression &expression) = 0;
virtual bool OnSubTextExpression(const gd::Platform &platform,
const gd::Project &project,
const gd::Layout &layout,
gd::Expression &expression) = 0;
/**
* \brief Return the description of the error that was found
*/
const gd::String & GetFirstError() { return firstErrorStr; }
/**
* \brief Return the description of the error that was found
*/
const gd::String &GetFirstError() { return firstErrorStr; }
/**
* \brief Return the position of the error that was found
* \return The position, or gd::String::npos if no error is found
*/
size_t GetFirstErrorPosition() { return firstErrorPos; }
/**
* \brief Return the position of the error that was found
* \return The position, or gd::String::npos if no error is found
*/
size_t GetFirstErrorPosition() { return firstErrorPos; }
protected:
gd::String firstErrorStr;
size_t firstErrorPos;
protected:
gd::String firstErrorStr;
size_t firstErrorPos;
private:
/**
* \brief Set the return type of the expression: Done by ExpressionParser according to
* which Parse* method is called.
* \see gd::ExpressionParser
*/
void SetReturnType(gd::String type) { returnType = type; }
private:
/**
* \brief Set the return type of the expression: Done by ExpressionParser
* according to which Parse* method is called. \see gd::ExpressionParser
*/
void SetReturnType(gd::String type) { returnType = type; }
gd::String returnType; //The type of the expression ("expression" (default), "string"...)
gd::String returnType; // The type of the expression ("expression" (default),
// "string"...)
};
}
} // namespace gd
#endif // GDEXPRESSIONPARSER_H
#endif // GDEXPRESSIONPARSER_H

View File

@@ -1,155 +1,141 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "GDCore/String.h"
#include <vector>
#include "GDCore/Events/Parsers/VariableParser.h"
namespace gd { class Layout; }
namespace gd { class Project; }
namespace gd { class Platform; }
#include <vector>
#include "GDCore/String.h"
namespace gd {
class Layout;
}
namespace gd {
class Project;
}
namespace gd {
class Platform;
}
#include "GDCore/Tools/Localization.h"
namespace gd
{
namespace gd {
VariableParser::~VariableParser()
{
VariableParser::~VariableParser() {}
bool VariableParser::Parse(VariableParserCallbacks& callbacks_) {
callbacks = &callbacks_;
rootVariableParsed = false;
firstErrorStr.clear();
firstErrorPos = 0;
currentPositionIt = expression.begin();
currentTokenType = TS_INVALID;
currentToken.clear();
S();
return firstErrorStr == "";
}
bool VariableParser::Parse(VariableParserCallbacks & callbacks_)
{
callbacks = &callbacks_;
rootVariableParsed = false;
firstErrorStr.clear();
firstErrorPos = 0;
currentPositionIt = expression.begin();
currentTokenType = TS_INVALID;
currentToken.clear();
S();
void VariableParser::ReadToken() {
currentTokenType = TS_INVALID;
currentToken.clear();
while (currentPositionIt != expression.end()) {
char32_t currentChar = *currentPositionIt;
if (currentChar == U'[' || currentChar == U']' || currentChar == U'.') {
if (currentTokenType == TS_VARNAME)
return; // We've parsed a variable name.
}
return firstErrorStr == "";
if (currentChar == U'[') {
currentTokenType = TS_OPENING_BRACKET;
currentToken.clear();
++currentPositionIt;
return;
} else if (currentChar == U']') {
currentTokenType = TS_CLOSING_BRACKET;
currentToken.clear();
++currentPositionIt;
return;
} else if (currentChar == U'.') {
currentTokenType = TS_PERIOD;
currentToken.clear();
++currentPositionIt;
return;
}
currentTokenType = TS_VARNAME; // We're parsing a variable name.
currentToken.push_back(currentChar);
++currentPositionIt;
}
// Can be reached if we are at the end of the expression. In this case,
// currentTokenType will be either TS_VARNAME or TS_INVALID.
}
void VariableParser::ReadToken()
{
currentTokenType = TS_INVALID;
currentToken.clear();
while ( currentPositionIt != expression.end() )
{
char32_t currentChar = *currentPositionIt;
if ( currentChar == U'[' ||
currentChar == U']' ||
currentChar == U'.' )
{
if ( currentTokenType == TS_VARNAME )
return; //We've parsed a variable name.
}
void VariableParser::S() {
ReadToken();
if (currentTokenType != TS_VARNAME) {
firstErrorStr = _("Expecting a variable name.");
firstErrorPos = std::distance<gd::String::const_iterator>(
expression.begin(), currentPositionIt);
return;
}
if ( currentChar == U'[' ) {
currentTokenType = TS_OPENING_BRACKET;
currentToken.clear();
++currentPositionIt;
return;
}
else if ( currentChar == U']' ) {
currentTokenType = TS_CLOSING_BRACKET;
currentToken.clear();
++currentPositionIt;
return;
}
else if ( currentChar == U'.' ) {
currentTokenType = TS_PERIOD;
currentToken.clear();
++currentPositionIt;
return;
}
if (!rootVariableParsed) {
rootVariableParsed = true;
if (callbacks) callbacks->OnRootVariable(currentToken);
} else if (callbacks)
callbacks->OnChildVariable(currentToken);
currentTokenType = TS_VARNAME; //We're parsing a variable name.
currentToken.push_back(currentChar);
++currentPositionIt;
}
//Can be reached if we are at the end of the expression. In this case,
//currentTokenType will be either TS_VARNAME or TS_INVALID.
X();
}
void VariableParser::S()
{
ReadToken();
if (currentTokenType != TS_VARNAME)
{
firstErrorStr = _("Expecting a variable name.");
firstErrorPos = std::distance<gd::String::const_iterator>(expression.begin(), currentPositionIt);
return;
}
void VariableParser::X() {
ReadToken();
if (currentTokenType == TS_INVALID)
return; // Ended parsing.
else if (currentTokenType == TS_PERIOD)
S();
else if (currentTokenType == TS_OPENING_BRACKET) {
gd::String strExpr = SkipStringExpression();
if (!rootVariableParsed)
{
rootVariableParsed = true;
if ( callbacks ) callbacks->OnRootVariable(currentToken);
}
else
if ( callbacks ) callbacks->OnChildVariable(currentToken);
X();
ReadToken();
if (currentTokenType != TS_CLOSING_BRACKET) {
firstErrorStr = _("Expecting ]");
firstErrorPos = std::distance<gd::String::const_iterator>(
expression.begin(), currentPositionIt);
return;
}
if (callbacks) callbacks->OnChildSubscript(strExpr);
X();
}
}
void VariableParser::X()
{
ReadToken();
if (currentTokenType == TS_INVALID)
return; //Ended parsing.
else if (currentTokenType == TS_PERIOD)
S();
else if (currentTokenType == TS_OPENING_BRACKET)
{
gd::String strExpr = SkipStringExpression();
gd::String VariableParser::SkipStringExpression() {
gd::String stringExpression;
bool insideStringLiteral = false;
bool lastCharacterWasBackslash = false;
unsigned int nestedBracket = 0;
while (currentPositionIt != expression.end()) {
char32_t currentChar = *currentPositionIt;
if (currentChar == U'\"') {
if (!insideStringLiteral)
insideStringLiteral = true;
else if (!lastCharacterWasBackslash)
insideStringLiteral = false;
} else if (currentChar == U'[' && !insideStringLiteral) {
nestedBracket++;
} else if (currentChar == U']' && !insideStringLiteral) {
if (nestedBracket == 0)
return stringExpression; // Found the end of the string litteral.
nestedBracket--;
}
ReadToken();
if (currentTokenType != TS_CLOSING_BRACKET)
{
firstErrorStr = _("Expecting ]");
firstErrorPos = std::distance<gd::String::const_iterator>(expression.begin(), currentPositionIt);
return;
}
if ( callbacks ) callbacks->OnChildSubscript(strExpr);
X();
}
lastCharacterWasBackslash = currentChar == U'\\';
stringExpression.push_back(currentChar);
++currentPositionIt;
}
// End of the expression reached ( So expression is invalid by the way )
return stringExpression;
}
gd::String VariableParser::SkipStringExpression()
{
gd::String stringExpression;
bool insideStringLiteral = false;
bool lastCharacterWasBackslash = false;
unsigned int nestedBracket = 0;
while ( currentPositionIt != expression.end() )
{
char32_t currentChar = *currentPositionIt;
if ( currentChar == U'\"' ) {
if ( !insideStringLiteral )
insideStringLiteral = true;
else if ( !lastCharacterWasBackslash )
insideStringLiteral = false;
}
else if ( currentChar == U'[' && !insideStringLiteral ) {
nestedBracket++;
}
else if ( currentChar == U']' && !insideStringLiteral ) {
if ( nestedBracket == 0 ) return stringExpression; //Found the end of the string litteral.
nestedBracket--;
}
lastCharacterWasBackslash = currentChar == U'\\';
stringExpression.push_back(currentChar);
++currentPositionIt;
}
//End of the expression reached ( So expression is invalid by the way )
return stringExpression;
}
}
} // namespace gd

View File

@@ -1,137 +1,147 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_VARIABLEPARSER_H
#define GDCORE_VARIABLEPARSER_H
#include "GDCore/String.h"
#include <vector>
namespace gd { class Layout; }
namespace gd { class Project; }
namespace gd { class Platform; }
namespace gd { class VariableParserCallbacks; }
#include "GDCore/String.h"
namespace gd {
class Layout;
}
namespace gd {
class Project;
}
namespace gd {
class Platform;
}
namespace gd {
class VariableParserCallbacks;
}
namespace gd
{
namespace gd {
/** \brief Parse a variable expression.
*
* Parse an variable expression ( like myVariable.child["subchild"+ToString(i)].subsubchild ),
* Parse an variable expression ( like
myVariable.child["subchild"+ToString(i)].subsubchild ),
* calling callbacks when a token is reached.
*
* Usage example:
\code
//...
//VariableCodeGenerationCallbacks is a class inheriting from gd::VariableParserCallbacks
VariableCodeGenerationCallbacks callbacks(output, *this, context, VariableCodeGenerationCallbacks::PROJECT_VARIABLE);
//VariableCodeGenerationCallbacks is a class inheriting from
gd::VariableParserCallbacks VariableCodeGenerationCallbacks callbacks(output,
*this, context, VariableCodeGenerationCallbacks::PROJECT_VARIABLE);
gd::VariableParser parser(parameter);
if ( !parser.Parse(callbacks) )
cout << "Error :" << parser.GetFirstError() << " in: "<< parameter << endl;
\endcode
cout << "Error :" << parser.GetFirstError() << " in: "<< parameter <<
endl; \endcode
*
* Here is the parsed grammar: <br>
* S -> VarName X <br>
* X -> e | . S | [StringExpression] X <br>
*
* where e = nothing ( end of expression ), StringExpression = A valid string expression and
* where e = nothing ( end of expression ), StringExpression = A valid string
expression and
* S is the start.
*
* \see gd::VariableParserCallbacks
*/
class GD_CORE_API VariableParser
{
public:
class GD_CORE_API VariableParser {
public:
/**
* \brief Default constructor
* \param expressionPlainString The string representing the expression to be
* parsed.
*/
VariableParser(const gd::String& expressionPlainString_)
: currentPositionIt(), expression(expressionPlainString_){};
virtual ~VariableParser();
/**
* \brief Default constructor
* \param expressionPlainString The string representing the expression to be parsed.
*/
VariableParser(const gd::String & expressionPlainString_) : currentPositionIt(), expression(expressionPlainString_) {};
virtual ~VariableParser();
/**
* Parse the expression, calling each callback when necessary.
* \param callbacks The callbacks to be called.
* \return true if expression was correctly parsed.
* \see gd::VariableParserCallbacks
*/
bool Parse(VariableParserCallbacks& callbacks);
/**
* Parse the expression, calling each callback when necessary.
* \param callbacks The callbacks to be called.
* \return true if expression was correctly parsed.
* \see gd::VariableParserCallbacks
*/
bool Parse(VariableParserCallbacks & callbacks);
/**
* \brief Return the description of the error that was found
*/
const gd::String& GetFirstError() { return firstErrorStr; }
/**
* \brief Return the description of the error that was found
*/
const gd::String & GetFirstError() { return firstErrorStr; }
/**
* \brief Return the position of the error that was found
* \return The position, or gd::String::npos if no error is found
*/
size_t GetFirstErrorPosition() { return firstErrorPos; }
/**
* \brief Return the position of the error that was found
* \return The position, or gd::String::npos if no error is found
*/
size_t GetFirstErrorPosition() { return firstErrorPos; }
gd::String firstErrorStr;
size_t firstErrorPos;
gd::String firstErrorStr;
size_t firstErrorPos;
private:
void S();
void X();
private:
/**
* \brief Skip the string expression, starting from the current position.
* \return The string expression skipped. currentPosition is now put on the
* closing bracket.
*/
gd::String SkipStringExpression();
void S();
void X();
void ReadToken();
/**
* \brief Skip the string expression, starting from the current position.
* \return The string expression skipped. currentPosition is now put on the closing bracket.
*/
gd::String SkipStringExpression();
enum TokenType {
TS_PERIOD,
TS_OPENING_BRACKET,
TS_CLOSING_BRACKET,
TS_VARNAME,
TS_INVALID
};
void ReadToken();
TokenType currentTokenType;
gd::String currentToken;
gd::String::const_iterator currentPositionIt;
gd::String expression;
enum TokenType {
TS_PERIOD,
TS_OPENING_BRACKET,
TS_CLOSING_BRACKET,
TS_VARNAME,
TS_INVALID
};
TokenType currentTokenType;
gd::String currentToken;
gd::String::const_iterator currentPositionIt;
gd::String expression;
VariableParserCallbacks * callbacks;
bool rootVariableParsed;
VariableParserCallbacks* callbacks;
bool rootVariableParsed;
};
/**
* \brief Callbacks called by VariableParser when parsing a variable expression.
*/
class GD_CORE_API VariableParserCallbacks
{
public:
/**
* \brief Called when the first variable has been parsed. ( varName1 in varName1.child for example. )
* \param variableName The variable name.
*/
virtual void OnRootVariable(gd::String variableName) = 0;
class GD_CORE_API VariableParserCallbacks {
public:
/**
* \brief Called when the first variable has been parsed. ( varName1 in
* varName1.child for example. ) \param variableName The variable name.
*/
virtual void OnRootVariable(gd::String variableName) = 0;
/**
* \brief Called when accessing the child of a structure variable. ( child in varName1.child for example. )
* \param variableName The child variable name.
*/
virtual void OnChildVariable(gd::String variableName) = 0;
/**
* \brief Called when accessing the child of a structure variable. ( child in
* varName1.child for example. ) \param variableName The child variable name.
*/
virtual void OnChildVariable(gd::String variableName) = 0;
/**
* \brief Called when accessing the child of a structure variable using a string expression
* in square brackets. ( "subscript" in varName1["subscript"] for example. )
*
* \param variableName The expression used to access the child variable.
*/
virtual void OnChildSubscript(gd::String stringExpression) = 0;
/**
* \brief Called when accessing the child of a structure variable using a
* string expression in square brackets. ( "subscript" in
* varName1["subscript"] for example. )
*
* \param variableName The expression used to access the child variable.
*/
virtual void OnChildSubscript(gd::String stringExpression) = 0;
};
}
} // namespace gd
#endif // GDEXPRESSIONPARSER_H
#endif // GDEXPRESSIONPARSER_H

View File

@@ -1,288 +1,285 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "GDCore/Project/Project.h"
#include "GDCore/Extensions/Platform.h"
#include "GDCore/Extensions/Metadata/InstructionMetadata.h"
#include "GDCore/Events/InstructionsList.h"
#include "GDCore/Events/EventsList.h"
#include "GDCore/Events/Event.h"
#include "GDCore/Events/Serialization.h"
#include "GDCore/CommonTools.h"
#include "GDCore/Events/Event.h"
#include "GDCore/Events/EventsList.h"
#include "GDCore/Events/Instruction.h"
#include "GDCore/Events/InstructionsList.h"
#include "GDCore/Extensions/Metadata/InstructionMetadata.h"
#include "GDCore/Extensions/Metadata/MetadataProvider.h"
#include "GDCore/Extensions/Platform.h"
#include "GDCore/Project/Project.h"
#include "GDCore/Serialization/Serializer.h"
#include "GDCore/Serialization/SerializerElement.h"
#include "GDCore/Events/Instruction.h"
#include "GDCore/Extensions/Metadata/MetadataProvider.h"
#include "GDCore/Tools/Log.h"
#include "GDCore/CommonTools.h"
using namespace std;
namespace gd
{
namespace gd {
void EventsListSerialization::UpdateInstructionsFromGD31x(gd::Project & project, gd::InstructionsList & list)
{
for (std::size_t i = 0;i<list.size();++i)
{
gd::Instruction & instr = list[i];
void EventsListSerialization::UpdateInstructionsFromGD31x(
gd::Project& project, gd::InstructionsList& list) {
for (std::size_t i = 0; i < list.size(); ++i) {
gd::Instruction& instr = list[i];
if (instr.GetType() == "VarScene" ||
instr.GetType() == "VarSceneTxt" ||
instr.GetType() == "VarGlobal" ||
instr.GetType() == "VarGlobalTxt" ||
instr.GetType() == "ModVarScene" ||
instr.GetType() == "ModVarSceneTxt" ||
instr.GetType() == "ModVarGlobal" ||
instr.GetType() == "ModVarGlobalTxt" )
{
std::vector< gd::Expression > parameters = instr.GetParameters();
if ( parameters.size() >= 1 ) parameters.erase(parameters.begin()+0);
instr.SetParameters(parameters);
}
if (instr.GetType() == "VarSceneDef" ||
instr.GetType() == "VarGlobalDef" ||
instr.GetType() == "VarObjetDef" )
{
instr.SetParameter(1, gd::Expression("\""+instr.GetParameter(1).GetPlainString()+"\""));
}
if (instr.GetType() == "VarScene" || instr.GetType() == "VarSceneTxt" ||
instr.GetType() == "VarGlobal" || instr.GetType() == "VarGlobalTxt" ||
instr.GetType() == "ModVarScene" ||
instr.GetType() == "ModVarSceneTxt" ||
instr.GetType() == "ModVarGlobal" ||
instr.GetType() == "ModVarGlobalTxt") {
std::vector<gd::Expression> parameters = instr.GetParameters();
if (parameters.size() >= 1) parameters.erase(parameters.begin() + 0);
instr.SetParameters(parameters);
}
if (instr.GetType() == "VarSceneDef" || instr.GetType() == "VarGlobalDef" ||
instr.GetType() == "VarObjetDef") {
instr.SetParameter(
1,
gd::Expression("\"" + instr.GetParameter(1).GetPlainString() + "\""));
}
}
}
void EventsListSerialization::UpdateInstructionsFromGD2x(gd::Project & project, gd::InstructionsList & list, bool instructionsAreActions)
{
for (std::size_t i = 0;i<list.size();++i)
{
gd::Instruction & instr = list[i];
void EventsListSerialization::UpdateInstructionsFromGD2x(
gd::Project& project,
gd::InstructionsList& list,
bool instructionsAreActions) {
for (std::size_t i = 0; i < list.size(); ++i) {
gd::Instruction& instr = list[i];
const gd::InstructionMetadata & metadata = instructionsAreActions ?
MetadataProvider::GetActionMetadata(project.GetCurrentPlatform(), instr.GetType()) :
MetadataProvider::GetConditionMetadata(project.GetCurrentPlatform(), instr.GetType());
const gd::InstructionMetadata& metadata =
instructionsAreActions
? MetadataProvider::GetActionMetadata(project.GetCurrentPlatform(),
instr.GetType())
: MetadataProvider::GetConditionMetadata(
project.GetCurrentPlatform(), instr.GetType());
//Specific updates for some instructions
if ( instr.GetType() == "LinkedObjects::LinkObjects" || instr.GetType() == "LinkedObjects::RemoveLinkBetween" )
{
instr.SetParameter(1, instr.GetParameter(3));
instr.SetParameter(2, instr.GetParameter(4));
}
else if (instr.GetType() == "LinkedObjects::RemoveAllLinksOf")
{
instr.SetParameter(1, instr.GetParameter(2));
}
else if (instr.GetType() == "LinkedObjects::PickObjectsLinkedTo")
{
instr.SetParameter(1, instr.GetParameter(5));
instr.SetParameter(2, instr.GetParameter(3));
}
else if (instr.GetType() == "PhysicsBehavior::AddRevoluteJointBetweenObjects")
{
instr.SetParameter(4, instr.GetParameter(5));
instr.SetParameter(5, instr.GetParameter(6));
}
else if (instr.GetType() == "FixCamera" || instr.GetType() == "CentreCamera")
{
std::vector< gd::Expression > parameters = instr.GetParameters();
if ( parameters.size() >= 3 ) parameters.erase(parameters.begin()+2);
instr.SetParameters(parameters);
}
else if (instr.GetType() == "AjoutObjConcern" || instr.GetType() == "AjoutHasard")
{
instr.SetParameter(1, instr.GetParameter(3));
}
else if (instr.GetType() == "SeDirige" || instr.GetType() == "EstTourne" )
{
std::vector< gd::Expression > parameters = instr.GetParameters();
if ( parameters.size() >= 3 ) parameters.erase(parameters.begin()+2);
if ( parameters.size() >= 3 ) parameters.erase(parameters.begin()+2);
instr.SetParameters(parameters);
}
else if (instr.GetType() == "Create")
{
std::vector< gd::Expression > parameters = instr.GetParameters();
if ( parameters.size() >= 2 ) parameters.erase(parameters.begin()+1);
if ( parameters.size() >= 2 ) parameters.erase(parameters.begin()+1);
instr.SetParameters(parameters);
}
else if (instr.GetType() == "CreateByName")
{
std::vector< gd::Expression > parameters = instr.GetParameters();
if ( parameters.size() >= 2 ) parameters.erase(parameters.begin()+1);
instr.SetParameters(parameters);
}
else if (instr.GetType() == "NbObjet")
{
std::vector< gd::Expression > parameters = instr.GetParameters();
if ( parameters.size() >= 2 ) parameters.erase(parameters.begin()+1);
instr.SetParameters(parameters);
}
else if (instr.GetType() == "Distance")
{
std::vector< gd::Expression > parameters = instr.GetParameters();
if ( parameters.size() >= 3 ) parameters.erase(parameters.begin()+2);
if ( parameters.size() >= 3 ) parameters.erase(parameters.begin()+2);
if ( parameters.size() >= 4 && (parameters[3].GetPlainString() == ">=" || parameters[3].GetPlainString() == ">") )
{
instr.SetInverted(true);
}
else
{
instr.SetInverted(false);
}
instr.SetParameters(parameters);
}
//Common updates for some parameters
const std::vector< gd::Expression > & parameters = instr.GetParameters();
for (std::size_t j = 0;j<parameters.size() && j<metadata.parameters.size();++j)
{
if ( metadata.parameters[j].type == "relationalOperator" ||
metadata.parameters[j].type == "operator" )
{
if ( j == parameters.size()-1 )
{
std::cout << "ERROR: No more parameters after a [relational]operator when trying to update an instruction from GD2.x";
}
else
{
//Exchange parameters
gd::String op = parameters[j+1].GetPlainString();
instr.SetParameter(j+1, parameters[j] );
instr.SetParameter(j, gd::Expression(op));
}
}
}
//UpdateInstructionsFromGD2x(project, instr.GetSubInstructions(), instructionsAreActions);
// Specific updates for some instructions
if (instr.GetType() == "LinkedObjects::LinkObjects" ||
instr.GetType() == "LinkedObjects::RemoveLinkBetween") {
instr.SetParameter(1, instr.GetParameter(3));
instr.SetParameter(2, instr.GetParameter(4));
} else if (instr.GetType() == "LinkedObjects::RemoveAllLinksOf") {
instr.SetParameter(1, instr.GetParameter(2));
} else if (instr.GetType() == "LinkedObjects::PickObjectsLinkedTo") {
instr.SetParameter(1, instr.GetParameter(5));
instr.SetParameter(2, instr.GetParameter(3));
} else if (instr.GetType() ==
"PhysicsBehavior::AddRevoluteJointBetweenObjects") {
instr.SetParameter(4, instr.GetParameter(5));
instr.SetParameter(5, instr.GetParameter(6));
} else if (instr.GetType() == "FixCamera" ||
instr.GetType() == "CentreCamera") {
std::vector<gd::Expression> parameters = instr.GetParameters();
if (parameters.size() >= 3) parameters.erase(parameters.begin() + 2);
instr.SetParameters(parameters);
} else if (instr.GetType() == "AjoutObjConcern" ||
instr.GetType() == "AjoutHasard") {
instr.SetParameter(1, instr.GetParameter(3));
} else if (instr.GetType() == "SeDirige" ||
instr.GetType() == "EstTourne") {
std::vector<gd::Expression> parameters = instr.GetParameters();
if (parameters.size() >= 3) parameters.erase(parameters.begin() + 2);
if (parameters.size() >= 3) parameters.erase(parameters.begin() + 2);
instr.SetParameters(parameters);
} else if (instr.GetType() == "Create") {
std::vector<gd::Expression> parameters = instr.GetParameters();
if (parameters.size() >= 2) parameters.erase(parameters.begin() + 1);
if (parameters.size() >= 2) parameters.erase(parameters.begin() + 1);
instr.SetParameters(parameters);
} else if (instr.GetType() == "CreateByName") {
std::vector<gd::Expression> parameters = instr.GetParameters();
if (parameters.size() >= 2) parameters.erase(parameters.begin() + 1);
instr.SetParameters(parameters);
} else if (instr.GetType() == "NbObjet") {
std::vector<gd::Expression> parameters = instr.GetParameters();
if (parameters.size() >= 2) parameters.erase(parameters.begin() + 1);
instr.SetParameters(parameters);
} else if (instr.GetType() == "Distance") {
std::vector<gd::Expression> parameters = instr.GetParameters();
if (parameters.size() >= 3) parameters.erase(parameters.begin() + 2);
if (parameters.size() >= 3) parameters.erase(parameters.begin() + 2);
if (parameters.size() >= 4 && (parameters[3].GetPlainString() == ">=" ||
parameters[3].GetPlainString() == ">")) {
instr.SetInverted(true);
} else {
instr.SetInverted(false);
}
instr.SetParameters(parameters);
}
// Common updates for some parameters
const std::vector<gd::Expression>& parameters = instr.GetParameters();
for (std::size_t j = 0;
j < parameters.size() && j < metadata.parameters.size();
++j) {
if (metadata.parameters[j].type == "relationalOperator" ||
metadata.parameters[j].type == "operator") {
if (j == parameters.size() - 1) {
std::cout << "ERROR: No more parameters after a [relational]operator "
"when trying to update an instruction from GD2.x";
} else {
// Exchange parameters
gd::String op = parameters[j + 1].GetPlainString();
instr.SetParameter(j + 1, parameters[j]);
instr.SetParameter(j, gd::Expression(op));
}
}
}
// UpdateInstructionsFromGD2x(project, instr.GetSubInstructions(),
// instructionsAreActions);
}
}
void EventsListSerialization::UnserializeEventsFrom(gd::Project & project, EventsList & list, const SerializerElement & events)
{
list.Clear();
events.ConsiderAsArrayOf("event", "Event");
for(std::size_t i = 0; i<events.GetChildrenCount(); ++i)
{
SerializerElement & eventElem = events.GetChild(i);
gd::String type = eventElem.GetChild("type", 0, "Type").GetValue().GetString();
gd::BaseEventSPtr event = project.CreateEvent(type);
if ( event != std::shared_ptr<gd::BaseEvent>())
event->UnserializeFrom(project, eventElem);
else
{
std::cout << "WARNING: Unknown event of type " << type << std::endl;
event = std::make_shared<EmptyEvent>();
}
event->SetDisabled(eventElem.GetBoolAttribute("disabled"));
event->SetFolded(eventElem.GetBoolAttribute("folded"));
list.InsertEvent(event, list.GetEventsCount());
void EventsListSerialization::UnserializeEventsFrom(
gd::Project& project, EventsList& list, const SerializerElement& events) {
list.Clear();
events.ConsiderAsArrayOf("event", "Event");
for (std::size_t i = 0; i < events.GetChildrenCount(); ++i) {
SerializerElement& eventElem = events.GetChild(i);
gd::String type =
eventElem.GetChild("type", 0, "Type").GetValue().GetString();
gd::BaseEventSPtr event = project.CreateEvent(type);
if (event != std::shared_ptr<gd::BaseEvent>())
event->UnserializeFrom(project, eventElem);
else {
std::cout << "WARNING: Unknown event of type " << type << std::endl;
event = std::make_shared<EmptyEvent>();
}
event->SetDisabled(eventElem.GetBoolAttribute("disabled"));
event->SetFolded(eventElem.GetBoolAttribute("folded"));
list.InsertEvent(event, list.GetEventsCount());
}
}
void EventsListSerialization::SerializeEventsTo(const EventsList & list, SerializerElement & events)
{
events.ConsiderAsArrayOf("event");
for ( std::size_t j = 0;j < list.size();j++ )
{
const gd::BaseEvent & event = list.GetEvent(j);
SerializerElement & eventElem = events.AddChild("event");
void EventsListSerialization::SerializeEventsTo(const EventsList& list,
SerializerElement& events) {
events.ConsiderAsArrayOf("event");
for (std::size_t j = 0; j < list.size(); j++) {
const gd::BaseEvent& event = list.GetEvent(j);
SerializerElement& eventElem = events.AddChild("event");
eventElem.SetAttribute("disabled", event.IsDisabled());
eventElem.SetAttribute("folded", event.IsFolded());
eventElem.AddChild("type").SetValue(event.GetType());
eventElem.SetAttribute("disabled", event.IsDisabled());
eventElem.SetAttribute("folded", event.IsFolded());
eventElem.AddChild("type").SetValue(event.GetType());
event.SerializeTo(eventElem);
}
event.SerializeTo(eventElem);
}
}
using namespace std;
void gd::EventsListSerialization::UnserializeInstructionsFrom(gd::Project & project, gd::InstructionsList & instructions, const SerializerElement & elem)
{
elem.ConsiderAsArrayOf("instruction");
//Compatibility with GD <= 4.0.95
if (elem.HasChild("condition", "Condition"))
elem.ConsiderAsArrayOf("condition", "Condition");
else if (elem.HasChild("action", "Action"))
elem.ConsiderAsArrayOf("action", "Action");
//end of compatibility code
void gd::EventsListSerialization::UnserializeInstructionsFrom(
gd::Project& project,
gd::InstructionsList& instructions,
const SerializerElement& elem) {
elem.ConsiderAsArrayOf("instruction");
// Compatibility with GD <= 4.0.95
if (elem.HasChild("condition", "Condition"))
elem.ConsiderAsArrayOf("condition", "Condition");
else if (elem.HasChild("action", "Action"))
elem.ConsiderAsArrayOf("action", "Action");
// end of compatibility code
for(std::size_t i = 0; i<elem.GetChildrenCount(); ++i)
{
gd::Instruction instruction;
const SerializerElement & instrElement = elem.GetChild(i);
for (std::size_t i = 0; i < elem.GetChildrenCount(); ++i) {
gd::Instruction instruction;
const SerializerElement& instrElement = elem.GetChild(i);
instruction.SetType(instrElement.GetChild("type", 0, "Type").GetStringAttribute("value")
.FindAndReplace("Automatism", "Behavior")); //Compatibility with GD <= 4
instruction.SetInverted(instrElement.GetChild("type", 0, "Type").GetBoolAttribute("inverted", false, "Contraire"));
instruction.SetType(
instrElement.GetChild("type", 0, "Type")
.GetStringAttribute("value")
.FindAndReplace("Automatism",
"Behavior")); // Compatibility with GD <= 4
instruction.SetInverted(
instrElement.GetChild("type", 0, "Type")
.GetBoolAttribute("inverted", false, "Contraire"));
//Read parameters
vector < gd::Expression > parameters;
// Read parameters
vector<gd::Expression> parameters;
//Compatibility with GD <= 3.3
if (instrElement.HasChild("Parametre")) {
// Compatibility with GD <= 3.3
if (instrElement.HasChild("Parametre")) {
for (std::size_t j = 0; j < instrElement.GetChildrenCount("Parametre");
++j)
parameters.push_back(gd::Expression(
instrElement.GetChild("Parametre", j).GetValue().GetString()));
for (std::size_t j = 0;j<instrElement.GetChildrenCount("Parametre");++j)
parameters.push_back(gd::Expression(instrElement.GetChild("Parametre", j).GetValue().GetString()));
}
//end of compatibility code
else
{
const SerializerElement & parametersElem = instrElement.GetChild("parameters");
parametersElem.ConsiderAsArrayOf("parameter");
for (std::size_t j = 0;j<parametersElem.GetChildrenCount();++j)
parameters.push_back(gd::Expression(parametersElem.GetChild(j).GetValue().GetString()));
}
instruction.SetParameters( parameters );
//Read sub instructions
if ( instrElement.HasChild("subInstructions") )
UnserializeInstructionsFrom(project, instruction.GetSubInstructions(), instrElement.GetChild("subInstructions"));
//Compatibility with GD <= 4.0.95
if ( instrElement.HasChild("subConditions", "SubConditions") )
UnserializeInstructionsFrom(project, instruction.GetSubInstructions(), instrElement.GetChild("subConditions", 0, "SubConditions" ));
if ( instrElement.HasChild("subActions", "SubActions") )
UnserializeInstructionsFrom(project, instruction.GetSubInstructions(), instrElement.GetChild("subActions", 0, "SubActions" ));
//end of compatibility code
instructions.Insert( instruction );
}
// end of compatibility code
else {
const SerializerElement& parametersElem =
instrElement.GetChild("parameters");
parametersElem.ConsiderAsArrayOf("parameter");
for (std::size_t j = 0; j < parametersElem.GetChildrenCount(); ++j)
parameters.push_back(
gd::Expression(parametersElem.GetChild(j).GetValue().GetString()));
}
//Compatibility with GD <= 3.1
if ( project.GetLastSaveGDMajorVersion() < 3 ||
(project.GetLastSaveGDMajorVersion() == 3 && project.GetLastSaveGDMinorVersion() <= 1 ) )
UpdateInstructionsFromGD31x(project, instructions);
instruction.SetParameters(parameters);
if ( project.GetLastSaveGDMajorVersion() < 3 )
UpdateInstructionsFromGD2x(project, instructions, elem.HasChild("action", "Action"));
//end of compatibility code
// Read sub instructions
if (instrElement.HasChild("subInstructions"))
UnserializeInstructionsFrom(project,
instruction.GetSubInstructions(),
instrElement.GetChild("subInstructions"));
// Compatibility with GD <= 4.0.95
if (instrElement.HasChild("subConditions", "SubConditions"))
UnserializeInstructionsFrom(
project,
instruction.GetSubInstructions(),
instrElement.GetChild("subConditions", 0, "SubConditions"));
if (instrElement.HasChild("subActions", "SubActions"))
UnserializeInstructionsFrom(
project,
instruction.GetSubInstructions(),
instrElement.GetChild("subActions", 0, "SubActions"));
// end of compatibility code
instructions.Insert(instruction);
}
// Compatibility with GD <= 3.1
if (project.GetLastSaveGDMajorVersion() < 3 ||
(project.GetLastSaveGDMajorVersion() == 3 &&
project.GetLastSaveGDMinorVersion() <= 1))
UpdateInstructionsFromGD31x(project, instructions);
if (project.GetLastSaveGDMajorVersion() < 3)
UpdateInstructionsFromGD2x(
project, instructions, elem.HasChild("action", "Action"));
// end of compatibility code
}
void gd::EventsListSerialization::SerializeInstructionsTo(const gd::InstructionsList & list, SerializerElement & instructions)
{
instructions.ConsiderAsArrayOf("instruction");
for ( std::size_t k = 0;k < list.size();k++ )
{
SerializerElement & instruction = instructions.AddChild("instruction");
instruction.AddChild("type")
.SetAttribute("value", list[k].GetType())
.SetAttribute("inverted", list[k].IsInverted());
void gd::EventsListSerialization::SerializeInstructionsTo(
const gd::InstructionsList& list, SerializerElement& instructions) {
instructions.ConsiderAsArrayOf("instruction");
for (std::size_t k = 0; k < list.size(); k++) {
SerializerElement& instruction = instructions.AddChild("instruction");
instruction.AddChild("type")
.SetAttribute("value", list[k].GetType())
.SetAttribute("inverted", list[k].IsInverted());
//Parameters
SerializerElement & parameters = instruction.AddChild("parameters");
parameters.ConsiderAsArrayOf("parameter");
for ( std::size_t l = 0;l < list[k].GetParameters().size();l++ )
parameters.AddChild("parameter").SetValue(list[k].GetParameter(l).GetPlainString());
// Parameters
SerializerElement& parameters = instruction.AddChild("parameters");
parameters.ConsiderAsArrayOf("parameter");
for (std::size_t l = 0; l < list[k].GetParameters().size(); l++)
parameters.AddChild("parameter")
.SetValue(list[k].GetParameter(l).GetPlainString());
//Sub instructions
SerializerElement & subInstructions = instruction.AddChild("subInstructions");
SerializeInstructionsTo(list[k].GetSubInstructions(), subInstructions);
}
// Sub instructions
SerializerElement& subInstructions =
instruction.AddChild("subInstructions");
SerializeInstructionsTo(list[k].GetSubInstructions(), subInstructions);
}
}
}
} // namespace gd

View File

@@ -1,66 +1,79 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_EVENTS_SERIALIZATION_H
#define GDCORE_EVENTS_SERIALIZATION_H
#include "GDCore/Serialization/Serializer.h"
#include <vector>
namespace gd { class InstructionsList; }
namespace gd { class Project; }
namespace gd { class EventsList; }
#include "GDCore/Serialization/Serializer.h"
namespace gd {
class InstructionsList;
}
namespace gd {
class Project;
}
namespace gd {
class EventsList;
}
namespace gd
{
namespace gd {
/**
* \brief Contains tools for loading and saving events to SerializerElement.
*/
class GD_CORE_API EventsListSerialization
{
public:
/**
* \brief Load an events list from a SerializerElement
* \param project The project the events belongs to.
* \param list The event list in which the events must be loaded.
* \param events The SerializerElement containing the events
*/
static void UnserializeEventsFrom(gd::Project & project, gd::EventsList & list, const SerializerElement & events);
class GD_CORE_API EventsListSerialization {
public:
/**
* \brief Load an events list from a SerializerElement
* \param project The project the events belongs to.
* \param list The event list in which the events must be loaded.
* \param events The SerializerElement containing the events
*/
static void UnserializeEventsFrom(gd::Project& project,
gd::EventsList& list,
const SerializerElement& events);
/**
* \brief Save an events list to a SerializerElement
* \param list The event list to be saved.
* \param events The SerializerElement in which the events must be serialized.
*/
static void SerializeEventsTo(const gd::EventsList & list, SerializerElement & events);
/**
* \brief Save an events list to a SerializerElement
* \param list The event list to be saved.
* \param events The SerializerElement in which the events must be serialized.
*/
static void SerializeEventsTo(const gd::EventsList& list,
SerializerElement& events);
/**
* \brief Unserialize a list of instructions
*/
static void UnserializeInstructionsFrom(gd::Project & project, gd::InstructionsList & list, const SerializerElement & elem);
/**
* \brief Unserialize a list of instructions
*/
static void UnserializeInstructionsFrom(gd::Project& project,
gd::InstructionsList& list,
const SerializerElement& elem);
/**
* \brief Serialize a list of instructions
*/
static void SerializeInstructionsTo(const gd::InstructionsList & list, SerializerElement & elem);
/**
* \brief Serialize a list of instructions
*/
static void SerializeInstructionsTo(const gd::InstructionsList& list,
SerializerElement& elem);
private:
/**
* \brief Internal method called when opening events created with GD2.x
*
* Some instructions names have been changed as well as parameters since GD 3.
*/
static void UpdateInstructionsFromGD2x(gd::Project & project, gd::InstructionsList & list, bool instructionsAreActions);
private:
/**
* \brief Internal method called when opening events created with GD2.x
*
* Some instructions names have been changed as well as parameters since GD 3.
*/
static void UpdateInstructionsFromGD2x(gd::Project& project,
gd::InstructionsList& list,
bool instructionsAreActions);
/**
* \brief Internal method called when opening events created with GD 3.1.x
*
* Variables related and some storage instructions have been changed.
*/
static void UpdateInstructionsFromGD31x(gd::Project & project, gd::InstructionsList & list);
/**
* \brief Internal method called when opening events created with GD 3.1.x
*
* Variables related and some storage instructions have been changed.
*/
static void UpdateInstructionsFromGD31x(gd::Project& project,
gd::InstructionsList& list);
};
}
} // namespace gd
#endif // GDCORE_EVENTS_SERIALIZATION_H
#endif // GDCORE_EVENTS_SERIALIZATION_H

View File

@@ -1,69 +1,70 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#if defined(GD_IDE_ONLY)
#include "GDCore/CommonTools.h"
#include "EventsCodeNameMangler.h"
#include "GDCore/CommonTools.h"
#include "GDCore/String.h"
EventsCodeNameMangler *EventsCodeNameMangler::_singleton = NULL;
gd::String EventsCodeNameMangler::GetMangledObjectsListName(const gd::String & originalObjectName)
{
gd::String partiallyMangledName = originalObjectName;
static const gd::String allowedCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
gd::String EventsCodeNameMangler::GetMangledObjectsListName(
const gd::String &originalObjectName) {
gd::String partiallyMangledName = originalObjectName;
static const gd::String allowedCharacters =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for (size_t i = 0;i<partiallyMangledName.size();++i) //Replace all unallowed letter by an underscore and the ascii number of the letter
{
if ( allowedCharacters.find_first_of(std::u32string(1, partiallyMangledName[i])) == gd::String::npos)
{
char32_t unallowedChar = partiallyMangledName[i];
partiallyMangledName.replace(i, 1, "_"+gd::String::From(unallowedChar));
}
for (size_t i = 0; i < partiallyMangledName.size();
++i) // Replace all unallowed letter by an underscore and the ascii
// number of the letter
{
if (allowedCharacters.find_first_of(
std::u32string(1, partiallyMangledName[i])) == gd::String::npos) {
char32_t unallowedChar = partiallyMangledName[i];
partiallyMangledName.replace(i, 1, "_" + gd::String::From(unallowedChar));
}
}
return "GD"+partiallyMangledName+"Objects";
return "GD" + partiallyMangledName + "Objects";
}
gd::String EventsCodeNameMangler::GetExternalEventsFunctionMangledName(const gd::String & externalEventsName)
{
gd::String partiallyMangledName = externalEventsName;
static const gd::String allowedCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
gd::String EventsCodeNameMangler::GetExternalEventsFunctionMangledName(
const gd::String &externalEventsName) {
gd::String partiallyMangledName = externalEventsName;
static const gd::String allowedCharacters =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for (size_t i = 0;i<partiallyMangledName.size();++i) //Replace all unallowed letter by an underscore and the ascii number of the letter
{
if ( allowedCharacters.find_first_of(std::u32string(1, partiallyMangledName[i])) == gd::String::npos)
{
char32_t unallowedChar = partiallyMangledName[i];
partiallyMangledName.replace(i, 1, "_"+gd::String::From(unallowedChar));
}
for (size_t i = 0; i < partiallyMangledName.size();
++i) // Replace all unallowed letter by an underscore and the ascii
// number of the letter
{
if (allowedCharacters.find_first_of(
std::u32string(1, partiallyMangledName[i])) == gd::String::npos) {
char32_t unallowedChar = partiallyMangledName[i];
partiallyMangledName.replace(i, 1, "_" + gd::String::From(unallowedChar));
}
}
return "GDExternalEvents"+partiallyMangledName;
return "GDExternalEvents" + partiallyMangledName;
}
gd::String ManObjListName(const gd::String & objectName)
{
return EventsCodeNameMangler::Get()->GetMangledObjectsListName(objectName);
gd::String ManObjListName(const gd::String &objectName) {
return EventsCodeNameMangler::Get()->GetMangledObjectsListName(objectName);
}
EventsCodeNameMangler * EventsCodeNameMangler::Get()
{
if ( NULL == _singleton )
_singleton = new EventsCodeNameMangler;
EventsCodeNameMangler *EventsCodeNameMangler::Get() {
if (NULL == _singleton) _singleton = new EventsCodeNameMangler;
return ( static_cast<EventsCodeNameMangler*>( _singleton ) );
return (static_cast<EventsCodeNameMangler *>(_singleton));
}
void EventsCodeNameMangler::DestroySingleton()
{
if ( NULL != _singleton )
{
delete _singleton;
_singleton = NULL;
}
void EventsCodeNameMangler::DestroySingleton() {
if (NULL != _singleton) {
delete _singleton;
_singleton = NULL;
}
}
#endif

View File

@@ -1,7 +1,7 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#if defined(GD_IDE_ONLY)
#ifndef EVENTSCODENAMEMANGLER_H
@@ -13,36 +13,36 @@
*
* \see ManObjListName
*/
class GD_CORE_API EventsCodeNameMangler
{
public:
class GD_CORE_API EventsCodeNameMangler {
public:
/**
* Get the mangled name from a name : All characters that are not 0-9, a-z,
* A-Z or _ are replaced by "_"+AsciiCodeOfTheCharacter.
*/
gd::String GetMangledObjectsListName(const gd::String &originalObjectName);
/**
* Get the mangled name from a name : All characters that are not 0-9, a-z, A-Z or _ are replaced by "_"+AsciiCodeOfTheCharacter.
*/
gd::String GetMangledObjectsListName(const gd::String & originalObjectName);
/**
* Get the mangled function name to be used to call external events named \a
* externalEventsName.
*/
gd::String GetExternalEventsFunctionMangledName(
const gd::String &externalEventsName);
/**
* Get the mangled function name to be used to call external events named \a externalEventsName.
*/
gd::String GetExternalEventsFunctionMangledName(const gd::String & externalEventsName);
static EventsCodeNameMangler *Get();
static void DestroySingleton();
static EventsCodeNameMangler *Get();
static void DestroySingleton();
private:
EventsCodeNameMangler() {};
virtual ~EventsCodeNameMangler() {};
static EventsCodeNameMangler *_singleton;
private:
EventsCodeNameMangler(){};
virtual ~EventsCodeNameMangler(){};
static EventsCodeNameMangler *_singleton;
};
/**
* Shortcut to EventsCodeNameMangler::Get()->GetMangledObjectsListName(objectName).
* \see EventsCodeNameMangler
* \return Mangled object name
* Shortcut to
* EventsCodeNameMangler::Get()->GetMangledObjectsListName(objectName). \see
* EventsCodeNameMangler \return Mangled object name
*/
gd::String GD_CORE_API ManObjListName(const gd::String & objectName);
gd::String GD_CORE_API ManObjListName(const gd::String &objectName);
#endif // EVENTSCODENAMEMANGLER_H
#endif // EVENTSCODENAMEMANGLER_H
#endif

View File

@@ -1,34 +1,36 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "AllBuiltinExtensions.h"
#include "GDCore/Tools/Localization.h"
using namespace std;
namespace gd
{
namespace gd {
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsAdvancedExtension(gd::PlatformExtension & extension)
{
extension.SetExtensionInformation("BuiltinAdvanced",
_("Advanced control features"),
_("Built-in extension providing advanced control features."),
"Florian Rival",
"Open source (MIT License)");
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsAdvancedExtension(
gd::PlatformExtension& extension) {
extension.SetExtensionInformation(
"BuiltinAdvanced",
_("Advanced control features"),
_("Built-in extension providing advanced control features."),
"Florian Rival",
"Open source (MIT License)");
#if defined(GD_IDE_ONLY)
extension.AddCondition("Toujours",
_("Always"),
_("This condition always returns true (or always false, if the condition is inverted)."),
_("Always"),
_("Other"),
"res/conditions/toujours24.png",
"res/conditions/toujours.png")
.AddCodeOnlyParameter("conditionInverted", "")
.MarkAsAdvanced();
#endif
#if defined(GD_IDE_ONLY)
extension
.AddCondition("Toujours",
_("Always"),
_("This condition always returns true (or always false, if "
"the condition is inverted)."),
_("Always"),
_("Other"),
"res/conditions/toujours24.png",
"res/conditions/toujours.png")
.AddCodeOnlyParameter("conditionInverted", "")
.MarkAsAdvanced();
#endif
}
}
} // namespace gd

View File

@@ -1,15 +1,14 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_COMMONINSTRUCTIONSEXTENSION_H
#define GDCORE_COMMONINSTRUCTIONSEXTENSION_H
#include "GDCore/Extensions/PlatformExtension.h"
namespace gd
{
namespace gd {
/**
* \brief Tool class containing static methods to setup an extension
@@ -20,30 +19,34 @@ namespace gd
*
* \ingroup BuiltinExtensions
*/
class GD_CORE_API BuiltinExtensionsImplementer
{
public:
static void ImplementsAdvancedExtension(gd::PlatformExtension & extension);
static void ImplementsAudioExtension(gd::PlatformExtension & extension);
static void ImplementsBaseObjectExtension(gd::PlatformExtension & extension);
static void ImplementsCameraExtension(gd::PlatformExtension & extension);
static void ImplementsCommonConversionsExtension(gd::PlatformExtension & extension);
static void ImplementsCommonInstructionsExtension(gd::PlatformExtension & extension);
static void ImplementsExternalLayoutsExtension(gd::PlatformExtension & extension);
static void ImplementsFileExtension(gd::PlatformExtension & extension);
static void ImplementsJoystickExtension(gd::PlatformExtension & extension);
static void ImplementsKeyboardExtension(gd::PlatformExtension & extension);
static void ImplementsMathematicalToolsExtension(gd::PlatformExtension & extension);
static void ImplementsMouseExtension(gd::PlatformExtension & extension);
static void ImplementsNetworkExtension(gd::PlatformExtension & extension);
static void ImplementsSceneExtension(gd::PlatformExtension & extension);
static void ImplementsSpriteExtension(gd::PlatformExtension & extension);
static void ImplementsStringInstructionsExtension(gd::PlatformExtension & extension);
static void ImplementsTimeExtension(gd::PlatformExtension & extension);
static void ImplementsVariablesExtension(gd::PlatformExtension & extension);
static void ImplementsWindowExtension(gd::PlatformExtension & extension);
class GD_CORE_API BuiltinExtensionsImplementer {
public:
static void ImplementsAdvancedExtension(gd::PlatformExtension& extension);
static void ImplementsAudioExtension(gd::PlatformExtension& extension);
static void ImplementsBaseObjectExtension(gd::PlatformExtension& extension);
static void ImplementsCameraExtension(gd::PlatformExtension& extension);
static void ImplementsCommonConversionsExtension(
gd::PlatformExtension& extension);
static void ImplementsCommonInstructionsExtension(
gd::PlatformExtension& extension);
static void ImplementsExternalLayoutsExtension(
gd::PlatformExtension& extension);
static void ImplementsFileExtension(gd::PlatformExtension& extension);
static void ImplementsJoystickExtension(gd::PlatformExtension& extension);
static void ImplementsKeyboardExtension(gd::PlatformExtension& extension);
static void ImplementsMathematicalToolsExtension(
gd::PlatformExtension& extension);
static void ImplementsMouseExtension(gd::PlatformExtension& extension);
static void ImplementsNetworkExtension(gd::PlatformExtension& extension);
static void ImplementsSceneExtension(gd::PlatformExtension& extension);
static void ImplementsSpriteExtension(gd::PlatformExtension& extension);
static void ImplementsStringInstructionsExtension(
gd::PlatformExtension& extension);
static void ImplementsTimeExtension(gd::PlatformExtension& extension);
static void ImplementsVariablesExtension(gd::PlatformExtension& extension);
static void ImplementsWindowExtension(gd::PlatformExtension& extension);
};
}
} // namespace gd
#endif // GDCORE_COMMONINSTRUCTIONSEXTENSION_H
#endif // GDCORE_COMMONINSTRUCTIONSEXTENSION_H

View File

@@ -1,435 +1,545 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "AllBuiltinExtensions.h"
#include "GDCore/Tools/Localization.h"
using namespace std;
namespace gd
{
namespace gd {
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsAudioExtension(gd::PlatformExtension & extension)
{
extension.SetExtensionInformation("BuiltinAudio",
_("Audio"),
_("Builtin audio extension"),
"Florian Rival",
"Open source (MIT License)");
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsAudioExtension(
gd::PlatformExtension& extension) {
extension.SetExtensionInformation("BuiltinAudio",
_("Audio"),
_("Builtin audio extension"),
"Florian Rival",
"Open source (MIT License)");
#if defined(GD_IDE_ONLY)
extension.AddAction("PlaySoundCanal",
_("Play a sound on a channel"),
_("Play a sound (small audio file) on a specific channel,\nso you'll be able to manipulate it."),
_("Play the sound _PARAM1_ on the channel _PARAM2_, vol.: _PARAM4_, loop: _PARAM3_"),
_("Audio/Sounds on channels"),
"res/actions/son24.png",
"res/actions/son.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("soundfile", _("Audio file (or audio resource name)"))
.AddParameter("expression", _("Channel identifier"))
.AddParameter("yesorno", _("Repeat the sound"), "",true).SetDefaultValue("no")
.AddParameter("expression", _("Volume (from 0 to 100, 100 by default)"), "",true).SetDefaultValue("100")
.AddParameter("expression", _("Pitch (speed) (1 by default)"), "",true).SetDefaultValue("1")
.MarkAsAdvanced();
#if defined(GD_IDE_ONLY)
extension
.AddAction("PlaySoundCanal",
_("Play a sound on a channel"),
_("Play a sound (small audio file) on a specific channel,\nso "
"you'll be able to manipulate it."),
_("Play the sound _PARAM1_ on the channel _PARAM2_, vol.: "
"_PARAM4_, loop: _PARAM3_"),
_("Audio/Sounds on channels"),
"res/actions/son24.png",
"res/actions/son.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("soundfile", _("Audio file (or audio resource name)"))
.AddParameter("expression", _("Channel identifier"))
.AddParameter("yesorno", _("Repeat the sound"), "", true)
.SetDefaultValue("no")
.AddParameter(
"expression", _("Volume (from 0 to 100, 100 by default)"), "", true)
.SetDefaultValue("100")
.AddParameter("expression", _("Pitch (speed) (1 by default)"), "", true)
.SetDefaultValue("1")
.MarkAsAdvanced();
extension.AddAction("StopSoundCanal",
_("Stop the sound of a channel"),
_("Stop the sound on the specified channel."),
_("Stop the sound of channel _PARAM1_"),
_("Audio/Sounds on channels"),
"res/actions/son24.png",
"res/actions/son.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.MarkAsAdvanced();
extension
.AddAction("StopSoundCanal",
_("Stop the sound of a channel"),
_("Stop the sound on the specified channel."),
_("Stop the sound of channel _PARAM1_"),
_("Audio/Sounds on channels"),
"res/actions/son24.png",
"res/actions/son.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.MarkAsAdvanced();
extension.AddAction("PauseSoundCanal",
_("Pause the sound of a channel"),
_("Pause the sound played on the specified channel."),
_("Pause the sound of channel _PARAM1_"),
_("Audio/Sounds on channels"),
"res/actions/son24.png",
"res/actions/son.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.MarkAsAdvanced();
extension
.AddAction("PauseSoundCanal",
_("Pause the sound of a channel"),
_("Pause the sound played on the specified channel."),
_("Pause the sound of channel _PARAM1_"),
_("Audio/Sounds on channels"),
"res/actions/son24.png",
"res/actions/son.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.MarkAsAdvanced();
extension.AddAction("RePlaySoundCanal",
_("Play the sound of a channel"),
_("Play the sound of the channel."),
_("Play the sound of channel _PARAM1_"),
_("Audio/Sounds on channels"),
"res/actions/son24.png",
"res/actions/son.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.MarkAsAdvanced();
extension
.AddAction("RePlaySoundCanal",
_("Play the sound of a channel"),
_("Play the sound of the channel."),
_("Play the sound of channel _PARAM1_"),
_("Audio/Sounds on channels"),
"res/actions/son24.png",
"res/actions/son.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.MarkAsAdvanced();
extension.AddAction("PlayMusicCanal",
_("Play a music file on a channel"),
_("Play a music file on a specific channel,\nso you'll be able to interact with it later."),
_("Play the music _PARAM1_ on channel _PARAM2_, vol.: _PARAM4_, loop: _PARAM3_"),
_("Audio/Music on channels"),
"res/actions/music24.png",
"res/actions/music.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("musicfile", _("Audio file (or audio resource name)"))
.AddParameter("expression", _("Channel identifier"))
.AddParameter("yesorno", _("Repeat the sound"), "",true).SetDefaultValue("no")
.AddParameter("expression", _("Volume (from 0 to 100, 100 by default)"), "",true).SetDefaultValue("100")
.AddParameter("expression", _("Pitch (speed) (1 by default)"), "",true).SetDefaultValue("1")
.MarkAsAdvanced();
extension
.AddAction("PlayMusicCanal",
_("Play a music file on a channel"),
_("Play a music file on a specific channel,\nso you'll be "
"able to interact with it later."),
_("Play the music _PARAM1_ on channel _PARAM2_, vol.: "
"_PARAM4_, loop: _PARAM3_"),
_("Audio/Music on channels"),
"res/actions/music24.png",
"res/actions/music.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("musicfile", _("Audio file (or audio resource name)"))
.AddParameter("expression", _("Channel identifier"))
.AddParameter("yesorno", _("Repeat the sound"), "", true)
.SetDefaultValue("no")
.AddParameter(
"expression", _("Volume (from 0 to 100, 100 by default)"), "", true)
.SetDefaultValue("100")
.AddParameter("expression", _("Pitch (speed) (1 by default)"), "", true)
.SetDefaultValue("1")
.MarkAsAdvanced();
extension.AddAction("StopMusicCanal",
_("Stop the music on a channel"),
_("Stop the music on the specified channel"),
_("Stop the music of channel _PARAM1_"),
_("Audio/Music on channels"),
"res/actions/music24.png",
"res/actions/music.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.MarkAsAdvanced();
extension
.AddAction("StopMusicCanal",
_("Stop the music on a channel"),
_("Stop the music on the specified channel"),
_("Stop the music of channel _PARAM1_"),
_("Audio/Music on channels"),
"res/actions/music24.png",
"res/actions/music.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.MarkAsAdvanced();
extension.AddAction("PauseMusicCanal",
_("Pause the music of a channel"),
_("Pause the music on the specified channel."),
_("Pause the music of channel _PARAM1_"),
_("Audio/Music on channels"),
"res/actions/music24.png",
"res/actions/music.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.MarkAsAdvanced();
extension
.AddAction("PauseMusicCanal",
_("Pause the music of a channel"),
_("Pause the music on the specified channel."),
_("Pause the music of channel _PARAM1_"),
_("Audio/Music on channels"),
"res/actions/music24.png",
"res/actions/music.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.MarkAsAdvanced();
extension.AddAction("RePlayMusicCanal",
_("Play the music of a channel"),
_("Play the music of the channel."),
_("Play the music of channel _PARAM1_"),
_("Audio/Music on channels"),
"res/actions/music24.png",
"res/actions/music.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.MarkAsAdvanced();
extension
.AddAction("RePlayMusicCanal",
_("Play the music of a channel"),
_("Play the music of the channel."),
_("Play the music of channel _PARAM1_"),
_("Audio/Music on channels"),
"res/actions/music24.png",
"res/actions/music.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.MarkAsAdvanced();
extension.AddAction("ModVolumeSoundCanal",
_("Volume of the sound on a channel"),
_("This action modifies the volume of the sound on the specified channel. The volume is between 0 and 100."),
_("Do _PARAM2__PARAM3_ to the volume of the sound on channel _PARAM1_"),
_("Audio/Sounds on channels"),
"res/actions/sonVolume24.png",
"res/actions/sonVolume.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddAction("ModVolumeSoundCanal",
_("Volume of the sound on a channel"),
_("This action modifies the volume of the sound on the "
"specified channel. The volume is between 0 and 100."),
_("Do _PARAM2__PARAM3_ to the volume of the sound on channel "
"_PARAM1_"),
_("Audio/Sounds on channels"),
"res/actions/sonVolume24.png",
"res/actions/sonVolume.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddAction("ModVolumeMusicCanal",
_("Volume of the music on a channel"),
_("This action modifies the volume of the music on the specified channel. The volume is between 0 and 100."),
_("Do _PARAM2__PARAM3_ to the volume of the music on channel _PARAM1_"),
_("Audio/Music on channels"),
"res/actions/musicVolume24.png",
"res/actions/musicVolume.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddAction("ModVolumeMusicCanal",
_("Volume of the music on a channel"),
_("This action modifies the volume of the music on the "
"specified channel. The volume is between 0 and 100."),
_("Do _PARAM2__PARAM3_ to the volume of the music on channel "
"_PARAM1_"),
_("Audio/Music on channels"),
"res/actions/musicVolume24.png",
"res/actions/musicVolume.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddAction("ModGlobalVolume",
_("Game global volume"),
_("This action modifies the global volume of the game. The volume is between 0 and 100."),
_("Do _PARAM1__PARAM2_ to global sound level"),
_("Audio"),
"res/actions/volume24.png",
"res/actions/volume.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsSimple()
.SetManipulatedType("number");
extension
.AddAction("ModGlobalVolume",
_("Game global volume"),
_("This action modifies the global volume of the game. The "
"volume is between 0 and 100."),
_("Do _PARAM1__PARAM2_ to global sound level"),
_("Audio"),
"res/actions/volume24.png",
"res/actions/volume.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsSimple()
.SetManipulatedType("number");
extension.AddAction("ModPitchSoundChannel",
_("Pitch of the sound of a channel"),
_("This action modifies the pitch (speed) of the sound on a channel.\n1 is the default pitch."),
_("Do _PARAM2__PARAM3_ to the pitch of the sound on channel _PARAM1_"),
_("Audio/Sounds on channels"),
"res/actions/son24.png",
"res/actions/son.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddAction("ModPitchSoundChannel",
_("Pitch of the sound of a channel"),
_("This action modifies the pitch (speed) of the sound on a "
"channel.\n1 is the default pitch."),
_("Do _PARAM2__PARAM3_ to the pitch of the sound on channel "
"_PARAM1_"),
_("Audio/Sounds on channels"),
"res/actions/son24.png",
"res/actions/son.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddAction("ModPitchMusicChannel",
_("Pitch of the music on a channel"),
_("This action modifies the pitch of the music on the specified channel. 1 is the default pitch"),
_("Do _PARAM2__PARAM3_ to the pitch of the music on channel _PARAM1_"),
_("Audio/Music on channels"),
"res/actions/music24.png",
"res/actions/music.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddAction("ModPitchMusicChannel",
_("Pitch of the music on a channel"),
_("This action modifies the pitch of the music on the "
"specified channel. 1 is the default pitch"),
_("Do _PARAM2__PARAM3_ to the pitch of the music on channel "
"_PARAM1_"),
_("Audio/Music on channels"),
"res/actions/music24.png",
"res/actions/music.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddAction("ModPlayingOffsetSoundChannel",
_("Playing offset of the sound on a channel"),
_("This action modifies the playing offset of the sound on a channel"),
_("Do _PARAM2__PARAM3_ to the playing offset of the sound on channel _PARAM1_"),
_("Audio/Sounds on channels"),
"res/actions/son24.png",
"res/actions/son.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddAction("ModPlayingOffsetSoundChannel",
_("Playing offset of the sound on a channel"),
_("This action modifies the playing offset of the sound on a "
"channel"),
_("Do _PARAM2__PARAM3_ to the playing offset of the sound on "
"channel _PARAM1_"),
_("Audio/Sounds on channels"),
"res/actions/son24.png",
"res/actions/son.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddAction("ModPlayingOffsetMusicChannel",
_("Playing offset of the music on a channel"),
_("This action modifies the playing offset of the music on the specified channel"),
_("Do _PARAM2__PARAM3_ to the playing offset of the music on channel _PARAM1_"),
_("Audio/Music on channels"),
"res/actions/music24.png",
"res/actions/music.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddAction("ModPlayingOffsetMusicChannel",
_("Playing offset of the music on a channel"),
_("This action modifies the playing offset of the music on "
"the specified channel"),
_("Do _PARAM2__PARAM3_ to the playing offset of the music on "
"channel _PARAM1_"),
_("Audio/Music on channels"),
"res/actions/music24.png",
"res/actions/music.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddAction("PlaySound",
_("Play a sound"),
_("Play a sound."),
_("Play the sound _PARAM1_, vol.: _PARAM3_, loop: _PARAM2_)"),
_("Audio"),
"res/actions/son24.png",
"res/actions/son.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("soundfile", _("Audio file (or audio resource name)"))
.AddParameter("yesorno", _("Repeat the sound"), "",true).SetDefaultValue("no")
.AddParameter("expression", _("Volume (from 0 to 100, 100 by default)"), "",true).SetDefaultValue("100")
.AddParameter("expression", _("Pitch (speed) (1 by default)"), "",true).SetDefaultValue("1")
.MarkAsSimple();
extension
.AddAction("PlaySound",
_("Play a sound"),
_("Play a sound."),
_("Play the sound _PARAM1_, vol.: _PARAM3_, loop: _PARAM2_)"),
_("Audio"),
"res/actions/son24.png",
"res/actions/son.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("soundfile", _("Audio file (or audio resource name)"))
.AddParameter("yesorno", _("Repeat the sound"), "", true)
.SetDefaultValue("no")
.AddParameter(
"expression", _("Volume (from 0 to 100, 100 by default)"), "", true)
.SetDefaultValue("100")
.AddParameter("expression", _("Pitch (speed) (1 by default)"), "", true)
.SetDefaultValue("1")
.MarkAsSimple();
extension.AddAction("PlayMusic",
_("Play a music file"),
_("Play a music file."),
_("Play the music _PARAM1_, vol.: _PARAM3_, loop: _PARAM2_)"),
_("Audio"),
"res/actions/music24.png",
"res/actions/music.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("musicfile", _("Audio file (or audio resource name)"))
.AddParameter("yesorno", _("Repeat the sound"), "",true).SetDefaultValue("no")
.AddParameter("expression", _("Volume (from 0 to 100, 100 by default)"), "",true).SetDefaultValue("100")
.AddParameter("expression", _("Pitch (speed) (1 by default)"), "",true).SetDefaultValue("1")
.MarkAsSimple();
extension
.AddAction("PlayMusic",
_("Play a music file"),
_("Play a music file."),
_("Play the music _PARAM1_, vol.: _PARAM3_, loop: _PARAM2_)"),
_("Audio"),
"res/actions/music24.png",
"res/actions/music.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("musicfile", _("Audio file (or audio resource name)"))
.AddParameter("yesorno", _("Repeat the sound"), "", true)
.SetDefaultValue("no")
.AddParameter(
"expression", _("Volume (from 0 to 100, 100 by default)"), "", true)
.SetDefaultValue("100")
.AddParameter("expression", _("Pitch (speed) (1 by default)"), "", true)
.SetDefaultValue("1")
.MarkAsSimple();
extension.AddCondition("MusicPlaying",
_("A music file is being played"),
_("Test if the music on a channel is being played"),
_("Music on channel _PARAM1_ is being played"),
_("Audio/Music on channels"),
"res/conditions/musicplaying24.png",
"res/conditions/musicplaying.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"))
.MarkAsAdvanced();
extension
.AddCondition("MusicPlaying",
_("A music file is being played"),
_("Test if the music on a channel is being played"),
_("Music on channel _PARAM1_ is being played"),
_("Audio/Music on channels"),
"res/conditions/musicplaying24.png",
"res/conditions/musicplaying.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"))
.MarkAsAdvanced();
extension.AddCondition("MusicPaused",
_("A music file is paused"),
_("Test if the music on the specified channel is paused."),
_("Music on channel _PARAM1_ is paused"),
_("Audio/Music on channels"),
"res/conditions/musicpaused24.png",
"res/conditions/musicpaused.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"))
.MarkAsAdvanced();
extension
.AddCondition("MusicPaused",
_("A music file is paused"),
_("Test if the music on the specified channel is paused."),
_("Music on channel _PARAM1_ is paused"),
_("Audio/Music on channels"),
"res/conditions/musicpaused24.png",
"res/conditions/musicpaused.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"))
.MarkAsAdvanced();
extension.AddCondition("MusicStopped",
_("A music file is stopped"),
_("Test if the music on the specified channel is stopped."),
_("Music on channel _PARAM1_ is stopped"),
_("Audio/Music on channels"),
"res/conditions/musicstopped24.png",
"res/conditions/musicstopped.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"))
.MarkAsAdvanced();
extension
.AddCondition("MusicStopped",
_("A music file is stopped"),
_("Test if the music on the specified channel is stopped."),
_("Music on channel _PARAM1_ is stopped"),
_("Audio/Music on channels"),
"res/conditions/musicstopped24.png",
"res/conditions/musicstopped.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"))
.MarkAsAdvanced();
extension.AddCondition("SoundPlaying",
_("A sound is being played"),
_("Test if the sound on a channel is being played."),
_("Sound on channel _PARAM1_ is being played"),
_("Audio/Sounds on channels"),
"res/conditions/sonplaying24.png",
"res/conditions/sonplaying.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"))
.MarkAsAdvanced();
extension
.AddCondition("SoundPlaying",
_("A sound is being played"),
_("Test if the sound on a channel is being played."),
_("Sound on channel _PARAM1_ is being played"),
_("Audio/Sounds on channels"),
"res/conditions/sonplaying24.png",
"res/conditions/sonplaying.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"))
.MarkAsAdvanced();
extension.AddCondition("SoundPaused",
_("A sound is paused"),
_("Test if the sound on the specified channel is paused."),
_("Sound on channel _PARAM1_ is paused"),
_("Audio/Sounds on channels"),
"res/conditions/sonpaused24.png",
"res/conditions/sonpaused.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"))
.MarkAsAdvanced();
extension
.AddCondition("SoundPaused",
_("A sound is paused"),
_("Test if the sound on the specified channel is paused."),
_("Sound on channel _PARAM1_ is paused"),
_("Audio/Sounds on channels"),
"res/conditions/sonpaused24.png",
"res/conditions/sonpaused.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"))
.MarkAsAdvanced();
extension.AddCondition("SoundStopped",
_("A sound is stopped"),
_("Test if the sound on the specified channel is stopped."),
_("Sound on channel _PARAM1_ is stopped"),
_("Audio/Sounds on channels"),
"res/conditions/sonstopped24.png",
"res/conditions/sonstopped.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"))
.MarkAsAdvanced();
extension
.AddCondition("SoundStopped",
_("A sound is stopped"),
_("Test if the sound on the specified channel is stopped."),
_("Sound on channel _PARAM1_ is stopped"),
_("Audio/Sounds on channels"),
"res/conditions/sonstopped24.png",
"res/conditions/sonstopped.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"))
.MarkAsAdvanced();
extension.AddCondition("SoundCanalVolume",
_("Volume of the sound on a channel"),
_("Test the volume of the sound on the specified channel. The volume is between 0 and 100."),
_("The volume of the sound on channel _PARAM1_ is _PARAM2__PARAM3_"),
_("Audio/Sounds on channels"),
"res/conditions/sonVolume24.png",
"res/conditions/sonVolume.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Volume to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddCondition(
"SoundCanalVolume",
_("Volume of the sound on a channel"),
_("Test the volume of the sound on the specified channel. The volume "
"is between 0 and 100."),
_("The volume of the sound on channel _PARAM1_ is _PARAM2__PARAM3_"),
_("Audio/Sounds on channels"),
"res/conditions/sonVolume24.png",
"res/conditions/sonVolume.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Volume to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddCondition("MusicCanalVolume",
_("Volume of the music on a channel"),
_("Test the volume of the music on a specified channel. The volume is between 0 and 100."),
_("The volume of the music on channel _PARAM1_ is _PARAM2__PARAM3_"),
_("Audio/Music on channels"),
"res/conditions/musicVolume24.png",
"res/conditions/musicVolume.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Volume to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddCondition(
"MusicCanalVolume",
_("Volume of the music on a channel"),
_("Test the volume of the music on a specified channel. The volume "
"is between 0 and 100."),
_("The volume of the music on channel _PARAM1_ is _PARAM2__PARAM3_"),
_("Audio/Music on channels"),
"res/conditions/musicVolume24.png",
"res/conditions/musicVolume.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Volume to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddCondition("GlobalVolume",
_("Global volume"),
_("Test the global sound level. The volume is between 0 and 100."),
_("The global game volume is _PARAM1__PARAM2_"),
_("Audio"),
"res/conditions/volume24.png",
"res/conditions/volume.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Volume to test"))
.SetManipulatedType("number");
extension
.AddCondition(
"GlobalVolume",
_("Global volume"),
_("Test the global sound level. The volume is between 0 and 100."),
_("The global game volume is _PARAM1__PARAM2_"),
_("Audio"),
"res/conditions/volume24.png",
"res/conditions/volume.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Volume to test"))
.SetManipulatedType("number");
extension.AddCondition("SoundChannelPitch",
_("Pitch of the sound of a channel"),
_("Test the pitch of the sound on the specified channel. 1 is the default pitch."),
_("The pitch of the sound on channel _PARAM1_ is _PARAM2__PARAM3_"),
_("Audio/Sounds on channels"),
"res/conditions/sonVolume24.png",
"res/conditions/sonVolume.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Pitch to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddCondition(
"SoundChannelPitch",
_("Pitch of the sound of a channel"),
_("Test the pitch of the sound on the specified channel. 1 is the "
"default pitch."),
_("The pitch of the sound on channel _PARAM1_ is _PARAM2__PARAM3_"),
_("Audio/Sounds on channels"),
"res/conditions/sonVolume24.png",
"res/conditions/sonVolume.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Pitch to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddCondition("MusicChannelPitch",
_("Pitch of the music on a channel"),
_("Test the pitch (speed) of the music on a specified channel. 1 is the default pitch."),
_("The pitch of the music on channel _PARAM1_ is _PARAM2__PARAM3_"),
_("Audio/Music on channels"),
"res/conditions/musicVolume24.png",
"res/conditions/musicVolume.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Pitch to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddCondition(
"MusicChannelPitch",
_("Pitch of the music on a channel"),
_("Test the pitch (speed) of the music on a specified channel. 1 is "
"the default pitch."),
_("The pitch of the music on channel _PARAM1_ is _PARAM2__PARAM3_"),
_("Audio/Music on channels"),
"res/conditions/musicVolume24.png",
"res/conditions/musicVolume.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Pitch to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddCondition("SoundChannelPlayingOffset",
_("Playing offset of the sound on a channel"),
_("Test the playing offset of the sound on the specified channel."),
_("The playing offset of the sound on channel _PARAM1_ is _PARAM2__PARAM3_"),
_("Audio/Sounds on channels"),
"res/conditions/sonVolume24.png",
"res/conditions/sonVolume.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Playing position (in seconds)"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddCondition(
"SoundChannelPlayingOffset",
_("Playing offset of the sound on a channel"),
_("Test the playing offset of the sound on the specified channel."),
_("The playing offset of the sound on channel _PARAM1_ is "
"_PARAM2__PARAM3_"),
_("Audio/Sounds on channels"),
"res/conditions/sonVolume24.png",
"res/conditions/sonVolume.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Playing position (in seconds)"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddCondition("MusicChannelPlayingOffset",
_("Playing offset of the music on a channel"),
_("Test the playing offset of the music on the specified channel."),
_("The playing offset of the music on channel _PARAM1_ is _PARAM2__PARAM3_"),
_("Audio/Music on channels"),
"res/conditions/musicVolume24.png",
"res/conditions/musicVolume.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Playing position (in seconds)"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddCondition(
"MusicChannelPlayingOffset",
_("Playing offset of the music on a channel"),
_("Test the playing offset of the music on the specified channel."),
_("The playing offset of the music on channel _PARAM1_ is "
"_PARAM2__PARAM3_"),
_("Audio/Music on channels"),
"res/conditions/musicVolume24.png",
"res/conditions/musicVolume.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel identifier"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Playing position (in seconds)"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddExpression("SoundChannelPlayingOffset", _("Sound playing offset"), _("Sound playing offset"), _("Sounds"), "res/actions/son.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"));
extension
.AddExpression("SoundChannelPlayingOffset",
_("Sound playing offset"),
_("Sound playing offset"),
_("Sounds"),
"res/actions/son.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"));
extension.AddExpression("MusicChannelPlayingOffset", _("Music playing offset"), _("Music playing offset"), _("Music"), "res/actions/music.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"));
extension
.AddExpression("MusicChannelPlayingOffset",
_("Music playing offset"),
_("Music playing offset"),
_("Music"),
"res/actions/music.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"));
extension.AddExpression("SoundChannelVolume", _("Sound volume"), _("Sound volume"), _("Sounds"), "res/actions/son.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"));
extension
.AddExpression("SoundChannelVolume",
_("Sound volume"),
_("Sound volume"),
_("Sounds"),
"res/actions/son.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"));
extension.AddExpression("MusicChannelVolume", _("Music volume"), _("Music volume"), _("Music"), "res/actions/music.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"));
extension
.AddExpression("MusicChannelVolume",
_("Music volume"),
_("Music volume"),
_("Music"),
"res/actions/music.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"));
extension.AddExpression("SoundChannelPitch", _("Sound's pitch"), _("Sound's pitch"), _("Sounds"), "res/actions/son.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"));
extension
.AddExpression("SoundChannelPitch",
_("Sound's pitch"),
_("Sound's pitch"),
_("Sounds"),
"res/actions/son.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"));
extension.AddExpression("MusicChannelPitch", _("Music's pitch"), _("Music's pitch"), _("Music"), "res/actions/music.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"));
extension
.AddExpression("MusicChannelPitch",
_("Music's pitch"),
_("Music's pitch"),
_("Music"),
"res/actions/music.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Channel"));
extension.AddExpression("GlobalVolume", _("Global volume"), _("Global volume value"), _("Sound level"), "res/conditions/volume.png")
.AddCodeOnlyParameter("currentScene", "");
extension
.AddExpression("GlobalVolume",
_("Global volume"),
_("Global volume value"),
_("Sound level"),
"res/conditions/volume.png")
.AddCodeOnlyParameter("currentScene", "");
#endif
#endif
}
}
} // namespace gd

File diff suppressed because it is too large Load Diff

View File

@@ -1,385 +1,583 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "AllBuiltinExtensions.h"
#include "GDCore/Tools/Localization.h"
using namespace std;
namespace gd
{
namespace gd {
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsCameraExtension(gd::PlatformExtension & extension)
{
extension.SetExtensionInformation("BuiltinCamera",
_("Cameras and layers features"),
_("Built-in camera extension"),
"Florian Rival",
"Open source (MIT License)");
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsCameraExtension(
gd::PlatformExtension& extension) {
extension.SetExtensionInformation("BuiltinCamera",
_("Cameras and layers features"),
_("Built-in camera extension"),
"Florian Rival",
"Open source (MIT License)");
#if defined(GD_IDE_ONLY)
extension.AddCondition("CameraX",
_("Camera center X position"),
_("Compare the X position of the center of a camera."),
_("X position of camera _PARAM4_ is _PARAM1__PARAM2_ (layer: _PARAM3_)"),
_("Layers and cameras"),
"res/conditions/camera24.png",
"res/conditions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.AddParameter("layer", _("Layer (base layer if empty)"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "",true).SetDefaultValue("0")
.MarkAsAdvanced()
.SetManipulatedType("number");
#if defined(GD_IDE_ONLY)
extension
.AddCondition("CameraX",
_("Camera center X position"),
_("Compare the X position of the center of a camera."),
_("X position of camera _PARAM4_ is _PARAM1__PARAM2_ "
"(layer: _PARAM3_)"),
_("Layers and cameras"),
"res/conditions/camera24.png",
"res/conditions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.AddParameter("layer", _("Layer (base layer if empty)"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true)
.SetDefaultValue("0")
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddCondition("CameraY",
_("Camera center Y position"),
_("Compare the Y position of the center of a camera."),
_("The Y position of camera _PARAM4_ is _PARAM1__PARAM2_ (layer: _PARAM3_)"),
_("Layers and cameras"),
"res/conditions/camera24.png",
"res/conditions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.AddParameter("layer", _("Layer (base layer if empty)")).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)")).SetDefaultValue("0")
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddCondition("CameraY",
_("Camera center Y position"),
_("Compare the Y position of the center of a camera."),
_("The Y position of camera _PARAM4_ is _PARAM1__PARAM2_ "
"(layer: _PARAM3_)"),
_("Layers and cameras"),
"res/conditions/camera24.png",
"res/conditions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.AddParameter("layer", _("Layer (base layer if empty)"))
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"))
.SetDefaultValue("0")
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddAction("CameraX",
_("Camera center X position"),
_("Change the X position of the center of the specified camera."),
_("Do _PARAM1__PARAM2_ to X position of camera _PARAM4_ (layer: _PARAM3_)"),
_("Layers and cameras"),
"res/conditions/camera24.png",
"res/conditions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.AddParameter("layer", _("Layer (base layer if empty)"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "",true).SetDefaultValue("0")
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddAction(
"CameraX",
_("Camera center X position"),
_("Change the X position of the center of the specified camera."),
_("Do _PARAM1__PARAM2_ to X position of camera _PARAM4_ (layer: "
"_PARAM3_)"),
_("Layers and cameras"),
"res/conditions/camera24.png",
"res/conditions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.AddParameter("layer", _("Layer (base layer if empty)"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true)
.SetDefaultValue("0")
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddAction("CameraY",
_("Camera center Y position"),
_("Change the Y position of the center of the specified camera."),
_("Do _PARAM1__PARAM2_ to Y position of camera _PARAM4_ (layer: _PARAM3_)"),
_("Layers and cameras"),
"res/conditions/camera24.png",
"res/conditions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.AddParameter("layer", _("Layer (base layer if empty)"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "",true).SetDefaultValue("0")
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddAction(
"CameraY",
_("Camera center Y position"),
_("Change the Y position of the center of the specified camera."),
_("Do _PARAM1__PARAM2_ to Y position of camera _PARAM4_ (layer: "
"_PARAM3_)"),
_("Layers and cameras"),
"res/conditions/camera24.png",
"res/conditions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.AddParameter("layer", _("Layer (base layer if empty)"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true)
.SetDefaultValue("0")
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddCondition("CameraWidth",
_("Width of a camera"),
_("Test the width of a camera of a layer"),
_("The width of camera _PARAM2_ of layer _PARAM1_ is _PARAM3__PARAM4_"),
_("Layers and cameras"),
"res/conditions/camera24.png",
"res/conditions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer")).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddCondition("CameraWidth",
_("Width of a camera"),
_("Test the width of a camera of a layer"),
_("The width of camera _PARAM2_ of layer _PARAM1_ is "
"_PARAM3__PARAM4_"),
_("Layers and cameras"),
"res/conditions/camera24.png",
"res/conditions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"))
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddCondition("CameraHeight",
_("Height of a camera"),
_("Test the height of a camera of a layer"),
_("The height of camera _PARAM2_ of layer _PARAM1_ is _PARAM3__PARAM4_"),
_("Layers and cameras"),
"res/conditions/camera24.png",
"res/conditions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)")).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddCondition("CameraHeight",
_("Height of a camera"),
_("Test the height of a camera of a layer"),
_("The height of camera _PARAM2_ of layer _PARAM1_ is "
"_PARAM3__PARAM4_"),
_("Layers and cameras"),
"res/conditions/camera24.png",
"res/conditions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)"))
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddCondition("CameraAngle",
_("Angle of a camera of a layer"),
_("Test a camera angle."),
_("Angle of camera is _PARAM1__PARAM2_ (layer: _PARAM3_, camera: _PARAM4_)"),
_("Layers and cameras"),
"res/conditions/camera24.png",
"res/conditions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.AddParameter("layer", _("Layer (base layer if empty)"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "",true).SetDefaultValue("0")
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddCondition("CameraAngle",
_("Angle of a camera of a layer"),
_("Test a camera angle."),
_("Angle of camera is _PARAM1__PARAM2_ (layer: _PARAM3_, "
"camera: _PARAM4_)"),
_("Layers and cameras"),
"res/conditions/camera24.png",
"res/conditions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.AddParameter("layer", _("Layer (base layer if empty)"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true)
.SetDefaultValue("0")
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddAction("RotateCamera",
_("Change camera angle"),
_("This action modifies the angle of a camera in the specified layer."),
_("Do _PARAM1__PARAM2_ to angle of camera (layer: _PARAM3_, camera: _PARAM4_)"),
_("Layers and cameras"),
"res/actions/camera24.png",
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.AddParameter("layer", _("Layer (base layer if empty)"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "",true).SetDefaultValue("0")
.SetManipulatedType("number");
extension
.AddAction("RotateCamera",
_("Change camera angle"),
_("This action modifies the angle of a camera in the "
"specified layer."),
_("Do _PARAM1__PARAM2_ to angle of camera (layer: _PARAM3_, "
"camera: _PARAM4_)"),
_("Layers and cameras"),
"res/actions/camera24.png",
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.AddParameter("layer", _("Layer (base layer if empty)"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true)
.SetDefaultValue("0")
.SetManipulatedType("number");
extension.AddAction("AddCamera",
_("Add a camera to a layer"),
_("This action adds a camera to a layer"),
_("Add a camera to layer _PARAM1_"),
_("Layers and cameras"),
"res/actions/camera24.png",
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)")).SetDefaultValue("\"\"")
.AddParameter("expression", _("Width"), "",true)
.AddParameter("expression", _("Height"), "",true)
.AddParameter("expression", _("Render zone: Top left side: X Position (between 0 and 1)"), "",true)
.AddParameter("expression", _("Render zone: Top left side: Y Position (between 0 and 1)"), "",true)
.AddParameter("expression", _("Render zone: Bottom right side: X Position (between 0 and 1)"), "",true)
.AddParameter("expression", _("Render zone: Bottom right side: Y Position (between 0 and 1)"), "",true)
.MarkAsComplex();
extension
.AddAction("AddCamera",
_("Add a camera to a layer"),
_("This action adds a camera to a layer"),
_("Add a camera to layer _PARAM1_"),
_("Layers and cameras"),
"res/actions/camera24.png",
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)"))
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Width"), "", true)
.AddParameter("expression", _("Height"), "", true)
.AddParameter(
"expression",
_("Render zone: Top left side: X Position (between 0 and 1)"),
"",
true)
.AddParameter(
"expression",
_("Render zone: Top left side: Y Position (between 0 and 1)"),
"",
true)
.AddParameter(
"expression",
_("Render zone: Bottom right side: X Position (between 0 and 1)"),
"",
true)
.AddParameter(
"expression",
_("Render zone: Bottom right side: Y Position (between 0 and 1)"),
"",
true)
.MarkAsComplex();
extension.AddAction("DeleteCamera",
_("Delete a camera of a layer"),
_("Remove the specified camera from a layer"),
_("Delete camera _PARAM2_ from layer _PARAM1_"),
_("Layers and cameras"),
"res/actions/camera24.png",
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)")).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number"))
.MarkAsComplex();
extension
.AddAction("DeleteCamera",
_("Delete a camera of a layer"),
_("Remove the specified camera from a layer"),
_("Delete camera _PARAM2_ from layer _PARAM1_"),
_("Layers and cameras"),
"res/actions/camera24.png",
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)"))
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number"))
.MarkAsComplex();
extension.AddAction("CameraSize",
_("Modify the size of a camera"),
_("This action modifies the size of a camera of the specified layer. The zoom will be reset."),
_("Change the size of camera _PARAM2_ of _PARAM1_ to _PARAM3_*_PARAM4_"),
_("Layers and cameras"),
"res/actions/camera24.png",
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)")).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number"))
.AddParameter("expression", _("Width"))
.AddParameter("expression", _("Height"))
.MarkAsComplex();
extension
.AddAction("CameraSize",
_("Modify the size of a camera"),
_("This action modifies the size of a camera of the specified "
"layer. The zoom will be reset."),
_("Change the size of camera _PARAM2_ of _PARAM1_ to "
"_PARAM3_*_PARAM4_"),
_("Layers and cameras"),
"res/actions/camera24.png",
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)"))
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number"))
.AddParameter("expression", _("Width"))
.AddParameter("expression", _("Height"))
.MarkAsComplex();
extension.AddAction("CameraViewport",
_("Modify the render zone of a camera"),
_("This action modifies the render zone of a camera of the specified layer."),
_("Set the render zone of camera _PARAM2_ from layer _PARAM1_ to _PARAM3_;_PARAM4_ _PARAM5_;_PARAM6_"),
_("Layers and cameras"),
"res/actions/camera24.png",
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)")).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number"))
.AddParameter("expression", _("Render zone: Top left side: X Position (between 0 and 1)"))
.AddParameter("expression", _("Render zone: Top left side: Y Position (between 0 and 1)"))
.AddParameter("expression", _("Render zone: Bottom right side: X Position (between 0 and 1)"))
.AddParameter("expression", _("Render zone: Bottom right side: Y Position (between 0 and 1)"))
.MarkAsComplex();
extension
.AddAction("CameraViewport",
_("Modify the render zone of a camera"),
_("This action modifies the render zone of a camera of the "
"specified layer."),
_("Set the render zone of camera _PARAM2_ from layer _PARAM1_ "
"to _PARAM3_;_PARAM4_ _PARAM5_;_PARAM6_"),
_("Layers and cameras"),
"res/actions/camera24.png",
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)"))
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number"))
.AddParameter(
"expression",
_("Render zone: Top left side: X Position (between 0 and 1)"))
.AddParameter(
"expression",
_("Render zone: Top left side: Y Position (between 0 and 1)"))
.AddParameter(
"expression",
_("Render zone: Bottom right side: X Position (between 0 and 1)"))
.AddParameter(
"expression",
_("Render zone: Bottom right side: Y Position (between 0 and 1)"))
.MarkAsComplex();
extension.AddAction("ZoomCamera",
_("Change camera zoom."),
_("Change camera zoom."),
_("Change camera zoom to _PARAM1_ (layer : _PARAM2_, camera : _PARAM3_)"),
_("Layers and cameras"),
"res/actions/camera24.png",
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Value (1:Initial zoom, 2:Zoom x2, 0.5:Unzoom x2...)"))
.AddParameter("layer", _("Layer (base layer if empty)"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "",true).SetDefaultValue("0");
extension
.AddAction("ZoomCamera",
_("Change camera zoom."),
_("Change camera zoom."),
_("Change camera zoom to _PARAM1_ (layer : _PARAM2_, camera : "
"_PARAM3_)"),
_("Layers and cameras"),
"res/actions/camera24.png",
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression",
_("Value (1:Initial zoom, 2:Zoom x2, 0.5:Unzoom x2...)"))
.AddParameter("layer", _("Layer (base layer if empty)"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true)
.SetDefaultValue("0");
extension.AddAction("FixCamera",
_("Center the camera on an object within limits"),
_("Center the camera on the specified object, without leaving the specified limits."),
_("Center the camera on _PARAM1_ (limit : from _PARAM2_;_PARAM3_ to _PARAM4_;_PARAM5_) (layer: _PARAM7_, camera: _PARAM8_)"),
_("Layers and cameras"),
"res/actions/camera24.png",
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("objectPtr", _("Object"))
.AddParameter("expression", _("Top left side of the boundary: X Position"))
.AddParameter("expression", _("Top left side of the boundary: Y Position"))
.AddParameter("expression", _("Bottom right side of the boundary: X Position"))
.AddParameter("expression", _("Bottom right side of the boundary: Y Position"))
.AddParameter("yesorno", _("Anticipate the movement of the object (yes by default)"), "",true).SetDefaultValue("yes")
.AddParameter("layer", _("Layer (base layer if empty)"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "",true).SetDefaultValue("0")
.MarkAsAdvanced();
extension
.AddAction(
"FixCamera",
_("Center the camera on an object within limits"),
_("Center the camera on the specified object, without leaving the "
"specified limits."),
_("Center the camera on _PARAM1_ (limit : from _PARAM2_;_PARAM3_ to "
"_PARAM4_;_PARAM5_) (layer: _PARAM7_, camera: _PARAM8_)"),
_("Layers and cameras"),
"res/actions/camera24.png",
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("objectPtr", _("Object"))
.AddParameter("expression",
_("Top left side of the boundary: X Position"))
.AddParameter("expression",
_("Top left side of the boundary: Y Position"))
.AddParameter("expression",
_("Bottom right side of the boundary: X Position"))
.AddParameter("expression",
_("Bottom right side of the boundary: Y Position"))
.AddParameter("yesorno",
_("Anticipate the movement of the object (yes by default)"),
"",
true)
.SetDefaultValue("yes")
.AddParameter("layer", _("Layer (base layer if empty)"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true)
.SetDefaultValue("0")
.MarkAsAdvanced();
extension.AddAction("CentreCamera",
_("Center the camera on an object"),
_("Center the camera on the specified object."),
_("Center camera on _PARAM1_ (layer: _PARAM3_, camera: _PARAM4_)"),
_("Layers and cameras"),
"res/actions/camera24.png",
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("objectPtr", _("Object"))
.AddParameter("yesorno", _("Anticipate the movement of the object (yes by default)"), "",true).SetDefaultValue("yes")
.AddParameter("layer", _("Layer (base layer if empty)"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "",true).SetDefaultValue("0")
.MarkAsSimple();
extension
.AddAction(
"CentreCamera",
_("Center the camera on an object"),
_("Center the camera on the specified object."),
_("Center camera on _PARAM1_ (layer: _PARAM3_, camera: _PARAM4_)"),
_("Layers and cameras"),
"res/actions/camera24.png",
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("objectPtr", _("Object"))
.AddParameter("yesorno",
_("Anticipate the movement of the object (yes by default)"),
"",
true)
.SetDefaultValue("yes")
.AddParameter("layer", _("Layer (base layer if empty)"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true)
.SetDefaultValue("0")
.MarkAsSimple();
extension.AddAction("ShowLayer",
_("Show a layer"),
_("Show a layer."),
_("Show layer _PARAM1_"),
_("Layers and cameras"),
"res/actions/layer24.png",
"res/actions/layer.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)")).SetDefaultValue("\"\"")
.MarkAsAdvanced();
extension
.AddAction("ShowLayer",
_("Show a layer"),
_("Show a layer."),
_("Show layer _PARAM1_"),
_("Layers and cameras"),
"res/actions/layer24.png",
"res/actions/layer.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)"))
.SetDefaultValue("\"\"")
.MarkAsAdvanced();
extension.AddAction("HideLayer",
_("Hide a layer"),
_("Hide a layer."),
_("Hide layer _PARAM1_"),
_("Layers and cameras"),
"res/actions/layer24.png",
"res/actions/layer.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)")).SetDefaultValue("\"\"")
.MarkAsAdvanced();
extension
.AddAction("HideLayer",
_("Hide a layer"),
_("Hide a layer."),
_("Hide layer _PARAM1_"),
_("Layers and cameras"),
"res/actions/layer24.png",
"res/actions/layer.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)"))
.SetDefaultValue("\"\"")
.MarkAsAdvanced();
extension.AddCondition("LayerVisible",
_("Visibility of a layer"),
_("Test if a layer is set as visible."),
_("Layer _PARAM1_ is visible"),
_("Layers and cameras"),
"res/conditions/layer24.png",
"res/conditions/layer.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)")).SetDefaultValue("\"\"")
.MarkAsAdvanced();
extension
.AddCondition("LayerVisible",
_("Visibility of a layer"),
_("Test if a layer is set as visible."),
_("Layer _PARAM1_ is visible"),
_("Layers and cameras"),
"res/conditions/layer24.png",
"res/conditions/layer.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)"))
.SetDefaultValue("\"\"")
.MarkAsAdvanced();
extension.AddAction("SetLayerEffectParameter",
_("Effect parameter"),
_("Change the parameter of an effect"),
_("Set _PARAM3_ to _PARAM4_ for effect _PARAM2_ of layer _PARAM1_"),
_("Layers and cameras/Effects"),
"res/conditions/camera24.png",
"res/conditions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)"), "",true).SetDefaultValue("\"\"")
.AddParameter("string", _("Effect"))
.AddParameter("string", _("Parameter name"))
.AddParameter("expression", _("New value"))
.MarkAsAdvanced();
extension
.AddAction(
"SetLayerEffectParameter",
_("Effect parameter"),
_("Change the parameter of an effect"),
_("Set _PARAM3_ to _PARAM4_ for effect _PARAM2_ of layer _PARAM1_"),
_("Layers and cameras/Effects"),
"res/conditions/camera24.png",
"res/conditions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("string", _("Effect"))
.AddParameter("string", _("Parameter name"))
.AddParameter("expression", _("New value"))
.MarkAsAdvanced();
extension.AddCondition("LayerTimeScale",
_("Layer time scale"),
_("Compare the time scale applied to the objects of the layer."),
_("The time scale of layer _PARAM1_ is _PARAM2__PARAM3_"),
_("Layers and cameras/Time"),
"res/conditions/time24.png",
"res/conditions/time.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)"), "",true).SetDefaultValue("\"\"")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddCondition(
"LayerTimeScale",
_("Layer time scale"),
_("Compare the time scale applied to the objects of the layer."),
_("The time scale of layer _PARAM1_ is _PARAM2__PARAM3_"),
_("Layers and cameras/Time"),
"res/conditions/time24.png",
"res/conditions/time.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddAction("ChangeLayerTimeScale",
_("Change layer time scale"),
_("Change the time scale applied to the objects of the layer."),
_("Set time scale of layer _PARAM1_ to _PARAM2_"),
_("Layers and cameras/Time"),
"res/actions/time24.png",
"res/actions/time.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Scale (1: Default, 2: 2x faster, 0.5: 2x slower...)"));
extension
.AddAction(
"ChangeLayerTimeScale",
_("Change layer time scale"),
_("Change the time scale applied to the objects of the layer."),
_("Set time scale of layer _PARAM1_ to _PARAM2_"),
_("Layers and cameras/Time"),
"res/actions/time24.png",
"res/actions/time.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("expression",
_("Scale (1: Default, 2: 2x faster, 0.5: 2x slower...)"));
extension.AddExpression("CameraWidth", _("Width of a camera of a layer"), _("Width of a camera of a layer"), _("Layers and cameras"), "res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"))
.AddParameter("expression", _("Camera number (default : 0)")).SetDefaultValue("0");
extension
.AddExpression("CameraWidth",
_("Width of a camera of a layer"),
_("Width of a camera of a layer"),
_("Layers and cameras"),
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"))
.AddParameter("expression", _("Camera number (default : 0)"))
.SetDefaultValue("0");
extension.AddExpression("CameraHeight", _("Height of a camera of a layer"), _("Height of a camera of a layer"), _("Layers and cameras"), "res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"))
.AddParameter("expression", _("Camera number (default : 0)")).SetDefaultValue("0");
extension
.AddExpression("CameraHeight",
_("Height of a camera of a layer"),
_("Height of a camera of a layer"),
_("Layers and cameras"),
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"))
.AddParameter("expression", _("Camera number (default : 0)"))
.SetDefaultValue("0");
extension.AddExpression("CameraViewportLeft", _("X position of the top left side point of a render zone"), _("X position of the top left side point of a render zone"), _("Layers and cameras"), "res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"))
.AddParameter("expression", _("Camera number (default : 0)")).SetDefaultValue("0");
extension
.AddExpression(
"CameraViewportLeft",
_("X position of the top left side point of a render zone"),
_("X position of the top left side point of a render zone"),
_("Layers and cameras"),
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"))
.AddParameter("expression", _("Camera number (default : 0)"))
.SetDefaultValue("0");
extension.AddExpression("CameraViewportTop", _("Y position of the top left side point of a render zone"), _("Y position of the top left side point of a render zone"), _("Layers and cameras"), "res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"))
.AddParameter("expression", _("Camera number (default : 0)")).SetDefaultValue("0");
extension
.AddExpression(
"CameraViewportTop",
_("Y position of the top left side point of a render zone"),
_("Y position of the top left side point of a render zone"),
_("Layers and cameras"),
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"))
.AddParameter("expression", _("Camera number (default : 0)"))
.SetDefaultValue("0");
extension.AddExpression("CameraViewportRight", _("X position of the bottom right side point of a render zone"), _("X position of the bottom right side point of a render zone"), _("Layers and cameras"), "res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"))
.AddParameter("expression", _("Camera number (default : 0)")).SetDefaultValue("0");
extension
.AddExpression(
"CameraViewportRight",
_("X position of the bottom right side point of a render zone"),
_("X position of the bottom right side point of a render zone"),
_("Layers and cameras"),
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"))
.AddParameter("expression", _("Camera number (default : 0)"))
.SetDefaultValue("0");
extension.AddExpression("CameraViewportBottom", _("Y position of the bottom right side point of a render zone"), _("Y position of the bottom right side point of a render zone"), _("Layers and cameras"), "res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"))
.AddParameter("expression", _("Camera number (default : 0)")).SetDefaultValue("0");
extension
.AddExpression(
"CameraViewportBottom",
_("Y position of the bottom right side point of a render zone"),
_("Y position of the bottom right side point of a render zone"),
_("Layers and cameras"),
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"))
.AddParameter("expression", _("Camera number (default : 0)"))
.SetDefaultValue("0");
extension.AddExpression("CameraX", _("Camera X position"), _("Camera X position"), _("Layers and cameras"), "res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "",true).SetDefaultValue("0");
extension
.AddExpression("CameraX",
_("Camera X position"),
_("Camera X position"),
_("Layers and cameras"),
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true)
.SetDefaultValue("0");
extension.AddExpression("VueX", _("Camera X position"), _("Camera X position"), _("Layers and cameras"), "res/actions/camera.png")
.SetHidden()
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "",true).SetDefaultValue("0");
extension
.AddExpression("VueX",
_("Camera X position"),
_("Camera X position"),
_("Layers and cameras"),
"res/actions/camera.png")
.SetHidden()
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true)
.SetDefaultValue("0");
extension.AddExpression("CameraY", _("Camera Y position"), _("Camera Y position"), _("Layers and cameras"), "res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "",true).SetDefaultValue("0");
extension
.AddExpression("CameraY",
_("Camera Y position"),
_("Camera Y position"),
_("Layers and cameras"),
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true)
.SetDefaultValue("0");
extension.AddExpression("VueY", _("Camera Y position"), _("Camera Y position"), _("Layers and cameras"), "res/actions/camera.png")
.SetHidden()
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "",true).SetDefaultValue("0");
extension
.AddExpression("VueY",
_("Camera Y position"),
_("Camera Y position"),
_("Layers and cameras"),
"res/actions/camera.png")
.SetHidden()
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true)
.SetDefaultValue("0");
extension.AddExpression("CameraRotation", _("Angle of a camera of a layer"), _("Angle of a camera of a layer"), _("Layers and cameras"), "res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "",true).SetDefaultValue("0");
extension
.AddExpression("CameraRotation",
_("Angle of a camera of a layer"),
_("Angle of a camera of a layer"),
_("Layers and cameras"),
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true)
.SetDefaultValue("0");
extension.AddExpression("VueRotation", _("Angle of a camera of a layer"), _("Angle of a camera of a layer"), _("Layers and cameras"), "res/actions/camera.png")
.SetHidden()
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "",true).SetDefaultValue("0");
extension
.AddExpression("VueRotation",
_("Angle of a camera of a layer"),
_("Angle of a camera of a layer"),
_("Layers and cameras"),
"res/actions/camera.png")
.SetHidden()
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true)
.SetDefaultValue("0");
extension.AddExpression("LayerTimeScale", _("Time scale"), _("Time scale"), _("Layers and cameras"), "res/actions/time.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"));
#endif
extension
.AddExpression("LayerTimeScale",
_("Time scale"),
_("Time scale"),
_("Layers and cameras"),
"res/actions/time.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"));
#endif
}
}
} // namespace gd

View File

@@ -1,61 +1,69 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "AllBuiltinExtensions.h"
#include "GDCore/Tools/Localization.h"
using namespace std;
namespace gd
{
namespace gd {
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsCommonConversionsExtension(gd::PlatformExtension & extension)
{
extension.SetExtensionInformation("BuiltinCommonConversions",
_("Standard Conversions"),
_("Built-in extension providing standard conversions expressions."),
"Florian Rival",
"Open source (MIT License)");
void GD_CORE_API
BuiltinExtensionsImplementer::ImplementsCommonConversionsExtension(
gd::PlatformExtension& extension) {
extension.SetExtensionInformation(
"BuiltinCommonConversions",
_("Standard Conversions"),
_("Built-in extension providing standard conversions expressions."),
"Florian Rival",
"Open source (MIT License)");
#if defined(GD_IDE_ONLY)
#if defined(GD_IDE_ONLY)
extension.AddExpression("ToNumber",
_("Text > Number"),
_("Convert the text to a number"),
_("Conversion"),
"res/conditions/toujours24.png")
.AddParameter("string", _("Text to convert to a number"));
extension
.AddExpression("ToNumber",
_("Text > Number"),
_("Convert the text to a number"),
_("Conversion"),
"res/conditions/toujours24.png")
.AddParameter("string", _("Text to convert to a number"));
extension.AddStrExpression("ToString",
_("Number > Text"),
_("Convert the result of the expression to text"),
_("Conversion"),
"res/conditions/toujours24.png")
.AddParameter("expression", _("Expression to be converted to text"));
extension
.AddStrExpression("ToString",
_("Number > Text"),
_("Convert the result of the expression to text"),
_("Conversion"),
"res/conditions/toujours24.png")
.AddParameter("expression", _("Expression to be converted to text"));
extension.AddStrExpression("LargeNumberToString",
_("Number > Text ( without scientific notation )"),
_("Convert the result of the expression to text, without using the scientific notation"),
_("Conversion"),
"res/conditions/toujours24.png")
.AddParameter("expression", _("Expression to be converted to text"));
extension
.AddStrExpression("LargeNumberToString",
_("Number > Text ( without scientific notation )"),
_("Convert the result of the expression to text, "
"without using the scientific notation"),
_("Conversion"),
"res/conditions/toujours24.png")
.AddParameter("expression", _("Expression to be converted to text"));
extension.AddExpression("ToRad",
_("Degrees > Radians"),
_("Converts the angle, expressed in degrees, into radians"),
_("Conversion"),
"res/conditions/toujours24.png")
.AddParameter("expression", _("Angle, in degrees"));
extension
.AddExpression(
"ToRad",
_("Degrees > Radians"),
_("Converts the angle, expressed in degrees, into radians"),
_("Conversion"),
"res/conditions/toujours24.png")
.AddParameter("expression", _("Angle, in degrees"));
extension.AddExpression("ToDeg",
_("Radians > Degrees"),
_("Converts the angle, expressed in radians, into degrees"),
_("Conversion"),
"res/conditions/toujours24.png")
.AddParameter("expression", _("Angle, in radians"));
#endif
extension
.AddExpression(
"ToDeg",
_("Radians > Degrees"),
_("Converts the angle, expressed in radians, into degrees"),
_("Conversion"),
"res/conditions/toujours24.png")
.AddParameter("expression", _("Angle, in radians"));
#endif
}
}
} // namespace gd

View File

@@ -1,107 +1,128 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "AllBuiltinExtensions.h"
#include "GDCore/Tools/Localization.h"
#if defined(GD_IDE_ONLY)
#include "GDCore/Events/Event.h"
#include "GDCore/Events/Builtin/StandardEvent.h"
#include "GDCore/Events/Builtin/CommentEvent.h"
#include "GDCore/Events/Builtin/ForEachEvent.h"
#include "GDCore/Events/Builtin/WhileEvent.h"
#include "GDCore/Events/Builtin/RepeatEvent.h"
#include "GDCore/Events/Builtin/LinkEvent.h"
#include "GDCore/Events/Builtin/GroupEvent.h"
#include "GDCore/Events/Builtin/LinkEvent.h"
#include "GDCore/Events/Builtin/RepeatEvent.h"
#include "GDCore/Events/Builtin/StandardEvent.h"
#include "GDCore/Events/Builtin/WhileEvent.h"
#include "GDCore/Events/Event.h"
#endif
using namespace std;
namespace gd
{
namespace gd {
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsCommonInstructionsExtension(gd::PlatformExtension & extension)
{
extension.SetExtensionInformation("BuiltinCommonInstructions",
_("Standard events"),
_("Built-in extension providing standard events."),
"Florian Rival",
"Open source (MIT License)");
void GD_CORE_API
BuiltinExtensionsImplementer::ImplementsCommonInstructionsExtension(
gd::PlatformExtension& extension) {
extension.SetExtensionInformation(
"BuiltinCommonInstructions",
_("Standard events"),
_("Built-in extension providing standard events."),
"Florian Rival",
"Open source (MIT License)");
#if defined(GD_IDE_ONLY)
extension.AddCondition("Or",
_("Or"),
_("Return true if one of the sub conditions is true"),
_("If one of these conditions is true:"),
_("Advanced"),
"res/conditions/or24.png",
"res/conditions/or.png")
.SetCanHaveSubInstructions()
.MarkAsAdvanced();
extension
.AddCondition("Or",
_("Or"),
_("Return true if one of the sub conditions is true"),
_("If one of these conditions is true:"),
_("Advanced"),
"res/conditions/or24.png",
"res/conditions/or.png")
.SetCanHaveSubInstructions()
.MarkAsAdvanced();
extension.AddCondition("And",
_("And"),
_("Return true if all sub conditions are true"),
_("If all of these conditions are true:"),
_("Advanced"),
"res/conditions/and24.png",
"res/conditions/and.png")
.SetCanHaveSubInstructions()
.MarkAsAdvanced();
extension
.AddCondition("And",
_("And"),
_("Return true if all sub conditions are true"),
_("If all of these conditions are true:"),
_("Advanced"),
"res/conditions/and24.png",
"res/conditions/and.png")
.SetCanHaveSubInstructions()
.MarkAsAdvanced();
extension.AddCondition("Not",
_("Not"),
_("Return the contrary of the result of the sub conditions"),
_("Invert the logical result of these conditions:"),
_("Advanced"),
"res/conditions/not24.png",
"res/conditions/not.png")
.SetCanHaveSubInstructions()
.MarkAsAdvanced();
extension
.AddCondition(
"Not",
_("Not"),
_("Return the contrary of the result of the sub conditions"),
_("Invert the logical result of these conditions:"),
_("Advanced"),
"res/conditions/not24.png",
"res/conditions/not.png")
.SetCanHaveSubInstructions()
.MarkAsAdvanced();
extension.AddCondition("Once",
_("Trigger once while true"),
_("Run actions only once, for each time the conditions have been met."),
_("Trigger once"),
_("Advanced"),
"res/conditions/once24.png",
"res/conditions/once.png");
extension.AddCondition(
"Once",
_("Trigger once while true"),
_("Run actions only once, for each time the conditions have been met."),
_("Trigger once"),
_("Advanced"),
"res/conditions/once24.png",
"res/conditions/once.png");
extension.AddEvent("Standard", _("Standard event"),
_("Standard event: Actions are run if conditions are fulfilled."),
"", "res/eventaddicon.png",
std::make_shared<gd::StandardEvent>());
extension.AddEvent(
"Standard",
_("Standard event"),
_("Standard event: Actions are run if conditions are fulfilled."),
"",
"res/eventaddicon.png",
std::make_shared<gd::StandardEvent>());
extension.AddEvent("Link", _("Link"),
_("Link to some external events"),
"", "res/lienaddicon.png",
std::make_shared<gd::LinkEvent>());
extension.AddEvent("Link",
_("Link"),
_("Link to some external events"),
"",
"res/lienaddicon.png",
std::make_shared<gd::LinkEvent>());
extension.AddEvent("Comment", _("Comment"),
_("Event displaying a text in the events editor"),
"", "res/comment.png",
std::make_shared<gd::CommentEvent>());
extension.AddEvent("Comment",
_("Comment"),
_("Event displaying a text in the events editor"),
"",
"res/comment.png",
std::make_shared<gd::CommentEvent>());
extension.AddEvent("While", _("While"),
_("The event is repeated while the conditions are true"),
"", "res/while.png",
std::make_shared<gd::WhileEvent>());
extension.AddEvent("While",
_("While"),
_("The event is repeated while the conditions are true"),
"",
"res/while.png",
std::make_shared<gd::WhileEvent>());
extension.AddEvent("Repeat", _("Repeat"),
_("Event repeated a number of times"),
"", "res/repeat.png",
std::make_shared<gd::RepeatEvent>());
extension.AddEvent("Repeat",
_("Repeat"),
_("Event repeated a number of times"),
"",
"res/repeat.png",
std::make_shared<gd::RepeatEvent>());
extension.AddEvent("ForEach", _("For each object"),
_("Repeat the event for each specified object."),
"", "res/foreach.png",
std::make_shared<gd::ForEachEvent>());
extension.AddEvent("ForEach",
_("For each object"),
_("Repeat the event for each specified object."),
"",
"res/foreach.png",
std::make_shared<gd::ForEachEvent>());
extension.AddEvent("Group", _("Group"),
_("Group containing events"),
"", "res/foreach.png",
std::make_shared<gd::GroupEvent>());
extension.AddEvent("Group",
_("Group"),
_("Group containing events"),
"",
"res/foreach.png",
std::make_shared<gd::GroupEvent>());
#endif
}
}
} // namespace gd

View File

@@ -1,37 +1,42 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "AllBuiltinExtensions.h"
#include "GDCore/Tools/Localization.h"
using namespace std;
namespace gd
{
namespace gd {
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsExternalLayoutsExtension(gd::PlatformExtension & extension)
{
extension.SetExtensionInformation("BuiltinExternalLayouts",
_("External layouts"),
_("Built-in extension providing actions and conditions related to external layouts"),
"Florian Rival",
"Open source (MIT License)");
void GD_CORE_API
BuiltinExtensionsImplementer::ImplementsExternalLayoutsExtension(
gd::PlatformExtension& extension) {
extension.SetExtensionInformation(
"BuiltinExternalLayouts",
_("External layouts"),
_("Built-in extension providing actions and conditions related to "
"external layouts"),
"Florian Rival",
"Open source (MIT License)");
#if defined(GD_IDE_ONLY)
extension.AddAction("CreateObjectsFromExternalLayout",
_("Create objects from an external layout"),
_("Create objects from an external layout."),
_("Create objects from the external layout named _PARAM1_"),
_("External layouts"),
"res/conditions/fichier24.png",
"res/conditions/fichier.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Name of the external layout"))
.AddParameter("expression", _("X position of the origin"), "",true).SetDefaultValue("0")
.AddParameter("expression", _("Y position of the origin"), "",true).SetDefaultValue("0")
.MarkAsAdvanced();
#endif
#if defined(GD_IDE_ONLY)
extension
.AddAction("CreateObjectsFromExternalLayout",
_("Create objects from an external layout"),
_("Create objects from an external layout."),
_("Create objects from the external layout named _PARAM1_"),
_("External layouts"),
"res/conditions/fichier24.png",
"res/conditions/fichier.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Name of the external layout"))
.AddParameter("expression", _("X position of the origin"), "", true)
.SetDefaultValue("0")
.AddParameter("expression", _("Y position of the origin"), "", true)
.SetDefaultValue("0")
.MarkAsAdvanced();
#endif
}
}
} // namespace gd

View File

@@ -1,151 +1,190 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "AllBuiltinExtensions.h"
#include "GDCore/Tools/Localization.h"
using namespace std;
namespace gd
{
namespace gd {
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsFileExtension(gd::PlatformExtension & extension)
{
extension.SetExtensionInformation("BuiltinFile",
_("Storage and files"),
_("Built-in extension providing functions to store data and manipulate files."),
"Florian Rival",
"Open source (MIT License)");
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsFileExtension(
gd::PlatformExtension& extension) {
extension.SetExtensionInformation("BuiltinFile",
_("Storage and files"),
_("Built-in extension providing functions "
"to store data and manipulate files."),
"Florian Rival",
"Open source (MIT License)");
#if defined(GD_IDE_ONLY)
extension.AddCondition("GroupExists",
_("Existence of a group"),
_("Check if an element (example : PlayerState/CurrentLevel) exists in the file.\nSpaces are forbidden in element names."),
_("_PARAM1_ exists in file _PARAM0_"),
_("Storage"),
"res/conditions/fichier24.png",
"res/conditions/fichier.png")
.AddParameter("file", _("Filename"))
.AddParameter("string", _("Group"))
.MarkAsAdvanced();
#if defined(GD_IDE_ONLY)
extension
.AddCondition(
"GroupExists",
_("Existence of a group"),
_("Check if an element (example : PlayerState/CurrentLevel) exists "
"in the file.\nSpaces are forbidden in element names."),
_("_PARAM1_ exists in file _PARAM0_"),
_("Storage"),
"res/conditions/fichier24.png",
"res/conditions/fichier.png")
.AddParameter("file", _("Filename"))
.AddParameter("string", _("Group"))
.MarkAsAdvanced();
extension.AddAction("LoadFile",
_("Load a structured file in memory"),
_("This action loads the structured file in memory, so you can write and read it.\nYou can open and write without using this action, but it will be slower.\nIf you use this action, do not forget to unload the file from memory.\n\nFor the native platform, the file format is XML."),
_("Load structured file _PARAM0_ in memory"),
_("Storage"),
"res/actions/fichier24.png",
"res/actions/fichier.png")
.AddParameter("file", _("File"))
.MarkAsAdvanced();
extension
.AddAction(
"LoadFile",
_("Load a structured file in memory"),
_("This action loads the structured file in memory, so you can write "
"and read it.\nYou can open and write without using this action, "
"but it will be slower.\nIf you use this action, do not forget to "
"unload the file from memory.\n\nFor the native platform, the file "
"format is XML."),
_("Load structured file _PARAM0_ in memory"),
_("Storage"),
"res/actions/fichier24.png",
"res/actions/fichier.png")
.AddParameter("file", _("File"))
.MarkAsAdvanced();
extension.AddAction("UnloadFile",
_("Close a structured file"),
_("This action closes the structured file previously loaded in memory, saving all changes made."),
_("Close structured file _PARAM0_"),
_("Storage"),
"res/actions/fichier24.png",
"res/actions/fichier.png")
.AddParameter("file", _("File"))
.MarkAsAdvanced();
extension
.AddAction("UnloadFile",
_("Close a structured file"),
_("This action closes the structured file previously loaded "
"in memory, saving all changes made."),
_("Close structured file _PARAM0_"),
_("Storage"),
"res/actions/fichier24.png",
"res/actions/fichier.png")
.AddParameter("file", _("File"))
.MarkAsAdvanced();
extension.AddAction("EcrireFichierExp",
_("Write a value"),
_("Write the result of the expression in the file, in the specified element.\nSpecify the structure leading to the element using / (example : Root/Level/Current)\nSpaces are forbidden in element names."),
_("Write _PARAM2_ in _PARAM1_ of file _PARAM0_"),
_("Storage"),
"res/actions/fichier24.png",
"res/actions/fichier.png")
.AddParameter("file", _("File"))
.AddParameter("string", _("Group"))
.AddParameter("expression", _("Expression"));
extension
.AddAction("EcrireFichierExp",
_("Write a value"),
_("Write the result of the expression in the file, in the "
"specified element.\nSpecify the structure leading to the "
"element using / (example : Root/Level/Current)\nSpaces are "
"forbidden in element names."),
_("Write _PARAM2_ in _PARAM1_ of file _PARAM0_"),
_("Storage"),
"res/actions/fichier24.png",
"res/actions/fichier.png")
.AddParameter("file", _("File"))
.AddParameter("string", _("Group"))
.AddParameter("expression", _("Expression"));
extension.AddAction("EcrireFichierTxt",
_("Write a text"),
_("Write the text in the file, in the specified element.\nSpecify the structure leading to the element using / (example : Root/Level/Current)\nSpaces are forbidden in element names."),
_("Write _PARAM2_ in _PARAM1_ of file _PARAM0_"),
_("Storage"),
"res/actions/fichier24.png",
"res/actions/fichier.png")
.AddParameter("file", _("File"))
.AddParameter("string", _("Group"))
.AddParameter("string", _("Text"));
extension
.AddAction(
"EcrireFichierTxt",
_("Write a text"),
_("Write the text in the file, in the specified element.\nSpecify "
"the structure leading to the element using / (example : "
"Root/Level/Current)\nSpaces are forbidden in element names."),
_("Write _PARAM2_ in _PARAM1_ of file _PARAM0_"),
_("Storage"),
"res/actions/fichier24.png",
"res/actions/fichier.png")
.AddParameter("file", _("File"))
.AddParameter("string", _("Group"))
.AddParameter("string", _("Text"));
extension.AddAction("LireFichierExp",
_("Read a value"),
_("Read the value saved in the specified element and store it in a variable.\nSpecify the structure leading to the element using / (example : Root/Level/Current)\nSpaces are forbidden in element names."),
_("Read _PARAM1_ from file _PARAM0_ and store value in _PARAM3_"),
_("Storage"),
"res/actions/fichier24.png",
"res/actions/fichier.png")
.AddParameter("file", _("File"))
.AddParameter("string", _("Group"))
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("scenevar", _("Scene variables"));
extension
.AddAction(
"LireFichierExp",
_("Read a value"),
_("Read the value saved in the specified element and store it in a "
"variable.\nSpecify the structure leading to the element using / "
"(example : Root/Level/Current)\nSpaces are forbidden in element "
"names."),
_("Read _PARAM1_ from file _PARAM0_ and store value in _PARAM3_"),
_("Storage"),
"res/actions/fichier24.png",
"res/actions/fichier.png")
.AddParameter("file", _("File"))
.AddParameter("string", _("Group"))
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("scenevar", _("Scene variables"));
extension.AddAction("LireFichierTxt",
_("Read a text"),
_("Read the text saved in the specified element and store it in a variable.\nSpecify the structure leading to the element using / (example : Root/Level/Current)\nSpaces are forbidden in element names."),
_("Read _PARAM1_ from file _PARAM0_ and store as text in _PARAM3_"),
_("Storage"),
"res/actions/fichier24.png",
"res/actions/fichier.png")
.AddParameter("file", _("File"))
.AddParameter("string", _("Group"))
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("scenevar", _("Scene variables"));
extension
.AddAction(
"LireFichierTxt",
_("Read a text"),
_("Read the text saved in the specified element and store it in a "
"variable.\nSpecify the structure leading to the element using / "
"(example : Root/Level/Current)\nSpaces are forbidden in element "
"names."),
_("Read _PARAM1_ from file _PARAM0_ and store as text in _PARAM3_"),
_("Storage"),
"res/actions/fichier24.png",
"res/actions/fichier.png")
.AddParameter("file", _("File"))
.AddParameter("string", _("Group"))
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("scenevar", _("Scene variables"));
extension.AddAction("DeleteGroupFichier",
_("Delete an element"),
_("This action deletes the specified element from the structured file.\nSpecify the structure leading to the element using / (example : Root/Level/Current)\nSpaces are forbidden in element names."),
_("Delete _PARAM1_ from the file _PARAM0_"),
_("Storage"),
"res/actions/delete24.png",
"res/actions/delete.png")
.AddParameter("file", _("Filename"))
.AddParameter("string", _("Group"))
.MarkAsAdvanced();
extension
.AddAction("DeleteGroupFichier",
_("Delete an element"),
_("This action deletes the specified element from the "
"structured file.\nSpecify the structure leading to the "
"element using / (example : Root/Level/Current)\nSpaces are "
"forbidden in element names."),
_("Delete _PARAM1_ from the file _PARAM0_"),
_("Storage"),
"res/actions/delete24.png",
"res/actions/delete.png")
.AddParameter("file", _("Filename"))
.AddParameter("string", _("Group"))
.MarkAsAdvanced();
extension.AddAction("DeleteFichier",
_("Delete a file"),
_("Delete the file."),
_("Delete the file _PARAM0_"),
_("Files"),
"res/actions/delete24.png",
"res/actions/delete.png")
.AddParameter("file", _("Filename"));
extension
.AddAction("DeleteFichier",
_("Delete a file"),
_("Delete the file."),
_("Delete the file _PARAM0_"),
_("Files"),
"res/actions/delete24.png",
"res/actions/delete.png")
.AddParameter("file", _("Filename"));
extension.AddCondition("FileExists",
_("A file exists"),
_("Test if the file exists."),
_("File _PARAM0_ exists"),
_("Files"),
"res/conditions/fichier24.png",
"res/conditions/fichier.png")
.AddParameter("file", _("Filename"))
.MarkAsAdvanced();
extension
.AddCondition("FileExists",
_("A file exists"),
_("Test if the file exists."),
_("File _PARAM0_ exists"),
_("Files"),
"res/conditions/fichier24.png",
"res/conditions/fichier.png")
.AddParameter("file", _("Filename"))
.MarkAsAdvanced();
extension.AddAction("LaunchFile",
_("Open a URL or a file"),
_("This action launches the specified file or URL, in a browser (or in a new tab if the game is using the Web platform and is launched inside a browser)."),
_("Open URL (or file) _PARAM0_"),
_("Files"),
"res/actions/launchFile24.png",
"res/actions/launchFile.png")
.AddParameter("string", _("URL (or filename)"))
.MarkAsAdvanced();
extension
.AddAction("LaunchFile",
_("Open a URL or a file"),
_("This action launches the specified file or URL, in a "
"browser (or in a new tab if the game is using the Web "
"platform and is launched inside a browser)."),
_("Open URL (or file) _PARAM0_"),
_("Files"),
"res/actions/launchFile24.png",
"res/actions/launchFile.png")
.AddParameter("string", _("URL (or filename)"))
.MarkAsAdvanced();
extension.AddAction("ExecuteCmd",
_("Execute a command"),
_("This action executes the specified command."),
_("Execute _PARAM0_"),
_("Files"),
"res/actions/launchFile24.png",
"res/actions/launchFile.png")
.AddParameter("string", _("Command"))
.MarkAsAdvanced();
#endif
extension
.AddAction("ExecuteCmd",
_("Execute a command"),
_("This action executes the specified command."),
_("Execute _PARAM0_"),
_("Files"),
"res/actions/launchFile24.png",
"res/actions/launchFile.png")
.AddParameter("string", _("Command"))
.MarkAsAdvanced();
#endif
}
}
} // namespace gd

View File

@@ -1,72 +1,78 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "AllBuiltinExtensions.h"
#include "GDCore/Tools/Localization.h"
using namespace std;
namespace gd
{
namespace gd {
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsJoystickExtension(gd::PlatformExtension & extension)
{
extension.SetExtensionInformation("BuiltinJoystick",
_("Joysticks features"),
_("Built-in extension that enables the use of joysticks"),
"Florian Rival",
"Open source (MIT License)");
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsJoystickExtension(
gd::PlatformExtension& extension) {
extension.SetExtensionInformation(
"BuiltinJoystick",
_("Joysticks features"),
_("Built-in extension that enables the use of joysticks"),
"Florian Rival",
"Open source (MIT License)");
#if defined(GD_IDE_ONLY)
extension.AddCondition("JoystickButtonDown",
_("A button on a joystick is pressed"),
_("Test if a button on a joystick is pressed."),
_("The button _PARAM2_ of joystick _PARAM1_ is pressed"),
_("Joystick"),
"res/conditions/joystick24.png",
"res/conditions/joystick.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Joystick number (first joystick: 0)"))
.AddParameter("expression", _("Button"));
#if defined(GD_IDE_ONLY)
extension
.AddCondition("JoystickButtonDown",
_("A button on a joystick is pressed"),
_("Test if a button on a joystick is pressed."),
_("The button _PARAM2_ of joystick _PARAM1_ is pressed"),
_("Joystick"),
"res/conditions/joystick24.png",
"res/conditions/joystick.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Joystick number (first joystick: 0)"))
.AddParameter("expression", _("Button"));
extension.AddCondition("JoystickAxis",
_("Value of an axis of a joystick"),
_("Test the value of an axis of a joystick."),
_("The value of the axis _PARAM2_ of joystick _PARAM1_ is _PARAM3__PARAM4_"),
_("Joystick"),
"res/conditions/joystick24.png",
"res/conditions/joystick.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Joystick number (first joystick: 0)"))
.AddParameter("joyaxis", _("Axis"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.SetManipulatedType("number");
extension
.AddCondition("JoystickAxis",
_("Value of an axis of a joystick"),
_("Test the value of an axis of a joystick."),
_("The value of the axis _PARAM2_ of joystick _PARAM1_ is "
"_PARAM3__PARAM4_"),
_("Joystick"),
"res/conditions/joystick24.png",
"res/conditions/joystick.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Joystick number (first joystick: 0)"))
.AddParameter("joyaxis", _("Axis"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.SetManipulatedType("number");
extension.AddAction("GetJoystickAxis",
_("Get the value of the axis of a joystick"),
_("Save the value of the axis of the joystick (from -100 to 100)."),
_("Save in _PARAM3_ the value of axis _PARAM2_ of joystick _PARAM1_"),
_("Joystick"),
"res/actions/joystick24.png",
"res/actions/joystick.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Joystick number (first joystick: 0)"))
.AddParameter("joyaxis", _("Axis"))
.AddParameter("scenevar", _("Save the result to the scene variable"))
.SetManipulatedType("number");
extension
.AddAction(
"GetJoystickAxis",
_("Get the value of the axis of a joystick"),
_("Save the value of the axis of the joystick (from -100 to 100)."),
_("Save in _PARAM3_ the value of axis _PARAM2_ of joystick _PARAM1_"),
_("Joystick"),
"res/actions/joystick24.png",
"res/actions/joystick.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Joystick number (first joystick: 0)"))
.AddParameter("joyaxis", _("Axis"))
.AddParameter("scenevar", _("Save the result to the scene variable"))
.SetManipulatedType("number");
extension.AddExpression("GetJoystickAxis",
_("Joystick axis"),
_("Value of an axis of a joystick"),
_("Joystick"),
"res/conditions/joystick.png")
extension
.AddExpression("GetJoystickAxis",
_("Joystick axis"),
_("Value of an axis of a joystick"),
_("Joystick"),
"res/conditions/joystick.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Joystick number (first joystick: 0)"))
.AddParameter("joyaxis", _("Axis"));
#endif
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Joystick number (first joystick: 0)"))
.AddParameter("joyaxis", _("Axis"));
#endif
}
}
} // namespace gd

View File

@@ -1,82 +1,91 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "AllBuiltinExtensions.h"
#include "GDCore/Tools/Localization.h"
using namespace std;
namespace gd
{
namespace gd {
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsKeyboardExtension(gd::PlatformExtension & extension)
{
extension.SetExtensionInformation("BuiltinKeyboard",
_("Keyboard features"),
_("Built-in extension that enables the use of a keyboard"),
"Florian Rival",
"Open source (MIT License)");
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsKeyboardExtension(
gd::PlatformExtension& extension) {
extension.SetExtensionInformation(
"BuiltinKeyboard",
_("Keyboard features"),
_("Built-in extension that enables the use of a keyboard"),
"Florian Rival",
"Open source (MIT License)");
#if defined(GD_IDE_ONLY)
extension.AddCondition("KeyPressed",
_("Key pressed"),
_("Test if a key is pressed"),
_("_PARAM1_ key is pressed"),
_("Keyboard"),
"res/conditions/keyboard24.png",
"res/conditions/keyboard.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("key", _("Key"));
#if defined(GD_IDE_ONLY)
extension
.AddCondition("KeyPressed",
_("Key pressed"),
_("Test if a key is pressed"),
_("_PARAM1_ key is pressed"),
_("Keyboard"),
"res/conditions/keyboard24.png",
"res/conditions/keyboard.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("key", _("Key"));
extension.AddCondition("KeyReleased",
_("Key released"),
_("Test if a key was just released"),
_("_PARAM1_ key is released"),
_("Keyboard"),
"res/conditions/keyboard24.png",
"res/conditions/keyboard.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("key", _("Key"));
extension
.AddCondition("KeyReleased",
_("Key released"),
_("Test if a key was just released"),
_("_PARAM1_ key is released"),
_("Keyboard"),
"res/conditions/keyboard24.png",
"res/conditions/keyboard.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("key", _("Key"));
extension.AddCondition("KeyFromTextPressed",
_("Key pressed (text expression)"),
_("Test if a key, retrieved from the result of the expression, is pressed"),
_("_PARAM1_ key is pressed"),
_("Keyboard"),
"res/conditions/keyboard24.png",
"res/conditions/keyboard.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Expression generating the key to test"))
.MarkAsAdvanced();
extension
.AddCondition("KeyFromTextPressed",
_("Key pressed (text expression)"),
_("Test if a key, retrieved from the result of the "
"expression, is pressed"),
_("_PARAM1_ key is pressed"),
_("Keyboard"),
"res/conditions/keyboard24.png",
"res/conditions/keyboard.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Expression generating the key to test"))
.MarkAsAdvanced();
extension.AddCondition("KeyFromTextReleased",
_("Key released (text expression)"),
_("Test if a key, retrieved from the result of the expression, was just released"),
_("_PARAM1_ key is released"),
_("Keyboard"),
"res/conditions/keyboard24.png",
"res/conditions/keyboard.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Expression generating the key to test"))
.MarkAsAdvanced();
extension
.AddCondition("KeyFromTextReleased",
_("Key released (text expression)"),
_("Test if a key, retrieved from the result of the "
"expression, was just released"),
_("_PARAM1_ key is released"),
_("Keyboard"),
"res/conditions/keyboard24.png",
"res/conditions/keyboard.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Expression generating the key to test"))
.MarkAsAdvanced();
extension.AddCondition("AnyKeyPressed",
_("Any key pressed"),
_("Test if any key is pressed"),
_("Any key is pressed"),
_("Keyboard"),
"res/conditions/keyboard24.png",
"res/conditions/keyboard.png")
.AddCodeOnlyParameter("currentScene", "");
extension
.AddCondition("AnyKeyPressed",
_("Any key pressed"),
_("Test if any key is pressed"),
_("Any key is pressed"),
_("Keyboard"),
"res/conditions/keyboard24.png",
"res/conditions/keyboard.png")
.AddCodeOnlyParameter("currentScene", "");
extension.AddStrExpression("LastPressedKey",
_("Last pressed key"),
_("Get the name of the latest key pressed on the keyboard"),
_("Keyboard"),
"res/conditions/keyboard.png")
.AddCodeOnlyParameter("currentScene", "");
#endif
extension
.AddStrExpression(
"LastPressedKey",
_("Last pressed key"),
_("Get the name of the latest key pressed on the keyboard"),
_("Keyboard"),
"res/conditions/keyboard.png")
.AddCodeOnlyParameter("currentScene", "");
#endif
}
}
} // namespace gd

View File

@@ -1,185 +1,343 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "AllBuiltinExtensions.h"
#include "GDCore/Tools/Localization.h"
using namespace std;
namespace gd
{
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsMathematicalToolsExtension(gd::PlatformExtension & extension)
{
extension.SetExtensionInformation("BuiltinMathematicalTools",
_("Mathematical tools"),
_("Built-in extension providing mathematical tools"),
"Florian Rival",
"Open source (MIT License)");
#if defined(GD_IDE_ONLY)
extension.AddExpression("AngleDifference", _("Difference between two angles"), _("Difference between two angles"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("First angle"))
.AddParameter("expression", _("Second angle"));
extension.AddExpression("mod", _("Modulo"), _("x mod y"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("x (as in x mod y)"))
.AddParameter("expression", _("y (as in x mod y)"));
extension.AddExpression("min", _("Minimum of two numbers"), _("Minimum of two numbers"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("First expression"))
.AddParameter("expression", _("Second expression"));
extension.AddExpression("max", _("Maximum of two numbers"), _("Maximum of two numbers"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("First expression"))
.AddParameter("expression", _("Second expression"));
extension.AddExpression("abs", _("Absolute value"), _("Absolute value"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("acos", _("Arccosine"), _("Arccosine"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("acosh", _("Hyperbolic arccosine"), _("Hyperbolic arccosine"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("asin", _("Arcsine"), _("Arcsine"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("asinh", _("Arcsine"), _("Arcsine"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("atan", _("Arctangent"), _("Arctangent"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("atan2", _("2 argument arctangent"), _("2 argument arctangent (atan2)"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Y"))
.AddParameter("expression", _("X"));
extension.AddExpression("atanh", _("Hyperbolic arctangent"), _("Hyperbolic arctangent"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("cbrt", _("Cube root"), _("Cube root"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("ceil", _("Ceil (round up)"), _("Round number up to an integer"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("floor", _("Floor (round down)"), _("Round number down to an integer"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("cos", _("Cosine"), _("Cosine of a number"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("cosh", _("Hyperbolic cosine"), _("Hyperbolic cosine"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("cot", _("Cotangent"), _("Cotangent of a number"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("csc", _("Cosecant"), _("Cosecant of a number"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("int", _("Round"), _("Round a number"), _("Mathematical tools"), "res/mathfunction.png")
.SetHidden()
.AddParameter("expression", _("Expression"));
extension.AddExpression("rint", _("Round"), _("Round a number"), _("Mathematical tools"), "res/mathfunction.png")
.SetHidden()
.AddParameter("expression", _("Expression"));
extension.AddExpression("round", _("Round"), _("Round a number"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("exp", _("Exponential"), _("Exponential of a number"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("log", _("Logarithm"), _("Logarithm"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("ln", _("Logarithm"), _("Logarithm"), _("Mathematical tools"), "res/mathfunction.png")
.SetHidden()
.AddParameter("expression", _("Expression"));
extension.AddExpression("log2", _("Base-2 logarithm"), _("Base 2 Logarithm"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("log10", _("Base-10 logarithm"), _("Base-10 logarithm"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("nthroot", _("Nth root"), _("Nth root of a number"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Number"))
.AddParameter("expression", _("N"));
extension.AddExpression("pow", _("Power"), _("Raise a number to power n"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Number"))
.AddParameter("expression", _("The exponent (n in x^n)"));
extension.AddExpression("sec", _("Secant"), _("Secant"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("sign", _("Sign of a number"), _("Return the sign of a number (1,-1 or 0)"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("sin", _("Sine"), _("Sine of a number"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("sinh", _("Hyperbolic sine"), _("Hyperbolic sine"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("sqrt", _("Square root"), _("Square root of a number"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("tan", _("Tangent"), _("Tangent of a number"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("tanh", _("Hyperbolic tangent"), _("Hyperbolic tangent"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("trunc", _("Truncation"), _("Troncate a number"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension.AddExpression("lerp", _("Lerp (Linear interpolation)"), _("Linearly interpolate a to b by x"), _("Mathematical tools"), "res/mathfunction.png")
.AddParameter("expression", _("a (in a+(b-a)*x)"))
.AddParameter("expression", _("b (in a+(b-a)*x)"))
.AddParameter("expression", _("x (in a+(b-a)*x)"));
#endif
namespace gd {
void GD_CORE_API
BuiltinExtensionsImplementer::ImplementsMathematicalToolsExtension(
gd::PlatformExtension& extension) {
extension.SetExtensionInformation(
"BuiltinMathematicalTools",
_("Mathematical tools"),
_("Built-in extension providing mathematical tools"),
"Florian Rival",
"Open source (MIT License)");
#if defined(GD_IDE_ONLY)
extension
.AddExpression("AngleDifference",
_("Difference between two angles"),
_("Difference between two angles"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("First angle"))
.AddParameter("expression", _("Second angle"));
extension
.AddExpression("mod",
_("Modulo"),
_("x mod y"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("x (as in x mod y)"))
.AddParameter("expression", _("y (as in x mod y)"));
extension
.AddExpression("min",
_("Minimum of two numbers"),
_("Minimum of two numbers"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("First expression"))
.AddParameter("expression", _("Second expression"));
extension
.AddExpression("max",
_("Maximum of two numbers"),
_("Maximum of two numbers"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("First expression"))
.AddParameter("expression", _("Second expression"));
extension
.AddExpression("abs",
_("Absolute value"),
_("Absolute value"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("acos",
_("Arccosine"),
_("Arccosine"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("acosh",
_("Hyperbolic arccosine"),
_("Hyperbolic arccosine"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("asin",
_("Arcsine"),
_("Arcsine"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("asinh",
_("Arcsine"),
_("Arcsine"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("atan",
_("Arctangent"),
_("Arctangent"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("atan2",
_("2 argument arctangent"),
_("2 argument arctangent (atan2)"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Y"))
.AddParameter("expression", _("X"));
extension
.AddExpression("atanh",
_("Hyperbolic arctangent"),
_("Hyperbolic arctangent"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("cbrt",
_("Cube root"),
_("Cube root"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("ceil",
_("Ceil (round up)"),
_("Round number up to an integer"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("floor",
_("Floor (round down)"),
_("Round number down to an integer"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("cos",
_("Cosine"),
_("Cosine of a number"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("cosh",
_("Hyperbolic cosine"),
_("Hyperbolic cosine"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("cot",
_("Cotangent"),
_("Cotangent of a number"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("csc",
_("Cosecant"),
_("Cosecant of a number"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("int",
_("Round"),
_("Round a number"),
_("Mathematical tools"),
"res/mathfunction.png")
.SetHidden()
.AddParameter("expression", _("Expression"));
extension
.AddExpression("rint",
_("Round"),
_("Round a number"),
_("Mathematical tools"),
"res/mathfunction.png")
.SetHidden()
.AddParameter("expression", _("Expression"));
extension
.AddExpression("round",
_("Round"),
_("Round a number"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("exp",
_("Exponential"),
_("Exponential of a number"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("log",
_("Logarithm"),
_("Logarithm"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("ln",
_("Logarithm"),
_("Logarithm"),
_("Mathematical tools"),
"res/mathfunction.png")
.SetHidden()
.AddParameter("expression", _("Expression"));
extension
.AddExpression("log2",
_("Base-2 logarithm"),
_("Base 2 Logarithm"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("log10",
_("Base-10 logarithm"),
_("Base-10 logarithm"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("nthroot",
_("Nth root"),
_("Nth root of a number"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Number"))
.AddParameter("expression", _("N"));
extension
.AddExpression("pow",
_("Power"),
_("Raise a number to power n"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Number"))
.AddParameter("expression", _("The exponent (n in x^n)"));
extension
.AddExpression("sec",
_("Secant"),
_("Secant"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("sign",
_("Sign of a number"),
_("Return the sign of a number (1,-1 or 0)"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("sin",
_("Sine"),
_("Sine of a number"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("sinh",
_("Hyperbolic sine"),
_("Hyperbolic sine"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("sqrt",
_("Square root"),
_("Square root of a number"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("tan",
_("Tangent"),
_("Tangent of a number"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("tanh",
_("Hyperbolic tangent"),
_("Hyperbolic tangent"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("trunc",
_("Truncation"),
_("Troncate a number"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("Expression"));
extension
.AddExpression("lerp",
_("Lerp (Linear interpolation)"),
_("Linearly interpolate a to b by x"),
_("Mathematical tools"),
"res/mathfunction.png")
.AddParameter("expression", _("a (in a+(b-a)*x)"))
.AddParameter("expression", _("b (in a+(b-a)*x)"))
.AddParameter("expression", _("x (in a+(b-a)*x)"));
#endif
}
}
} // namespace gd

View File

@@ -1,260 +1,362 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "AllBuiltinExtensions.h"
#include "GDCore/Tools/Localization.h"
using namespace std;
namespace gd
{
namespace gd {
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsMouseExtension(gd::PlatformExtension & extension)
{
extension.SetExtensionInformation("BuiltinMouse",
_("Mouse features"),
_("Built-in extension that enables the use of a mouse"),
"Florian Rival",
"Open source (MIT License)");
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsMouseExtension(
gd::PlatformExtension& extension) {
extension.SetExtensionInformation(
"BuiltinMouse",
_("Mouse features"),
_("Built-in extension that enables the use of a mouse"),
"Florian Rival",
"Open source (MIT License)");
#if defined(GD_IDE_ONLY)
extension.AddCondition("SourisSurObjet",
_("The cursor/touch is on an object"),
_("Test if the cursor is over an object, or if the object is being touched."),
_("The cursor/touch is on _PARAM0_"),
_("Mouse and touch"),
"res/conditions/surObjet24.png",
"res/conditions/surObjet.png")
#if defined(GD_IDE_ONLY)
extension
.AddCondition("SourisSurObjet",
_("The cursor/touch is on an object"),
_("Test if the cursor is over an object, or if the object "
"is being touched."),
_("The cursor/touch is on _PARAM0_"),
_("Mouse and touch"),
"res/conditions/surObjet24.png",
"res/conditions/surObjet.png")
.AddParameter("objectList", _("Object"))
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("yesorno", _("Accurate test (yes by default)"), "", true).SetDefaultValue("yes")
.AddCodeOnlyParameter("conditionInverted", "")
.MarkAsSimple();
.AddParameter("objectList", _("Object"))
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("yesorno", _("Accurate test (yes by default)"), "", true)
.SetDefaultValue("yes")
.AddCodeOnlyParameter("conditionInverted", "")
.MarkAsSimple();
extension.AddAction("TouchSimulateMouse",
_("De/activate moving the mouse cursor with touches"),
_("When activated, any touch made on a touchscreen will also move the mouse cursor. When deactivated, mouse and touch positions will be completely independent.\nBy default, this is activated so that you can simply use the mouse conditions to also support touchscreens. If you want to have multitouch and differentiate mouse movement and touches, just deactivate it with this action."),
_("Move mouse cursor when touching screen: _PARAM1_"),
_("Mouse and touch"),
"res/conditions/touch24.png",
"res/conditions/touch.png")
extension
.AddAction(
"TouchSimulateMouse",
_("De/activate moving the mouse cursor with touches"),
_("When activated, any touch made on a touchscreen will also move "
"the mouse cursor. When deactivated, mouse and touch positions "
"will be completely independent.\nBy default, this is activated so "
"that you can simply use the mouse conditions to also support "
"touchscreens. If you want to have multitouch and differentiate "
"mouse movement and touches, just deactivate it with this action."),
_("Move mouse cursor when touching screen: _PARAM1_"),
_("Mouse and touch"),
"res/conditions/touch24.png",
"res/conditions/touch.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("yesorno", _("Activate (yes by default when game is launched)")).SetDefaultValue("yes")
.MarkAsAdvanced();
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("yesorno",
_("Activate (yes by default when game is launched)"))
.SetDefaultValue("yes")
.MarkAsAdvanced();
extension.AddAction("CentreSourisX",
_("Center cursor horizontally"),
_("Put the cursor in the middle of the screen horizontally."),
_("Center cursor horizontally"),
_("Mouse and touch"),
"res/actions/mouse24.png",
"res/actions/mouse.png")
extension
.AddAction("CentreSourisX",
_("Center cursor horizontally"),
_("Put the cursor in the middle of the screen horizontally."),
_("Center cursor horizontally"),
_("Mouse and touch"),
"res/actions/mouse24.png",
"res/actions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.MarkAsAdvanced();
.AddCodeOnlyParameter("currentScene", "")
.MarkAsAdvanced();
extension.AddAction("CentreSourisY",
_("Center cursor vertically"),
_("Put the cursor in the middle of the screen vertically."),
_("Center cursor vertically"),
_("Mouse and touch"),
"res/actions/mouse24.png",
"res/actions/mouse.png")
extension
.AddAction("CentreSourisY",
_("Center cursor vertically"),
_("Put the cursor in the middle of the screen vertically."),
_("Center cursor vertically"),
_("Mouse and touch"),
"res/actions/mouse24.png",
"res/actions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.MarkAsAdvanced();
.AddCodeOnlyParameter("currentScene", "")
.MarkAsAdvanced();
extension.AddAction("CacheSouris",
_("Hide the cursor"),
_("Hide the cursor."),
_("Hide the cursor"),
_("Mouse and touch"),
"res/actions/mouse24.png",
"res/actions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.MarkAsAdvanced();
extension
.AddAction("CacheSouris",
_("Hide the cursor"),
_("Hide the cursor."),
_("Hide the cursor"),
_("Mouse and touch"),
"res/actions/mouse24.png",
"res/actions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.MarkAsAdvanced();
extension.AddAction("MontreSouris",
_("Show the cursor"),
_("Show the cursor."),
_("Show the cursor"),
_("Mouse and touch"),
"res/actions/mouse24.png",
"res/actions/mouse.png")
extension
.AddAction("MontreSouris",
_("Show the cursor"),
_("Show the cursor."),
_("Show the cursor"),
_("Mouse and touch"),
"res/actions/mouse24.png",
"res/actions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.MarkAsAdvanced();
.AddCodeOnlyParameter("currentScene", "")
.MarkAsAdvanced();
extension.AddAction("SetSourisXY",
_("Position the cursor of the mouse"),
_("Position the cursor at the given coordinates."),
_("Position cursor at _PARAM1_;_PARAM2_"),
_("Mouse and touch"),
"res/actions/mouse24.png",
"res/actions/mouse.png")
extension
.AddAction("SetSourisXY",
_("Position the cursor of the mouse"),
_("Position the cursor at the given coordinates."),
_("Position cursor at _PARAM1_;_PARAM2_"),
_("Mouse and touch"),
"res/actions/mouse24.png",
"res/actions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("X position"))
.AddParameter("expression", _("Y position"))
.MarkAsAdvanced();
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("X position"))
.AddParameter("expression", _("Y position"))
.MarkAsAdvanced();
extension.AddAction("CentreSouris",
_("Center the cursor"),
_("Center the cursor on the screen."),
_("Center the cursor"),
_("Mouse and touch"),
"res/actions/mouse24.png",
"res/actions/mouse.png")
extension
.AddAction("CentreSouris",
_("Center the cursor"),
_("Center the cursor on the screen."),
_("Center the cursor"),
_("Mouse and touch"),
"res/actions/mouse24.png",
"res/actions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.MarkAsAdvanced();
.AddCodeOnlyParameter("currentScene", "")
.MarkAsAdvanced();
extension.AddCondition("SourisX",
_("Cursor X position"),
_("Compare the X position of the cursor or of a touch."),
_("Cursor X position is _PARAM1__PARAM2_"),
_("Mouse and touch"),
"res/conditions/mouse24.png",
"res/conditions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("X position"))
.AddParameter("layer", _("Layer (base layer if empty)"), "", true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true).SetDefaultValue("0")
.SetManipulatedType("number");
extension
.AddCondition("SourisX",
_("Cursor X position"),
_("Compare the X position of the cursor or of a touch."),
_("Cursor X position is _PARAM1__PARAM2_"),
_("Mouse and touch"),
"res/conditions/mouse24.png",
"res/conditions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("X position"))
.AddParameter("layer", _("Layer (base layer if empty)"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true)
.SetDefaultValue("0")
.SetManipulatedType("number");
extension.AddCondition("SourisY",
_("Cursor Y position"),
_("Compare the Y position of the cursor or of a touch."),
_("Cursor Y position is _PARAM1__PARAM2_"),
_("Mouse and touch"),
"res/conditions/mouse24.png",
"res/conditions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Y position"))
.AddParameter("layer", _("Layer (base layer if empty)"), "", true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true).SetDefaultValue("0")
.SetManipulatedType("number");
extension
.AddCondition("SourisY",
_("Cursor Y position"),
_("Compare the Y position of the cursor or of a touch."),
_("Cursor Y position is _PARAM1__PARAM2_"),
_("Mouse and touch"),
"res/conditions/mouse24.png",
"res/conditions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Y position"))
.AddParameter("layer", _("Layer (base layer if empty)"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true)
.SetDefaultValue("0")
.SetManipulatedType("number");
extension.AddCondition("SourisBouton",
_("Mouse button pressed or touch held"),
_("Return true if the specified mouse button is pressed or if a touch is in contact with the screen."),
_("Touch or _PARAM1_ mouse button is down"),
_("Mouse and touch"),
"res/conditions/mouse24.png",
"res/conditions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("mouse", _("Button to test"))
.MarkAsSimple();
extension
.AddCondition("SourisBouton",
_("Mouse button pressed or touch held"),
_("Return true if the specified mouse button is pressed or "
"if a touch is in contact with the screen."),
_("Touch or _PARAM1_ mouse button is down"),
_("Mouse and touch"),
"res/conditions/mouse24.png",
"res/conditions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("mouse", _("Button to test"))
.MarkAsSimple();
extension.AddCondition("MouseButtonReleased",
_("Mouse button released"),
_("Return true if the specified mouse button was released."),
_("_PARAM1_ mouse button was released"),
_("Mouse and touch"),
"res/conditions/mouse24.png",
"res/conditions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("mouse", _("Button to test"))
.MarkAsSimple();
extension
.AddCondition(
"MouseButtonReleased",
_("Mouse button released"),
_("Return true if the specified mouse button was released."),
_("_PARAM1_ mouse button was released"),
_("Mouse and touch"),
"res/conditions/mouse24.png",
"res/conditions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("mouse", _("Button to test"))
.MarkAsSimple();
extension.AddCondition("TouchX",
_("Touch X position"),
_("Compare the X position of a specific touch."),
_("Touch #_PARAM1_ X position is _PARAM2__PARAM3_"),
_("Mouse and touch/Multitouch"),
"res/conditions/touch24.png",
"res/conditions/touch.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Touch identifier"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("X position"))
.AddParameter("layer", _("Layer (base layer if empty)"), "", true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true).SetDefaultValue("0")
.SetManipulatedType("number");
extension
.AddCondition("TouchX",
_("Touch X position"),
_("Compare the X position of a specific touch."),
_("Touch #_PARAM1_ X position is _PARAM2__PARAM3_"),
_("Mouse and touch/Multitouch"),
"res/conditions/touch24.png",
"res/conditions/touch.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Touch identifier"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("X position"))
.AddParameter("layer", _("Layer (base layer if empty)"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true)
.SetDefaultValue("0")
.SetManipulatedType("number");
extension.AddCondition("TouchY",
_("Touch Y position"),
_("Compare the Y position of a specific touch."),
_("Touch #_PARAM1_ Y position is _PARAM2__PARAM3_"),
_("Mouse and touch/Multitouch"),
"res/conditions/touch24.png",
"res/conditions/touch.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Touch identifier"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("X position"))
.AddParameter("layer", _("Layer (base layer if empty)"), "", true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true).SetDefaultValue("0")
.SetManipulatedType("number");
extension
.AddCondition("TouchY",
_("Touch Y position"),
_("Compare the Y position of a specific touch."),
_("Touch #_PARAM1_ Y position is _PARAM2__PARAM3_"),
_("Mouse and touch/Multitouch"),
"res/conditions/touch24.png",
"res/conditions/touch.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Touch identifier"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("X position"))
.AddParameter("layer", _("Layer (base layer if empty)"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true)
.SetDefaultValue("0")
.SetManipulatedType("number");
extension.AddCondition("PopStartedTouch",
_("A new touch has started"),
_("Return true if a touch has started. The touch identifier can be accessed using LastTouchId().\nAs more than one touch can be started, this condition is only true once for each touch: the next time you use it, it will be for a new touch, or it will return false if no more touches have just started."),
_("A new touch has started"),
_("Mouse and touch/Multitouch"),
"res/conditions/touch24.png",
"res/conditions/touch.png")
.AddCodeOnlyParameter("currentScene", "");
extension
.AddCondition(
"PopStartedTouch",
_("A new touch has started"),
_("Return true if a touch has started. The touch identifier can be "
"accessed using LastTouchId().\nAs more than one touch can be "
"started, this condition is only true once for each touch: the "
"next time you use it, it will be for a new touch, or it will "
"return false if no more touches have just started."),
_("A new touch has started"),
_("Mouse and touch/Multitouch"),
"res/conditions/touch24.png",
"res/conditions/touch.png")
.AddCodeOnlyParameter("currentScene", "");
extension.AddCondition("PopEndedTouch",
_("A touch has ended"),
_("Return true if a touch has ended. The touch identifier can be accessed using LastEndedTouchId().\nAs more than one touch can be ended, this condition is only true once for each touch: the next time you use it, it will be for a new touch, or it will return false if no more touches have just ended."),
_("A touch has ended"),
_("Mouse and touch/Multitouch"),
"res/conditions/touch24.png",
"res/conditions/touch.png")
.AddCodeOnlyParameter("currentScene", "");
extension
.AddCondition(
"PopEndedTouch",
_("A touch has ended"),
_("Return true if a touch has ended. The touch identifier can be "
"accessed using LastEndedTouchId().\nAs more than one touch can be "
"ended, this condition is only true once for each touch: the next "
"time you use it, it will be for a new touch, or it will return "
"false if no more touches have just ended."),
_("A touch has ended"),
_("Mouse and touch/Multitouch"),
"res/conditions/touch24.png",
"res/conditions/touch.png")
.AddCodeOnlyParameter("currentScene", "");
extension.AddExpression("MouseX", _("Cursor X position"), _("Cursor X position"), _("Mouse cursor"), "res/actions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "", true).SetDefaultValue("\"\"")
.AddParameter("camera", _("Camera"), "", true).SetDefaultValue("0");
extension
.AddExpression("MouseX",
_("Cursor X position"),
_("Cursor X position"),
_("Mouse cursor"),
"res/actions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("camera", _("Camera"), "", true)
.SetDefaultValue("0");
extension.AddExpression("SourisX", _("Cursor X position"), _("Cursor X position"), _("Mouse cursor"), "res/actions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "", true).SetDefaultValue("\"\"")
.AddParameter("camera", _("Camera"), "", true).SetDefaultValue("0")
.SetHidden();
extension
.AddExpression("SourisX",
_("Cursor X position"),
_("Cursor X position"),
_("Mouse cursor"),
"res/actions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("camera", _("Camera"), "", true)
.SetDefaultValue("0")
.SetHidden();
extension.AddExpression("MouseY", _("Cursor Y position"), _("Cursor Y position"), _("Mouse cursor"), "res/actions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "", true).SetDefaultValue("\"\"")
.AddParameter("camera", _("Camera"), "", true).SetDefaultValue("0");
extension
.AddExpression("MouseY",
_("Cursor Y position"),
_("Cursor Y position"),
_("Mouse cursor"),
"res/actions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("camera", _("Camera"), "", true)
.SetDefaultValue("0");
extension
.AddExpression("SourisY",
_("Cursor Y position"),
_("Cursor Y position"),
_("Mouse cursor"),
"res/actions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("camera", _("Camera"), "", true)
.SetDefaultValue("0")
.SetHidden();
extension.AddExpression("SourisY", _("Cursor Y position"), _("Cursor Y position"), _("Mouse cursor"), "res/actions/mouse.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "", true).SetDefaultValue("\"\"")
.AddParameter("camera", _("Camera"), "", true).SetDefaultValue("0")
.SetHidden();
extension
.AddExpression("MouseWheelDelta",
_("Mouse wheel: Displacement"),
_("Mouse wheel displacement"),
_("Mouse cursor"),
"res/actions/mouse.png")
.AddCodeOnlyParameter("currentScene", "");
extension.AddExpression("MouseWheelDelta", _("Mouse wheel: Displacement"), _("Mouse wheel displacement"), _("Mouse cursor"), "res/actions/mouse.png")
.AddCodeOnlyParameter("currentScene", "");
extension
.AddExpression("TouchX",
_("Touch X position"),
_("Touch X position"),
_("Multitouch"),
"res/conditions/touch.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Touch identifier"))
.AddParameter("layer", _("Layer"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("camera", _("Camera"), "", true)
.SetDefaultValue("0");
extension.AddExpression("TouchX", _("Touch X position"), _("Touch X position"), _("Multitouch"), "res/conditions/touch.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Touch identifier"))
.AddParameter("layer", _("Layer"), "", true).SetDefaultValue("\"\"")
.AddParameter("camera", _("Camera"), "", true).SetDefaultValue("0");
extension
.AddExpression("TouchY",
_("Touch Y position"),
_("Touch Y position"),
_("Multitouch"),
"res/conditions/touch.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Touch identifier"))
.AddParameter("layer", _("Layer"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("camera", _("Camera"), "", true)
.SetDefaultValue("0");
extension.AddExpression("TouchY", _("Touch Y position"), _("Touch Y position"), _("Multitouch"), "res/conditions/touch.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Touch identifier"))
.AddParameter("layer", _("Layer"), "", true).SetDefaultValue("\"\"")
.AddParameter("camera", _("Camera"), "", true).SetDefaultValue("0");
extension
.AddExpression("LastTouchId",
_("Identifier of the last touch"),
_("Identifier of the last touch"),
_("Multitouch"),
"res/conditions/touch.png")
.AddCodeOnlyParameter("currentScene", "");
extension.AddExpression("LastTouchId", _("Identifier of the last touch"), _("Identifier of the last touch"), _("Multitouch"), "res/conditions/touch.png")
.AddCodeOnlyParameter("currentScene", "");
extension
.AddExpression("LastEndedTouchId",
_("Identifier of the last ended touch"),
_("Identifier of the last ended touch"),
_("Multitouch"),
"res/conditions/touch.png")
.AddCodeOnlyParameter("currentScene", "");
extension.AddExpression("LastEndedTouchId", _("Identifier of the last ended touch"), _("Identifier of the last ended touch"), _("Multitouch"), "res/conditions/touch.png")
.AddCodeOnlyParameter("currentScene", "");
#endif
#endif
}
}
} // namespace gd

View File

@@ -1,123 +1,159 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "AllBuiltinExtensions.h"
#include "GDCore/Tools/Localization.h"
using namespace std;
namespace gd
{
namespace gd {
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsNetworkExtension(gd::PlatformExtension & extension)
{
extension.SetExtensionInformation("BuiltinNetwork",
_("Basic internet features"),
_("Built-in extension providing network features."),
"Florian Rival",
"Open source (MIT License)");
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsNetworkExtension(
gd::PlatformExtension& extension) {
extension.SetExtensionInformation(
"BuiltinNetwork",
_("Basic internet features"),
_("Built-in extension providing network features."),
"Florian Rival",
"Open source (MIT License)");
#if defined(GD_IDE_ONLY)
extension.AddAction("EnvoiDataNet",
_("Send data to a website"),
_("Send data to a specified web site.\nYou need to set up a .php page on your web site to receive this data.\nEnter a password here, and enter the same password in the configuration of your .php page.\nRead the help file to get more information."),
_("Send to _PARAM0_ the following data : _PARAM2_, _PARAM3_,_PARAM4_,_PARAM5_,_PARAM6_,_PARAM7_"),
_("Network"),
"res/actions/net24.png",
"res/actions/net.png")
.AddParameter("string", _(".php page URL (don't forget the protocol http://)"))
.AddParameter("password", _("Password"))
.AddParameter("string", _("Data 1"))
.AddParameter("string", _("Data 2"), "", true)
.AddParameter("string", _("Data 3"), "", true)
.AddParameter("string", _("Data 4"), "", true)
.AddParameter("string", _("Data 5"), "", true)
.AddParameter("string", _("Data 6"), "", true)
.SetHidden();
#if defined(GD_IDE_ONLY)
extension
.AddAction(
"EnvoiDataNet",
_("Send data to a website"),
_("Send data to a specified web site.\nYou need to set up a .php "
"page on your web site to receive this data.\nEnter a password "
"here, and enter the same password in the configuration of your "
".php page.\nRead the help file to get more information."),
_("Send to _PARAM0_ the following data : _PARAM2_, "
"_PARAM3_,_PARAM4_,_PARAM5_,_PARAM6_,_PARAM7_"),
_("Network"),
"res/actions/net24.png",
"res/actions/net.png")
.AddParameter("string",
_(".php page URL (don't forget the protocol http://)"))
.AddParameter("password", _("Password"))
.AddParameter("string", _("Data 1"))
.AddParameter("string", _("Data 2"), "", true)
.AddParameter("string", _("Data 3"), "", true)
.AddParameter("string", _("Data 4"), "", true)
.AddParameter("string", _("Data 5"), "", true)
.AddParameter("string", _("Data 6"), "", true)
.SetHidden();
extension.AddAction("SendRequest",
_("Send a request to a web page"),
_("Send a request to the specified web page.\n\nPlease note that for the web platform games, the game must be hosted on the same host as specified below, except if the server is configured to answer to all requests (cross-domain requests)."),
_("Send _PARAM3_ request to _PARAM0__PARAM1_ with body: _PARAM2_"),
_("Network"),
"res/actions/net24.png",
"res/actions/net.png")
.AddParameter("string", _("Host (example: http://www.some-server.org/)"))
.AddParameter("string", _("Path to page (Example: /page.php)"))
.AddParameter("string", _("Request body content"))
.AddParameter("string", _("Method: \"POST\" or \"GET\" (if empty, GET will be used)"), "", true ).SetDefaultValue("\"GET\"")
.AddParameter("string", _("Content type (application/x-www-form-urlencoded by default)"), "", true )
.AddParameter("scenevar", _("Store the response in this variable"), "", true )
.MarkAsComplex();
extension
.AddAction(
"SendRequest",
_("Send a request to a web page"),
_("Send a request to the specified web page.\n\nPlease note that for "
"the web platform games, the game must be hosted on the same host "
"as specified below, except if the server is configured to answer "
"to all requests (cross-domain requests)."),
_("Send _PARAM3_ request to _PARAM0__PARAM1_ with body: _PARAM2_"),
_("Network"),
"res/actions/net24.png",
"res/actions/net.png")
.AddParameter("string", _("Host (example: http://www.some-server.org/)"))
.AddParameter("string", _("Path to page (Example: /page.php)"))
.AddParameter("string", _("Request body content"))
.AddParameter(
"string",
_("Method: \"POST\" or \"GET\" (if empty, GET will be used)"),
"",
true)
.SetDefaultValue("\"GET\"")
.AddParameter(
"string",
_("Content type (application/x-www-form-urlencoded by default)"),
"",
true)
.AddParameter(
"scenevar", _("Store the response in this variable"), "", true)
.MarkAsComplex();
extension.AddAction("DownloadFile",
_("Download a file"),
_("Download a file from a web site"),
_("Download file _PARAM1_ from _PARAM0_ under the name of _PARAM2_"),
_("Network"),
"res/actions/net24.png",
"res/actions/net.png")
.AddParameter("string", _("Host (for example : http://www.website.com)"))
.AddParameter("string", _("Path to file (for example : /folder/file.txt)"))
.AddParameter("string", _("Save as"));
extension
.AddAction(
"DownloadFile",
_("Download a file"),
_("Download a file from a web site"),
_("Download file _PARAM1_ from _PARAM0_ under the name of _PARAM2_"),
_("Network"),
"res/actions/net24.png",
"res/actions/net.png")
.AddParameter("string", _("Host (for example : http://www.website.com)"))
.AddParameter("string",
_("Path to file (for example : /folder/file.txt)"))
.AddParameter("string", _("Save as"));
extension.AddAction("JSONToVariableStructure",
_("Convert JSON to a variable"),
_("Parse a JSON object and store it into a variable"),
_("Parse JSON string _PARAM0_ and store it into variable _PARAM1_"),
_("Network"),
"res/actions/net24.png",
"res/actions/net.png")
.AddParameter("string", _("JSON string"))
.AddParameter("scenevar", _("Variable where store the JSON object"))
.MarkAsAdvanced();
extension
.AddAction(
"JSONToVariableStructure",
_("Convert JSON to a variable"),
_("Parse a JSON object and store it into a variable"),
_("Parse JSON string _PARAM0_ and store it into variable _PARAM1_"),
_("Network"),
"res/actions/net24.png",
"res/actions/net.png")
.AddParameter("string", _("JSON string"))
.AddParameter("scenevar", _("Variable where store the JSON object"))
.MarkAsAdvanced();
extension.AddAction("JSONToGlobalVariableStructure",
_("Convert JSON to global variable"),
_("Parse a JSON object and store it into a global variable"),
_("Parse JSON string _PARAM0_ and store it into global variable _PARAM1_"),
_("Network"),
"res/actions/net24.png",
"res/actions/net.png")
.AddParameter("string", _("JSON string"))
.AddParameter("globalvar", _("Global variable where store the JSON object"))
.MarkAsAdvanced();
extension
.AddAction("JSONToGlobalVariableStructure",
_("Convert JSON to global variable"),
_("Parse a JSON object and store it into a global variable"),
_("Parse JSON string _PARAM0_ and store it into global "
"variable _PARAM1_"),
_("Network"),
"res/actions/net24.png",
"res/actions/net.png")
.AddParameter("string", _("JSON string"))
.AddParameter("globalvar",
_("Global variable where store the JSON object"))
.MarkAsAdvanced();
extension.AddAction("JSONToObjectVariableStructure",
_("Convert JSON to object variable"),
_("Parse a JSON object and store it into an object variable"),
_("Parse JSON string _PARAM0_ and store it into variable _PARAM2_ of _PARAM1_"),
_("Network"),
"res/actions/net24.png",
"res/actions/net.png")
.AddParameter("string", _("JSON string"))
.AddParameter("objectPtr", _("Object"))
.AddParameter("objectvar", _("Object variable where store the JSON object"))
.MarkAsAdvanced();
extension
.AddAction("JSONToObjectVariableStructure",
_("Convert JSON to object variable"),
_("Parse a JSON object and store it into an object variable"),
_("Parse JSON string _PARAM0_ and store it into variable "
"_PARAM2_ of _PARAM1_"),
_("Network"),
"res/actions/net24.png",
"res/actions/net.png")
.AddParameter("string", _("JSON string"))
.AddParameter("objectPtr", _("Object"))
.AddParameter("objectvar",
_("Object variable where store the JSON object"))
.MarkAsAdvanced();
extension.AddStrExpression("ToJSON",
_("Convert variable to JSON"),
_("Convert a variable to JSON"),
_("Conversion"),
"res/conditions/toujours24.png")
.AddParameter("scenevar", _("The variable to be stringified"));
extension
.AddStrExpression("ToJSON",
_("Convert variable to JSON"),
_("Convert a variable to JSON"),
_("Conversion"),
"res/conditions/toujours24.png")
.AddParameter("scenevar", _("The variable to be stringified"));
extension.AddStrExpression("GlobalVarToJSON",
_("Convert global variable to JSON"),
_("Convert a global variable to JSON"),
_("Conversion"),
"res/conditions/toujours24.png")
.AddParameter("globalvar", _("The global variable to be stringified"));
extension
.AddStrExpression("GlobalVarToJSON",
_("Convert global variable to JSON"),
_("Convert a global variable to JSON"),
_("Conversion"),
"res/conditions/toujours24.png")
.AddParameter("globalvar", _("The global variable to be stringified"));
extension.AddStrExpression("ObjectVarToJSON",
_("Convert object variable to JSON"),
_("Convert an object variable to JSON"),
_("Conversion"),
"res/conditions/toujours24.png")
.AddParameter("objectPtr", _("The object with the variable"))
.AddParameter("objectvar", _("The object variable to be stringified"));
#endif
extension
.AddStrExpression("ObjectVarToJSON",
_("Convert object variable to JSON"),
_("Convert an object variable to JSON"),
_("Conversion"),
"res/conditions/toujours24.png")
.AddParameter("objectPtr", _("The object with the variable"))
.AddParameter("objectvar", _("The object variable to be stringified"));
#endif
}
}
} // namespace gd

View File

@@ -1,118 +1,142 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "AllBuiltinExtensions.h"
#include "GDCore/Tools/Localization.h"
using namespace std;
namespace gd
{
namespace gd {
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsSceneExtension(gd::PlatformExtension & extension)
{
extension.SetExtensionInformation("BuiltinScene",
_("Scene management features"),
_("This Built-in extension allows you to manipulate scenes"),
"Florian Rival",
"Open source (MIT License)");
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsSceneExtension(
gd::PlatformExtension& extension) {
extension.SetExtensionInformation(
"BuiltinScene",
_("Scene management features"),
_("This Built-in extension allows you to manipulate scenes"),
"Florian Rival",
"Open source (MIT License)");
#if defined(GD_IDE_ONLY)
#if defined(GD_IDE_ONLY)
extension.AddExpression("Random", _("Random value"), _("Random value"), _("Random"), "res/actions/position.png")
.AddParameter("expression", _("Maximum value"));
extension
.AddExpression("Random",
_("Random value"),
_("Random value"),
_("Random"),
"res/actions/position.png")
.AddParameter("expression", _("Maximum value"));
extension.AddStrExpression("CurrentSceneName", _("Current scene name"), _("Name of the current scene"), _("Scene"), "res/actions/texte.png")
.AddCodeOnlyParameter("currentScene", "");
extension
.AddStrExpression("CurrentSceneName",
_("Current scene name"),
_("Name of the current scene"),
_("Scene"),
"res/actions/texte.png")
.AddCodeOnlyParameter("currentScene", "");
extension.AddCondition("DepartScene",
_("At the beginning of the scene"),
_("Is true only when scene just begins."),
_("At the beginning of the scene"),
_("Scene"),
"res/conditions/depart24.png",
"res/conditions/depart.png")
.AddCodeOnlyParameter("currentScene", "")
.MarkAsSimple();
extension
.AddCondition("DepartScene",
_("At the beginning of the scene"),
_("Is true only when scene just begins."),
_("At the beginning of the scene"),
_("Scene"),
"res/conditions/depart24.png",
"res/conditions/depart.png")
.AddCodeOnlyParameter("currentScene", "")
.MarkAsSimple();
extension.AddAction("Scene",
_("Change the scene"),
_("Stop this scene and start the specified one instead."),
_("Change for scene _PARAM1_"),
_("Scene"),
"res/actions/replaceScene24.png",
"res/actions/replaceScene.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Name of the new scene"))
.AddParameter("yesorno", _("Stop any other paused scenes?")).SetDefaultValue("true")
.MarkAsAdvanced();
extension
.AddAction("Scene",
_("Change the scene"),
_("Stop this scene and start the specified one instead."),
_("Change for scene _PARAM1_"),
_("Scene"),
"res/actions/replaceScene24.png",
"res/actions/replaceScene.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Name of the new scene"))
.AddParameter("yesorno", _("Stop any other paused scenes?"))
.SetDefaultValue("true")
.MarkAsAdvanced();
extension.AddAction("PushScene",
_("Pause and start a new scene"),
_("Pause this scene and start the specified one.\nLater, you can use the \"Stop and go back to previous scene\" action to go back to this scene."),
_("Pause the scene and start _PARAM1_"),
_("Scene"),
"res/actions/pushScene24.png",
"res/actions/pushScene.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Name of the new scene"))
.MarkAsAdvanced();
extension
.AddAction("PushScene",
_("Pause and start a new scene"),
_("Pause this scene and start the specified one.\nLater, you "
"can use the \"Stop and go back to previous scene\" action "
"to go back to this scene."),
_("Pause the scene and start _PARAM1_"),
_("Scene"),
"res/actions/pushScene24.png",
"res/actions/pushScene.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Name of the new scene"))
.MarkAsAdvanced();
extension.AddAction("PopScene",
_("Stop and go back to previous scene"),
_("Stop this scene and go back to the previous paused one.\nTo pause a scene, use the \"Pause and start a new scene\" action."),
_("Stop the scene and go back to the previous paused one"),
_("Scene"),
"res/actions/popScene24.png",
"res/actions/popScene.png")
.AddCodeOnlyParameter("currentScene", "")
.MarkAsAdvanced();
extension
.AddAction(
"PopScene",
_("Stop and go back to previous scene"),
_("Stop this scene and go back to the previous paused one.\nTo pause "
"a scene, use the \"Pause and start a new scene\" action."),
_("Stop the scene and go back to the previous paused one"),
_("Scene"),
"res/actions/popScene24.png",
"res/actions/popScene.png")
.AddCodeOnlyParameter("currentScene", "")
.MarkAsAdvanced();
extension.AddAction("Quit",
_("Quit the game"),
_("Quit the game"),
_("Quit the game"),
_("Scene"),
"res/actions/quit24.png",
"res/actions/quit.png")
.AddCodeOnlyParameter("currentScene", "")
.MarkAsAdvanced();
extension
.AddAction("Quit",
_("Quit the game"),
_("Quit the game"),
_("Quit the game"),
_("Scene"),
"res/actions/quit24.png",
"res/actions/quit.png")
.AddCodeOnlyParameter("currentScene", "")
.MarkAsAdvanced();
extension.AddAction("SceneBackground",
_("Change background color"),
_("Change the background color of the scene."),
_("Set background color to _PARAM1_"),
_("Scene"),
"res/actions/background24.png",
"res/actions/background.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("color", _("Color"))
.MarkAsAdvanced();
extension
.AddAction("SceneBackground",
_("Change background color"),
_("Change the background color of the scene."),
_("Set background color to _PARAM1_"),
_("Scene"),
"res/actions/background24.png",
"res/actions/background.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("color", _("Color"))
.MarkAsAdvanced();
extension.AddAction("DisableInputWhenFocusIsLost",
_("Disable input when focus is lost"),
_("Decide if the keyboard and mouse buttons must be taken into account even\nif the window is not active."),
_("Disable input when focus is lost: _PARAM1_"),
_("Scene"),
"res/actions/window24.png",
"res/actions/window.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("yesorno", _("Deactivate input when focus is lost"))
.MarkAsAdvanced();
extension
.AddAction("DisableInputWhenFocusIsLost",
_("Disable input when focus is lost"),
_("Decide if the keyboard and mouse buttons must be taken "
"into account even\nif the window is not active."),
_("Disable input when focus is lost: _PARAM1_"),
_("Scene"),
"res/actions/window24.png",
"res/actions/window.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("yesorno", _("Deactivate input when focus is lost"))
.MarkAsAdvanced();
extension.AddCondition("Egal",
_("Compare two expressions"),
_("Test the two expressions"),
_("_PARAM0_ _PARAM1_ _PARAM2_"),
_("Other"),
"res/conditions/egal24.png",
"res/conditions/egal.png")
.AddParameter("expression", _("Expression 1"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Expression 2"))
.MarkAsAdvanced();
#endif
extension
.AddCondition("Egal",
_("Compare two expressions"),
_("Test the two expressions"),
_("_PARAM0_ _PARAM1_ _PARAM2_"),
_("Other"),
"res/conditions/egal24.png",
"res/conditions/egal.png")
.AddParameter("expression", _("Expression 1"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Expression 2"))
.MarkAsAdvanced();
#endif
}
}
} // namespace gd

View File

@@ -1,74 +1,56 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "GDCore/Extensions/Builtin/SpriteExtension/Animation.h"
#include <vector>
#include "GDCore/Extensions/Builtin/SpriteExtension/Direction.h"
#include "GDCore/Extensions/Builtin/SpriteExtension/Sprite.h"
#include "GDCore/String.h"
#include <vector>
namespace gd {
Direction Animation::badDirection;
Animation::Animation() :
useMultipleDirections(false)
{
Animation::Animation() : useMultipleDirections(false) {}
Animation::~Animation() {}
std::size_t Animation::GetDirectionsCount() const { return directions.size(); };
bool Animation::HasNoDirections() const { return directions.empty(); };
void Animation::SetDirectionsCount(std::size_t nb) {
while (directions.size() < nb) {
Direction direction;
directions.push_back(direction);
}
while (directions.size() > nb)
directions.erase(directions.begin() + directions.size() - 1);
}
Animation::~Animation()
{
const Direction& Animation::GetDirection(std::size_t nb) const {
if (!useMultipleDirections) nb = 0;
if (nb < directions.size()) return directions[nb];
return badDirection;
}
std::size_t Animation::GetDirectionsCount() const
{
return directions.size();
};
Direction& Animation::GetDirection(std::size_t nb) {
if (!useMultipleDirections) nb = 0;
bool Animation::HasNoDirections() const
{
return directions.empty();
};
if (nb < directions.size()) return directions[nb];
void Animation::SetDirectionsCount(std::size_t nb)
{
while ( directions.size() < nb ) {
Direction direction;
directions.push_back(direction);
}
while ( directions.size() > nb )
directions.erase(directions.begin()+directions.size()-1);
return badDirection;
}
const Direction & Animation::GetDirection(std::size_t nb) const
{
if (!useMultipleDirections) nb = 0;
void Animation::SetDirection(const Direction& direction, std::size_t nb) {
if (nb < directions.size()) directions[nb] = direction;
if ( nb < directions.size() )
return directions[nb];
return badDirection;
return;
}
Direction & Animation::GetDirection(std::size_t nb)
{
if (!useMultipleDirections) nb = 0;
if (nb < directions.size() )
return directions[nb];
return badDirection;
}
void Animation::SetDirection(const Direction & direction, std::size_t nb)
{
if (nb < directions.size() ) directions[nb] = direction;
return;
}
}
} // namespace gd

View File

@@ -1,17 +1,18 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_ANIMATION_H
#define GDCORE_ANIMATION_H
#include <vector>
#include "GDCore/String.h"
namespace gd { class Direction; }
namespace gd {
class Direction;
}
namespace gd
{
namespace gd {
/**
* \brief Class representing an animation of a SpriteObject.
@@ -20,76 +21,76 @@ namespace gd
* \see Direction
* \ingroup SpriteObjectExtension
*/
class GD_CORE_API Animation
{
public:
Animation();
virtual ~Animation();
class GD_CORE_API Animation {
public:
Animation();
virtual ~Animation();
/**
* \brief Set the name of the animation
*/
const gd::String & GetName() const { return name; }
/**
* \brief Set the name of the animation
*/
const gd::String& GetName() const { return name; }
/**
* \brief Change the name of the animation
*/
void SetName(const gd::String & name_) { name = name_; }
/**
* \brief Change the name of the animation
*/
void SetName(const gd::String& name_) { name = name_; }
/**
* \brief Return the n-th direction
*/
const Direction & GetDirection(std::size_t n) const;
/**
* \brief Return the n-th direction
*/
const Direction& GetDirection(std::size_t n) const;
/**
* \brief Return the n-th direction
*/
Direction & GetDirection(std::size_t n);
/**
* \brief Return the n-th direction
*/
Direction& GetDirection(std::size_t n);
/**
* \brief Change a direction
*/
void SetDirection(const Direction & direction, std::size_t nb);
/**
* \brief Change a direction
*/
void SetDirection(const Direction& direction, std::size_t nb);
/**
* \brief Change direction count
*/
void SetDirectionsCount(std::size_t nb);
/**
* \brief Change direction count
*/
void SetDirectionsCount(std::size_t nb);
/**
* \brief Get direction count
*/
std::size_t GetDirectionsCount() const;
/**
* \brief Get direction count
*/
std::size_t GetDirectionsCount() const;
/**
* \brief Return true if there isn't any direction in the animation
*/
bool HasNoDirections() const;
/**
* \brief Return true if there isn't any direction in the animation
*/
bool HasNoDirections() const;
/**
* \brief Return true if the animation is composed of more than one direction.
*
* By default, an animation is composed of a single direction, and the sprite
* is rotated.
*/
bool UseMultipleDirections() const { return useMultipleDirections; }
/**
* \brief Return true if the animation is composed of more than one direction.
*
* By default, an animation is composed of a single direction, and the sprite
* is rotated.
*/
bool UseMultipleDirections() const { return useMultipleDirections; }
/**
* \brief Set if the animation is using more than one direction.
*
* By default, an animation is composed of a single direction, and the sprite
* is rotated.
*/
void SetUseMultipleDirections(bool enable) { useMultipleDirections = enable; }
/**
* \brief Set if the animation is using more than one direction.
*
* By default, an animation is composed of a single direction, and the sprite
* is rotated.
*/
void SetUseMultipleDirections(bool enable) { useMultipleDirections = enable; }
bool useMultipleDirections; ///< deprecated This should be moved to class private members
bool useMultipleDirections; ///< deprecated This should be moved to class
///< private members
private:
std::vector < Direction > directions;
gd::String name;
private:
std::vector<Direction> directions;
gd::String name;
static Direction badDirection;
static Direction badDirection;
};
}
#endif // GDCORE_ANIMATION_H
} // namespace gd
#endif // GDCORE_ANIMATION_H

View File

@@ -1,32 +1,38 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
#ifndef SPRITEOBJECTEDITOR_H
#define SPRITEOBJECTEDITOR_H
//(*Headers(SpriteObjectEditor)
#include <wx/listctrl.h>
#include <wx/treectrl.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/menu.h>
#include <wx/treelist.h>
#include <wx/aui/aui.h>
#include <wx/dialog.h>
#include <wx/listctrl.h>
#include <wx/menu.h>
#include <wx/panel.h>
#include <wx/scrolbar.h>
#include <wx/dialog.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/timer.h>
#include <wx/treectrl.h>
#include <wx/treelist.h>
//*)
#include <wx/dnd.h>
#include <vector>
namespace gd { class MainFrameWrapper; }
namespace gd {
class MainFrameWrapper;
}
class ResourcesEditor;
class SpriteObject;
namespace gd { class Resource; }
namespace gd { class Project; }
namespace gd {
class Resource;
}
namespace gd {
class Project;
}
class Sprite;
#include "GDCore/IDE/Dialogs/PolygonEditionHelper.h"
@@ -39,281 +45,284 @@ namespace gd {
* \ingroup IDEDialogs
* \ingroup BuiltinExtensions
*/
class SpriteObjectEditor: public wxDialog
{
public:
class SpriteObjectEditor : public wxDialog {
public:
SpriteObjectEditor(wxWindow* parent,
gd::Project& game,
SpriteObject& object,
gd::MainFrameWrapper& mainFrameWrapper_);
virtual ~SpriteObjectEditor();
SpriteObjectEditor(wxWindow* parent, gd::Project & game, SpriteObject & object, gd::MainFrameWrapper & mainFrameWrapper_ );
virtual ~SpriteObjectEditor();
/**
* \brief Can be called to add an image to the current animation.
*
* Used by DndTextSpriteObjectEditor so as to add a dragged image.
* \param image The name of the image resource to add.
* \param refresh Optional parameter: When set to false, the lists of images
* won't be refreshed.
*/
void AddImageToCurrentAnimation(wxString image, bool refresh = true);
/**
* \brief Can be called to add an image to the current animation.
*
* Used by DndTextSpriteObjectEditor so as to add a dragged image.
* \param image The name of the image resource to add.
* \param refresh Optional parameter: When set to false, the lists of images won't be refreshed.
*/
void AddImageToCurrentAnimation(wxString image, bool refresh = true);
//(*Declarations(SpriteObjectEditor)
wxAuiManager* AuiManager1;
wxMenu* MenuItem2;
wxTreeCtrl* animationsTree;
wxTreeListCtrl* maskTree;
wxMenuItem* MenuItem8;
wxListCtrl* pointsList;
wxPanel* toolbarPanel;
wxAuiToolBar* toolbar;
wxMenuItem* MenuItem7;
wxAuiToolBar* pointToolbar;
wxAuiManager* mgr;
wxAuiManager* AuiManager4;
wxStaticText* statusTxt;
wxMenuItem* MenuItem5;
wxPanel* centerPanel;
wxMenuItem* deleteItem;
wxMenuItem* MenuItem1;
wxMenuItem* MenuItem4;
wxMenuItem* MenuItem14;
wxMenuItem* MenuItem11;
wxMenuItem* MenuItem15;
wxPanel* Panel1;
wxMenu animationsMenu;
wxMenuItem* MenuItem17;
wxMenu* MenuItem13;
wxMenuItem* MenuItem10;
wxAuiManager* AuiManager2;
wxMenuItem* removeImageItem;
wxPanel* Panel3;
wxAuiToolBar* maskToolbar;
wxPanel* animationsPanel;
wxMenuItem* MenuItem12;
wxScrollBar* xScrollBar;
wxTimer previewTimer;
wxMenuItem* MenuItem3;
wxAuiManager* AuiManager3;
wxMenuItem* MenuItem20;
wxPanel* imagePanel;
wxScrollBar* yScrollBar;
wxMenu emptyImagesMenu;
wxMenuItem* moveLeftItem;
wxMenuItem* MenuItem6;
wxPanel* previewPanel;
wxPanel* maskPanel;
wxMenuItem* moveRightItem;
wxPanel* Panel2;
wxMenuItem* automaticRotationItem;
wxMenuItem* MenuItem16;
wxPanel* pointsPanel;
wxMenuItem* MenuItem9;
wxMenuItem* multipleDirectionsItem;
wxListCtrl* imagesList;
wxMenuItem* MenuItem18;
wxMenu imagesMenu;
wxMenu maskMenu;
wxPanel* imagesPanel;
wxAuiToolBar* animationToolbar;
wxMenuItem* MenuItem19;
//*)
ResourcesEditor* resourcesEditorPnl;
//(*Declarations(SpriteObjectEditor)
wxAuiManager* AuiManager1;
wxMenu* MenuItem2;
wxTreeCtrl* animationsTree;
wxTreeListCtrl* maskTree;
wxMenuItem* MenuItem8;
wxListCtrl* pointsList;
wxPanel* toolbarPanel;
wxAuiToolBar* toolbar;
wxMenuItem* MenuItem7;
wxAuiToolBar* pointToolbar;
wxAuiManager* mgr;
wxAuiManager* AuiManager4;
wxStaticText* statusTxt;
wxMenuItem* MenuItem5;
wxPanel* centerPanel;
wxMenuItem* deleteItem;
wxMenuItem* MenuItem1;
wxMenuItem* MenuItem4;
wxMenuItem* MenuItem14;
wxMenuItem* MenuItem11;
wxMenuItem* MenuItem15;
wxPanel* Panel1;
wxMenu animationsMenu;
wxMenuItem* MenuItem17;
wxMenu* MenuItem13;
wxMenuItem* MenuItem10;
wxAuiManager* AuiManager2;
wxMenuItem* removeImageItem;
wxPanel* Panel3;
wxAuiToolBar* maskToolbar;
wxPanel* animationsPanel;
wxMenuItem* MenuItem12;
wxScrollBar* xScrollBar;
wxTimer previewTimer;
wxMenuItem* MenuItem3;
wxAuiManager* AuiManager3;
wxMenuItem* MenuItem20;
wxPanel* imagePanel;
wxScrollBar* yScrollBar;
wxMenu emptyImagesMenu;
wxMenuItem* moveLeftItem;
wxMenuItem* MenuItem6;
wxPanel* previewPanel;
wxPanel* maskPanel;
wxMenuItem* moveRightItem;
wxPanel* Panel2;
wxMenuItem* automaticRotationItem;
wxMenuItem* MenuItem16;
wxPanel* pointsPanel;
wxMenuItem* MenuItem9;
wxMenuItem* multipleDirectionsItem;
wxListCtrl* imagesList;
wxMenuItem* MenuItem18;
wxMenu imagesMenu;
wxMenu maskMenu;
wxPanel* imagesPanel;
wxAuiToolBar* animationToolbar;
wxMenuItem* MenuItem19;
//*)
ResourcesEditor * resourcesEditorPnl;
protected:
//(*Identifiers(SpriteObjectEditor)
static const long ID_MASKITEM;
static const long ID_POINTSITEM;
static const long ID_AUITOOLBARITEM4;
static const long ID_AUITOOLBARITEM2;
static const long ID_AUITOOLBAR1;
static const long ID_PANEL6;
static const long ID_PANEL4;
static const long ID_SCROLLBAR1;
static const long ID_SCROLLBAR2;
static const long ID_STATICTEXT1;
static const long ID_PANEL1;
static const long ID_AUITOOLBARITEM5;
static const long ID_AUITOOLBARITEM8;
static const long ID_TOOLLOOP;
static const long ID_AUITOOLBARITEM10;
static const long ID_AUITOOLBAR4;
static const long ID_PANEL11;
static const long ID_TREECTRL1;
static const long ID_PANEL3;
static const long ID_LISTCTRL1;
static const long ID_PANEL2;
static const long ID_AUITOOLBARITEM9;
static const long ID_AUITOOLBARITEM11;
static const long ID_AUITOOLBARITEM7;
static const long ID_AUITOOLBARITEM1;
static const long ID_MASKAPPLYWHOLEANIMITEM;
static const long ID_AUITOOLBAR3;
static const long ID_PANEL9;
static const long ID_TREELISTCTRL1;
static const long ID_PANEL8;
static const long ID_AUITOOLBARITEM3;
static const long ID_DELETEPOINTITEM;
static const long ID_POINTAPPLYWHOLEANIMITEM;
static const long ID_AUITOOLBAR2;
static const long ID_PANEL7;
static const long ID_LISTCTRL3;
static const long ID_PANEL5;
static const long ID_PANEL10;
static const long ID_MENUITEM5;
static const long ID_MENUITEM6;
static const long ID_MENUITEM4;
static const long ID_MENUIDLENAME;
static const long ID_MENUWALKNAME;
static const long ID_MENURUNNAME;
static const long ID_MENUJUMPNAME;
static const long ID_MENUSHOOTNAME;
static const long ID_MENUDEADNAME;
static const long ID_MENUCUSTOMNAME;
static const long ID_MENUITEM15;
static const long ID_MENUTIMEBETWEENFRAMES;
static const long ID_MENULOOP;
static const long ID_MENUITEM1;
static const long ID_MENUITEM2;
static const long ID_MENUITEM3;
static const long ID_MENUITEM7;
static const long ID_MENUITEM11;
static const long ID_MENUITEM8;
static const long ID_MENUITEM9;
static const long ID_MENUITEM10;
static const long ID_POSITIONMASKITEM;
static const long ID_MOVEPOLYGONITEM;
static const long ID_MENUITEM14;
static const long ID_TIMER1;
static const long ID_MENUITEM12;
static const long ID_MENUITEM13;
//*)
protected:
private:
//(*Handlers(SpriteObjectEditor)
void OnimagePanelPaint(wxPaintEvent& event);
void OnimagePanelEraseBackground(wxEraseEvent& event);
void OnimagesListItemSelect(wxListEvent& event);
void OnimagePanelResize(wxSizeEvent& event);
void OnanimationsTreeSelectionChanged(wxTreeEvent& event);
void OnAddAnimationSelected(wxCommandEvent& event);
void OnDeleteAnimationSelected(wxCommandEvent& event);
void OnanimationsTreeItemRightClick(wxTreeEvent& event);
void OnautomaticRotationItemSelected(wxCommandEvent& event);
void OnmultipleDirectionsItemSelected(wxCommandEvent& event);
void OnimagesListItemRClick(wxListEvent& event);
void OnremoveImageItemSelected(wxCommandEvent& event);
void OnMoveLeftSelected(wxCommandEvent& event);
void OnMoveRightSelected(wxCommandEvent& event);
void OnMaskEditClick(wxCommandEvent& event);
void OnPointEditClick(wxCommandEvent& event);
void OnmgrPaneClose(wxAuiManagerEvent& event);
void OnpointsListBeginLabelEdit(wxListEvent& event);
void OnpointsListEndLabelEdit(wxListEvent& event);
void OnimagePanelLeftUp(wxMouseEvent& event);
void OnpointsListItemSelect(wxListEvent& event);
void OnDeletePointClick(wxCommandEvent& event);
void OnAddPointClick(wxCommandEvent& event);
void OnpointsListItemActivated(wxListEvent& event);
void OnimagePanelLeftDown(wxMouseEvent& event);
void OnimagePanelMouseMove(wxMouseEvent& event);
void OnAddMaskClick(wxCommandEvent& event);
void OnDeleteMaskClick(wxCommandEvent& event);
void OnDefaultMaskClick(wxCommandEvent& event);
void OnPositionMaskSelected(wxCommandEvent& event);
void OnResizeMaskSelected(wxCommandEvent& event);
void OnMenuLoopSelected(wxCommandEvent& event);
void OnTimeBetweenFramesSelected(wxCommandEvent& event);
void OnpreviewPanelEraseBackground(wxEraseEvent& event);
void OnpreviewPanelResize(wxSizeEvent& event);
void OnpreviewPanelPaint(wxPaintEvent& event);
void OnTimer1Trigger(wxTimerEvent& event);
void OnpreviewTimerTrigger(wxTimerEvent& event);
void OnPreviewClick(wxCommandEvent& event);
void OnimagesListKeyDown(wxListEvent& event);
void OnAddImageFromFileSelected(wxCommandEvent& event);
void OnAddFromImageBankSelected(wxCommandEvent& event);
void OnHelpClick(wxCommandEvent& event);
void OnToolLoopClick(wxCommandEvent& event);
void OnMovePolygonSelected(wxCommandEvent& event);
void OnAddPolygonMaskClick(wxCommandEvent& event);
void OnAddVerticeClick(wxCommandEvent& event);
void OnRotatePolygonSelected(wxCommandEvent& event);
void OnyScrollBarScroll(wxScrollEvent& event);
void OnxScrollBarScroll(wxScrollEvent& event);
void OnSetAnimationNameIdleSelected(wxCommandEvent& event);
void OnSetAnimationNameWalkSelected(wxCommandEvent& event);
void OnSetAnimationNameRunSelected(wxCommandEvent& event);
void OnSetAnimationNameJumpSelected(wxCommandEvent& event);
void OnSetAnimationNameShootSelected(wxCommandEvent& event);
void OnSetAnimationNameDeadSelected(wxCommandEvent& event);
void OnSetCustomAnimationNameSelected(wxCommandEvent& event);
//*)
void OnmaskTreeItemRClick(wxTreeListEvent& event);
void OnmaskTreeItemActivated(wxTreeListEvent& event);
void OnmaskTreeSelectionChanged(wxTreeListEvent& event);
void OnimagesListRightClick(wxMouseEvent& event);
void RefreshAll();
void RefreshAnimationTree();
void RefreshAnimationToolbar();
void RefreshImagesList();
void RefreshImageAndControls();
void RefreshPoints();
void RefreshCollisionMasks();
void ResetPreview();
wxBitmap GetwxBitmapFromImageResource(gd::Resource& resource);
void SetAnimationName(gd::String newName);
//(*Identifiers(SpriteObjectEditor)
static const long ID_MASKITEM;
static const long ID_POINTSITEM;
static const long ID_AUITOOLBARITEM4;
static const long ID_AUITOOLBARITEM2;
static const long ID_AUITOOLBAR1;
static const long ID_PANEL6;
static const long ID_PANEL4;
static const long ID_SCROLLBAR1;
static const long ID_SCROLLBAR2;
static const long ID_STATICTEXT1;
static const long ID_PANEL1;
static const long ID_AUITOOLBARITEM5;
static const long ID_AUITOOLBARITEM8;
static const long ID_TOOLLOOP;
static const long ID_AUITOOLBARITEM10;
static const long ID_AUITOOLBAR4;
static const long ID_PANEL11;
static const long ID_TREECTRL1;
static const long ID_PANEL3;
static const long ID_LISTCTRL1;
static const long ID_PANEL2;
static const long ID_AUITOOLBARITEM9;
static const long ID_AUITOOLBARITEM11;
static const long ID_AUITOOLBARITEM7;
static const long ID_AUITOOLBARITEM1;
static const long ID_MASKAPPLYWHOLEANIMITEM;
static const long ID_AUITOOLBAR3;
static const long ID_PANEL9;
static const long ID_TREELISTCTRL1;
static const long ID_PANEL8;
static const long ID_AUITOOLBARITEM3;
static const long ID_DELETEPOINTITEM;
static const long ID_POINTAPPLYWHOLEANIMITEM;
static const long ID_AUITOOLBAR2;
static const long ID_PANEL7;
static const long ID_LISTCTRL3;
static const long ID_PANEL5;
static const long ID_PANEL10;
static const long ID_MENUITEM5;
static const long ID_MENUITEM6;
static const long ID_MENUITEM4;
static const long ID_MENUIDLENAME;
static const long ID_MENUWALKNAME;
static const long ID_MENURUNNAME;
static const long ID_MENUJUMPNAME;
static const long ID_MENUSHOOTNAME;
static const long ID_MENUDEADNAME;
static const long ID_MENUCUSTOMNAME;
static const long ID_MENUITEM15;
static const long ID_MENUTIMEBETWEENFRAMES;
static const long ID_MENULOOP;
static const long ID_MENUITEM1;
static const long ID_MENUITEM2;
static const long ID_MENUITEM3;
static const long ID_MENUITEM7;
static const long ID_MENUITEM11;
static const long ID_MENUITEM8;
static const long ID_MENUITEM9;
static const long ID_MENUITEM10;
static const long ID_POSITIONMASKITEM;
static const long ID_MOVEPOLYGONITEM;
static const long ID_MENUITEM14;
static const long ID_TIMER1;
static const long ID_MENUITEM12;
static const long ID_MENUITEM13;
//*)
/**
* Return a vector containing the sprites which must be modified when editing
* a point or collision masks: When buttons "Apply the changes to the whole
* animation" are checked, the vector contains all the sprites of the
* animation. If the buttons are unchecked, the vector contains only the
* sprite currently modified
*/
std::vector<Sprite*> GetSpritesToModify();
private:
DECLARE_EVENT_TABLE()
//(*Handlers(SpriteObjectEditor)
void OnimagePanelPaint(wxPaintEvent& event);
void OnimagePanelEraseBackground(wxEraseEvent& event);
void OnimagesListItemSelect(wxListEvent& event);
void OnimagePanelResize(wxSizeEvent& event);
void OnanimationsTreeSelectionChanged(wxTreeEvent& event);
void OnAddAnimationSelected(wxCommandEvent& event);
void OnDeleteAnimationSelected(wxCommandEvent& event);
void OnanimationsTreeItemRightClick(wxTreeEvent& event);
void OnautomaticRotationItemSelected(wxCommandEvent& event);
void OnmultipleDirectionsItemSelected(wxCommandEvent& event);
void OnimagesListItemRClick(wxListEvent& event);
void OnremoveImageItemSelected(wxCommandEvent& event);
void OnMoveLeftSelected(wxCommandEvent& event);
void OnMoveRightSelected(wxCommandEvent& event);
void OnMaskEditClick(wxCommandEvent& event);
void OnPointEditClick(wxCommandEvent& event);
void OnmgrPaneClose(wxAuiManagerEvent& event);
void OnpointsListBeginLabelEdit(wxListEvent& event);
void OnpointsListEndLabelEdit(wxListEvent& event);
void OnimagePanelLeftUp(wxMouseEvent& event);
void OnpointsListItemSelect(wxListEvent& event);
void OnDeletePointClick(wxCommandEvent& event);
void OnAddPointClick(wxCommandEvent& event);
void OnpointsListItemActivated(wxListEvent& event);
void OnimagePanelLeftDown(wxMouseEvent& event);
void OnimagePanelMouseMove(wxMouseEvent& event);
void OnAddMaskClick(wxCommandEvent& event);
void OnDeleteMaskClick(wxCommandEvent& event);
void OnDefaultMaskClick(wxCommandEvent& event);
void OnPositionMaskSelected(wxCommandEvent& event);
void OnResizeMaskSelected(wxCommandEvent& event);
void OnMenuLoopSelected(wxCommandEvent& event);
void OnTimeBetweenFramesSelected(wxCommandEvent& event);
void OnpreviewPanelEraseBackground(wxEraseEvent& event);
void OnpreviewPanelResize(wxSizeEvent& event);
void OnpreviewPanelPaint(wxPaintEvent& event);
void OnTimer1Trigger(wxTimerEvent& event);
void OnpreviewTimerTrigger(wxTimerEvent& event);
void OnPreviewClick(wxCommandEvent& event);
void OnimagesListKeyDown(wxListEvent& event);
void OnAddImageFromFileSelected(wxCommandEvent& event);
void OnAddFromImageBankSelected(wxCommandEvent& event);
void OnHelpClick(wxCommandEvent& event);
void OnToolLoopClick(wxCommandEvent& event);
void OnMovePolygonSelected(wxCommandEvent& event);
void OnAddPolygonMaskClick(wxCommandEvent& event);
void OnAddVerticeClick(wxCommandEvent& event);
void OnRotatePolygonSelected(wxCommandEvent& event);
void OnyScrollBarScroll(wxScrollEvent& event);
void OnxScrollBarScroll(wxScrollEvent& event);
void OnSetAnimationNameIdleSelected(wxCommandEvent& event);
void OnSetAnimationNameWalkSelected(wxCommandEvent& event);
void OnSetAnimationNameRunSelected(wxCommandEvent& event);
void OnSetAnimationNameJumpSelected(wxCommandEvent& event);
void OnSetAnimationNameShootSelected(wxCommandEvent& event);
void OnSetAnimationNameDeadSelected(wxCommandEvent& event);
void OnSetCustomAnimationNameSelected(wxCommandEvent& event);
//*)
void OnmaskTreeItemRClick(wxTreeListEvent& event);
void OnmaskTreeItemActivated(wxTreeListEvent& event);
void OnmaskTreeSelectionChanged(wxTreeListEvent& event);
void OnimagesListRightClick(wxMouseEvent& event);
void RefreshAll();
void RefreshAnimationTree();
void RefreshAnimationToolbar();
void RefreshImagesList();
void RefreshImageAndControls();
void RefreshPoints();
void RefreshCollisionMasks();
void ResetPreview();
wxBitmap GetwxBitmapFromImageResource(gd::Resource & resource);
void SetAnimationName(gd::String newName);
gd::Project& game;
SpriteObject& object;
std::size_t selectedAnimation;
std::size_t selectedDirection;
std::size_t selectedImage;
gd::String selectedPoint;
float spritePosX; ///< Used to remember the position where the sprite have
///< been drawn.
float spritePosY; ///< Used to remember the position where the sprite have
///< been drawn.
float spriteWidth; ///< Used to remember the width of the current sprite.
float spriteHeight; ///< Used to remember the height of the current sprite.
/**
* Return a vector containing the sprites which must be modified when editing a point
* or collision masks:
* When buttons "Apply the changes to the whole animation" are checked, the vector contains
* all the sprites of the animation. If the buttons are unchecked, the vector contains only
* the sprite currently modified
*/
std::vector < Sprite * > GetSpritesToModify();
bool editingMask;
bool editingPoint;
bool deletingMaskTreeItems; // Used to workaround an event being called when
// using maskTree->DeleteAllItems().
DECLARE_EVENT_TABLE()
gd::String renamedPointOldName;
gd::Project & game;
SpriteObject & object;
std::size_t selectedAnimation;
std::size_t selectedDirection;
std::size_t selectedImage;
gd::String selectedPoint;
float spritePosX; ///< Used to remember the position where the sprite have been drawn.
float spritePosY; ///< Used to remember the position where the sprite have been drawn.
float spriteWidth; ///< Used to remember the width of the current sprite.
float spriteHeight; ///< Used to remember the height of the current sprite.
gd::PolygonEditionHelper polygonEditionHelper;
bool editingMask;
bool editingPoint;
bool deletingMaskTreeItems; //Used to workaround an event being called when using maskTree->DeleteAllItems().
float previewElapsedTime;
int previewCurrentSprite;
gd::String renamedPointOldName;
gd::PolygonEditionHelper polygonEditionHelper;
float previewElapsedTime;
int previewCurrentSprite;
gd::MainFrameWrapper & mainFrameWrapper;
gd::MainFrameWrapper& mainFrameWrapper;
};
/**
* \brief Tool class used by SpriteObjectEditor to enable inserting images using drag'n'drop
* \brief Tool class used by SpriteObjectEditor to enable inserting images using
* drag'n'drop
*/
class DndTextSpriteObjectEditor : public wxTextDropTarget
{
public:
DndTextSpriteObjectEditor(SpriteObjectEditor & editor_) : editor(editor_) {}
class DndTextSpriteObjectEditor : public wxTextDropTarget {
public:
DndTextSpriteObjectEditor(SpriteObjectEditor& editor_) : editor(editor_) {}
virtual bool OnDropText(wxCoord x, wxCoord y, const wxString& text);
virtual bool OnDropText(wxCoord x, wxCoord y, const wxString& text);
private:
SpriteObjectEditor & editor;
private:
SpriteObjectEditor& editor;
};
}
} // namespace gd
#endif
#endif

View File

@@ -1,214 +1,189 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include <iostream>
#include "GDCore/String.h"
#include <vector>
#include "GDCore/Extensions/Builtin/SpriteExtension/Direction.h"
#include <iostream>
#include <vector>
#include "GDCore/CommonTools.h"
#include "GDCore/Extensions/Builtin/SpriteExtension/Sprite.h"
#include "GDCore/Serialization/SerializerElement.h"
#include "GDCore/CommonTools.h"
#include "GDCore/String.h"
using namespace std;
namespace gd {
Direction::Direction() :
loop(false),
timeBetweenFrame(1)
{
Direction::Direction() : loop(false), timeBetweenFrame(1) {}
Direction::~Direction(){};
void Direction::SetLoop(bool loop_) { loop = loop_; }
void Direction::SetTimeBetweenFrames(float time) { timeBetweenFrame = time; }
void Direction::AddSprite(const Sprite& sprite) { sprites.push_back(sprite); }
const Sprite& Direction::GetSprite(std::size_t nb) const { return sprites[nb]; }
Sprite& Direction::GetSprite(std::size_t nb) { return sprites[nb]; }
void Direction::RemoveSprite(std::size_t index) {
if (index < sprites.size()) sprites.erase(sprites.begin() + index);
}
Direction::~Direction()
{
};
void Direction::SetLoop( bool loop_ )
{
loop = loop_;
void Direction::SwapSprites(std::size_t firstSpriteIndex,
std::size_t secondSpriteIndex) {
if (firstSpriteIndex < sprites.size() && secondSpriteIndex < sprites.size() &&
firstSpriteIndex != secondSpriteIndex)
swap(sprites[firstSpriteIndex], sprites[secondSpriteIndex]);
}
void Direction::SetTimeBetweenFrames( float time )
{
timeBetweenFrame = time;
void Direction::MoveSprite(std::size_t oldIndex, std::size_t newIndex) {
if (oldIndex >= sprites.size() || newIndex >= sprites.size()) return;
auto sprite = sprites[oldIndex];
sprites.erase(sprites.begin() + oldIndex);
sprites.insert(sprites.begin() + newIndex, sprite);
}
void Direction::AddSprite( const Sprite & sprite )
{
bool Direction::HasNoSprites() const { return sprites.empty(); }
std::size_t Direction::GetSpritesCount() const { return sprites.size(); }
void Direction::RemoveAllSprites() { sprites.clear(); }
void OpenPoint(Point& point, const gd::SerializerElement& element) {
point.SetName(element.GetStringAttribute("name", "", "nom"));
point.SetX(element.GetDoubleAttribute("x", 0, "X"));
point.SetY(element.GetDoubleAttribute("y", 0, "Y"));
}
void OpenPointsSprites(vector<Point>& points,
const gd::SerializerElement& element) {
element.ConsiderAsArrayOf("point", "Point");
for (std::size_t i = 0; i < element.GetChildrenCount(); ++i) {
Point point("");
OpenPoint(point, element.GetChild(i));
points.push_back(point);
}
}
void Direction::UnserializeFrom(const gd::SerializerElement& element) {
SetTimeBetweenFrames(
element.GetDoubleAttribute("timeBetweenFrames", 1, "tempsEntre"));
SetLoop(element.GetBoolAttribute("looping", false, "boucle"));
const gd::SerializerElement& spritesElement =
element.GetChild("sprites", 0, "Sprites");
spritesElement.ConsiderAsArrayOf("sprite", "Sprite");
for (std::size_t i = 0; i < spritesElement.GetChildrenCount(); ++i) {
const gd::SerializerElement& spriteElement = spritesElement.GetChild(i);
Sprite sprite;
sprite.SetImageName(spriteElement.GetStringAttribute("image"));
OpenPointsSprites(sprite.GetAllNonDefaultPoints(),
spriteElement.GetChild("points", 0, "Points"));
OpenPoint(sprite.GetOrigin(),
spriteElement.GetChild("originPoint", 0, "PointOrigine"));
OpenPoint(sprite.GetCenter(),
spriteElement.GetChild("centerPoint", 0, "PointCentre"));
sprite.SetDefaultCenterPoint(
spriteElement.GetChild("centerPoint", 0, "PointCentre")
.GetBoolAttribute("automatic", true));
if (spriteElement.HasChild("CustomCollisionMask"))
sprite.SetCollisionMaskAutomatic(
!spriteElement.GetChild("CustomCollisionMask")
.GetBoolAttribute("custom", false));
else
sprite.SetCollisionMaskAutomatic(
!spriteElement.GetBoolAttribute("hasCustomCollisionMask", false));
std::vector<Polygon2d> mask;
const gd::SerializerElement& collisionMaskElement =
spriteElement.GetChild("customCollisionMask", 0, "CustomCollisionMask");
collisionMaskElement.ConsiderAsArrayOf("polygon", "Polygon");
for (std::size_t j = 0; j < collisionMaskElement.GetChildrenCount(); ++j) {
Polygon2d polygon;
const gd::SerializerElement& polygonElement =
collisionMaskElement.GetChild(j);
polygonElement.ConsiderAsArrayOf("vertice", "Point");
for (std::size_t k = 0; k < polygonElement.GetChildrenCount(); ++k) {
const gd::SerializerElement& verticeElement =
polygonElement.GetChild(k);
polygon.vertices.push_back(
sf::Vector2f(verticeElement.GetDoubleAttribute("x"),
verticeElement.GetDoubleAttribute("y")));
}
mask.push_back(polygon);
}
sprite.SetCustomCollisionMask(mask);
sprites.push_back(sprite);
}
const Sprite & Direction::GetSprite(std::size_t nb) const
{
return sprites[nb];
}
Sprite & Direction::GetSprite(std::size_t nb)
{
return sprites[nb];
}
void Direction::RemoveSprite(std::size_t index)
{
if ( index < sprites.size() )
sprites.erase(sprites.begin()+index);
}
void Direction::SwapSprites(std::size_t firstSpriteIndex, std::size_t secondSpriteIndex)
{
if ( firstSpriteIndex < sprites.size() && secondSpriteIndex < sprites.size() && firstSpriteIndex != secondSpriteIndex)
swap(sprites[firstSpriteIndex], sprites[secondSpriteIndex]);
}
void Direction::MoveSprite(std::size_t oldIndex, std::size_t newIndex)
{
if ( oldIndex >= sprites.size() || newIndex >= sprites.size())
return;
auto sprite = sprites[oldIndex];
sprites.erase(sprites.begin() + oldIndex);
sprites.insert(sprites.begin() + newIndex, sprite);
}
bool Direction::HasNoSprites() const
{
return sprites.empty();
}
std::size_t Direction::GetSpritesCount() const
{
return sprites.size();
}
void Direction::RemoveAllSprites()
{
sprites.clear();
}
void OpenPoint(Point & point, const gd::SerializerElement & element)
{
point.SetName(element.GetStringAttribute("name", "", "nom"));
point.SetX(element.GetDoubleAttribute("x", 0, "X"));
point.SetY(element.GetDoubleAttribute("y", 0, "Y"));
}
void OpenPointsSprites(vector < Point > & points, const gd::SerializerElement & element)
{
element.ConsiderAsArrayOf("point", "Point");
for (std::size_t i = 0; i < element.GetChildrenCount(); ++i)
{
Point point("");
OpenPoint(point, element.GetChild(i));
points.push_back(point);
}
}
void Direction::UnserializeFrom(const gd::SerializerElement & element)
{
SetTimeBetweenFrames(element.GetDoubleAttribute("timeBetweenFrames", 1, "tempsEntre"));
SetLoop(element.GetBoolAttribute("looping", false, "boucle"));
const gd::SerializerElement & spritesElement = element.GetChild("sprites", 0, "Sprites");
spritesElement.ConsiderAsArrayOf("sprite", "Sprite");
for (std::size_t i = 0; i < spritesElement.GetChildrenCount(); ++i)
{
const gd::SerializerElement & spriteElement = spritesElement.GetChild(i);
Sprite sprite;
sprite.SetImageName(spriteElement.GetStringAttribute("image"));
OpenPointsSprites(sprite.GetAllNonDefaultPoints(), spriteElement.GetChild("points", 0, "Points"));
OpenPoint(sprite.GetOrigin(), spriteElement.GetChild("originPoint" , 0, "PointOrigine"));
OpenPoint(sprite.GetCenter(), spriteElement.GetChild("centerPoint" , 0, "PointCentre"));
sprite.SetDefaultCenterPoint(spriteElement.GetChild("centerPoint" , 0, "PointCentre").GetBoolAttribute("automatic", true));
if (spriteElement.HasChild("CustomCollisionMask"))
sprite.SetCollisionMaskAutomatic(!spriteElement.GetChild("CustomCollisionMask").GetBoolAttribute("custom", false));
else
sprite.SetCollisionMaskAutomatic(!spriteElement.GetBoolAttribute("hasCustomCollisionMask", false));
std::vector<Polygon2d> mask;
const gd::SerializerElement & collisionMaskElement = spriteElement.GetChild("customCollisionMask", 0, "CustomCollisionMask");
collisionMaskElement.ConsiderAsArrayOf("polygon", "Polygon");
for (std::size_t j = 0; j < collisionMaskElement.GetChildrenCount(); ++j)
{
Polygon2d polygon;
const gd::SerializerElement & polygonElement = collisionMaskElement.GetChild(j);
polygonElement.ConsiderAsArrayOf("vertice", "Point");
for (std::size_t k = 0; k < polygonElement.GetChildrenCount(); ++k)
{
const gd::SerializerElement & verticeElement = polygonElement.GetChild(k);
polygon.vertices.push_back(sf::Vector2f(verticeElement.GetDoubleAttribute("x"),
verticeElement.GetDoubleAttribute("y")));
}
mask.push_back(polygon);
}
sprite.SetCustomCollisionMask(mask);
sprites.push_back(sprite);
}
}
};
#if defined(GD_IDE_ONLY)
void SavePoint(const Point & point, gd::SerializerElement & element)
{
element.SetAttribute("name", point.GetName());
element.SetAttribute("x", point.GetX());
element.SetAttribute("y", point.GetY());
void SavePoint(const Point& point, gd::SerializerElement& element) {
element.SetAttribute("name", point.GetName());
element.SetAttribute("x", point.GetX());
element.SetAttribute("y", point.GetY());
}
void SavePointsSprites(const vector < Point > & points, gd::SerializerElement & element)
{
element.ConsiderAsArrayOf("point");
for (std::size_t i = 0;i<points.size();++i)
SavePoint(points[i], element.AddChild("point"));
void SavePointsSprites(const vector<Point>& points,
gd::SerializerElement& element) {
element.ConsiderAsArrayOf("point");
for (std::size_t i = 0; i < points.size(); ++i)
SavePoint(points[i], element.AddChild("point"));
}
void SaveSpritesDirection(const vector < Sprite > & sprites, gd::SerializerElement & element)
{
element.ConsiderAsArrayOf("sprite");
for (std::size_t i = 0;i<sprites.size();++i)
{
gd::SerializerElement & spriteElement = element.AddChild("sprite");
void SaveSpritesDirection(const vector<Sprite>& sprites,
gd::SerializerElement& element) {
element.ConsiderAsArrayOf("sprite");
for (std::size_t i = 0; i < sprites.size(); ++i) {
gd::SerializerElement& spriteElement = element.AddChild("sprite");
spriteElement.SetAttribute("image", sprites[i].GetImageName());
SavePointsSprites(sprites[i].GetAllNonDefaultPoints(), spriteElement.AddChild("points"));
spriteElement.SetAttribute("image", sprites[i].GetImageName());
SavePointsSprites(sprites[i].GetAllNonDefaultPoints(),
spriteElement.AddChild("points"));
SavePoint(sprites[i].GetOrigin(), spriteElement.AddChild("originPoint"));
SavePoint(sprites[i].GetCenter(), spriteElement.AddChild("centerPoint"));
spriteElement.GetChild("centerPoint").SetAttribute("automatic", sprites[i].IsDefaultCenterPoint());
SavePoint(sprites[i].GetOrigin(), spriteElement.AddChild("originPoint"));
SavePoint(sprites[i].GetCenter(), spriteElement.AddChild("centerPoint"));
spriteElement.GetChild("centerPoint")
.SetAttribute("automatic", sprites[i].IsDefaultCenterPoint());
spriteElement.SetAttribute("hasCustomCollisionMask", !sprites[i].IsCollisionMaskAutomatic());
spriteElement.SetAttribute("hasCustomCollisionMask",
!sprites[i].IsCollisionMaskAutomatic());
gd::SerializerElement & collisionMaskElement = spriteElement.AddChild("customCollisionMask");
collisionMaskElement.ConsiderAsArrayOf("polygon");
std::vector<Polygon2d> polygons = sprites[i].GetCollisionMask();
for (std::size_t j = 0;j<polygons.size();++j)
{
gd::SerializerElement & polygonElement = collisionMaskElement.AddChild("polygon");
polygonElement.ConsiderAsArrayOf("vertice");
for (std::size_t k = 0;k<polygons[j].vertices.size();++k)
{
polygonElement.AddChild("vertice")
.SetAttribute("x", polygons[j].vertices[k].x)
.SetAttribute("y", polygons[j].vertices[k].y);
}
}
gd::SerializerElement& collisionMaskElement =
spriteElement.AddChild("customCollisionMask");
collisionMaskElement.ConsiderAsArrayOf("polygon");
std::vector<Polygon2d> polygons = sprites[i].GetCollisionMask();
for (std::size_t j = 0; j < polygons.size(); ++j) {
gd::SerializerElement& polygonElement =
collisionMaskElement.AddChild("polygon");
polygonElement.ConsiderAsArrayOf("vertice");
for (std::size_t k = 0; k < polygons[j].vertices.size(); ++k) {
polygonElement.AddChild("vertice")
.SetAttribute("x", polygons[j].vertices[k].x)
.SetAttribute("y", polygons[j].vertices[k].y);
}
}
}
}
void Direction::SerializeTo(gd::SerializerElement & element) const
{
element.SetAttribute("looping", IsLooping());
element.SetAttribute("timeBetweenFrames", GetTimeBetweenFrames());
SaveSpritesDirection(sprites, element.AddChild("sprites"));
void Direction::SerializeTo(gd::SerializerElement& element) const {
element.SetAttribute("looping", IsLooping());
element.SetAttribute("timeBetweenFrames", GetTimeBetweenFrames());
SaveSpritesDirection(sprites, element.AddChild("sprites"));
}
#endif
}
} // namespace gd

View File

@@ -1,13 +1,17 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_DIRECTION_H
#define GDCORE_DIRECTION_H
#include <vector>
namespace gd { class Sprite; }
namespace gd { class SerializerElement; }
namespace gd {
class Sprite;
}
namespace gd {
class SerializerElement;
}
namespace gd {
@@ -19,97 +23,97 @@ namespace gd {
* \see Sprite
* \ingroup SpriteObjectExtension
*
* \todo Support UTF8 (currently convert all loaded strings from UTF8 to the current locale)
* \todo Support UTF8 (currently convert all loaded strings from UTF8 to the
* current locale)
*/
class GD_CORE_API Direction
{
public:
Direction();
virtual ~Direction();
class GD_CORE_API Direction {
public:
Direction();
virtual ~Direction();
/**
* Return true if sprites looping is activated
*/
inline bool IsLooping() const { return loop; }
/**
* Return true if sprites looping is activated
*/
inline bool IsLooping() const { return loop; }
/**
* Set if the sprites must be looping or not.
*/
void SetLoop(bool loop_);
/**
* Set if the sprites must be looping or not.
*/
void SetLoop(bool loop_);
/**
* Get the time between each sprite
*/
inline float GetTimeBetweenFrames() const { return timeBetweenFrame; }
/**
* Get the time between each sprite
*/
inline float GetTimeBetweenFrames() const { return timeBetweenFrame; }
/**
* Set the time between each sprite
* \param time Time between each sprite, in seconds.
*/
void SetTimeBetweenFrames(float time);
/**
* Set the time between each sprite
* \param time Time between each sprite, in seconds.
*/
void SetTimeBetweenFrames(float time);
/**
* Return a reference to a sprite of the direction.
* \param nb The index of the sprite to be accessed. Bound checking is not made.
* \return A reference to the sprite.
*/
const Sprite & GetSprite(std::size_t nb) const;
/**
* Return a reference to a sprite of the direction.
* \param nb The index of the sprite to be accessed. Bound checking is not
* made. \return A reference to the sprite.
*/
const Sprite& GetSprite(std::size_t nb) const;
/**
* Return a reference to a sprite of the direction.
* \param nb The index of the sprite to be accessed. Bound checking is not made.
* \return A reference to the sprite.
*/
Sprite & GetSprite(std::size_t nb);
/**
* Return a reference to a sprite of the direction.
* \param nb The index of the sprite to be accessed. Bound checking is not
* made. \return A reference to the sprite.
*/
Sprite& GetSprite(std::size_t nb);
/**
* Check if the direction contains sprites.
* \return true if the direction does not have any sprite.
*/
bool HasNoSprites() const;
/**
* Check if the direction contains sprites.
* \return true if the direction does not have any sprite.
*/
bool HasNoSprites() const;
/**
* Return the number of sprite used in the direction
* \return The number of sprite used in the direction
*/
std::size_t GetSpritesCount() const;
/**
* Return the number of sprite used in the direction
* \return The number of sprite used in the direction
*/
std::size_t GetSpritesCount() const;
/**
* Remove the sprite at the specified position.
* Bound-checking is made.
*/
void RemoveSprite(std::size_t index);
/**
* Remove the sprite at the specified position.
* Bound-checking is made.
*/
void RemoveSprite(std::size_t index);
/**
* Clear the direction from all of its sprites
*/
void RemoveAllSprites();
/**
* Clear the direction from all of its sprites
*/
void RemoveAllSprites();
/**
* Add a new sprite at the end of the list.
*/
void AddSprite( const Sprite & sprite );
/**
* Add a new sprite at the end of the list.
*/
void AddSprite(const Sprite& sprite);
/**
* Swap the position of two sprites
*/
void SwapSprites(std::size_t firstSpriteIndex, std::size_t secondSpriteIndex);
/**
* Swap the position of two sprites
*/
void SwapSprites(std::size_t firstSpriteIndex, std::size_t secondSpriteIndex);
/**
* Change the position of the specified sprite.
*/
void MoveSprite(std::size_t oldIndex, std::size_t newIndex);
/**
* Change the position of the specified sprite.
*/
void MoveSprite(std::size_t oldIndex, std::size_t newIndex);
void UnserializeFrom(const gd::SerializerElement & element);
#if defined(GD_IDE_ONLY)
void SerializeTo(gd::SerializerElement & element) const;
#endif
void UnserializeFrom(const gd::SerializerElement& element);
#if defined(GD_IDE_ONLY)
void SerializeTo(gd::SerializerElement& element) const;
#endif
private:
bool loop; ///< true if the animation must loop.
float timeBetweenFrame; ///< The time between each sprite of the animation.
std::vector < Sprite > sprites; ///< The sprites of the direction.
private:
bool loop; ///< true if the animation must loop.
float timeBetweenFrame; ///< The time between each sprite of the animation.
std::vector<Sprite> sprites; ///< The sprites of the direction.
};
}
#endif // GDCORE_DIRECTION_H
} // namespace gd
#endif // GDCORE_DIRECTION_H

View File

@@ -1,17 +1,12 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "GDCore/Extensions/Builtin/SpriteExtension/Point.h"
#include "GDCore/String.h"
Point::Point(const gd::String & name_) :
name(name_),
x(0),
y(0)
{
//ctor
Point::Point(const gd::String& name_) : name(name_), x(0), y(0) {
// ctor
}

View File

@@ -1,7 +1,7 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_POINT_H
@@ -13,52 +13,53 @@
*
* \ingroup SpriteObjectExtension
*/
class GD_CORE_API Point
{
public:
Point(const gd::String & name_);
virtual ~Point() {};
class GD_CORE_API Point {
public:
Point(const gd::String& name_);
virtual ~Point(){};
/**
* Change point name
*/
void SetName(const gd::String & name_) { name = name_; }
/**
* Change point name
*/
void SetName(const gd::String& name_) { name = name_; }
/**
* Get point name
*/
const gd::String & GetName() const { return name; }
/**
* Get point name
*/
const gd::String& GetName() const { return name; }
/**
* Change point position.
*/
void SetXY(float x_, float y_) { x = x_;y = y_; }
/**
* Change point position.
*/
void SetXY(float x_, float y_) {
x = x_;
y = y_;
}
/**
* Change point X position.
*/
void SetX(float x_) { x = x_; }
/**
* Change point X position.
*/
void SetX(float x_) { x = x_; }
/**
* Change point Y position.
*/
void SetY(float y_) { y = y_; }
/**
* Change point Y position.
*/
void SetY(float y_) { y = y_; }
/**
* Get point X position.
*/
float GetX() const { return x; }
/**
* Get point X position.
*/
float GetX() const { return x; }
/**
* Get point Y position.
*/
float GetY() const { return y; }
/**
* Get point Y position.
*/
float GetY() const { return y; }
private:
gd::String name;
float x;
float y;
private:
gd::String name;
float x;
float y;
};
#endif // GDCORE_POINT_H
#endif // GDCORE_POINT_H

View File

@@ -1,93 +1,86 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "Polygon2d.h"
#include <SFML/System/Vector2.hpp>
#include <cmath>
#include <iostream>
#include <SFML/System/Vector2.hpp>
void Polygon2d::Rotate(float angle)
{
float t,
cosa = cos(-angle),
sina = sin(-angle); //We want a clockwise rotation
void Polygon2d::Rotate(float angle) {
float t, cosa = cos(-angle),
sina = sin(-angle); // We want a clockwise rotation
for (std::size_t i = 0;i<vertices.size();++i)
{
t = vertices[i].x;
vertices[i].x = t*cosa + vertices[i].y*sina;
vertices[i].y = -t*sina + vertices[i].y*cosa;
}
for (std::size_t i = 0; i < vertices.size(); ++i) {
t = vertices[i].x;
vertices[i].x = t * cosa + vertices[i].y * sina;
vertices[i].y = -t * sina + vertices[i].y * cosa;
}
}
void Polygon2d::Move(float x, float y)
{
for (std::size_t i = 0; i < vertices.size(); i++)
{
vertices[i].x += x;
vertices[i].y += y;
}
ComputeEdges();
void Polygon2d::Move(float x, float y) {
for (std::size_t i = 0; i < vertices.size(); i++) {
vertices[i].x += x;
vertices[i].y += y;
}
ComputeEdges();
}
void Polygon2d::ComputeEdges() const
{
sf::Vector2f v1, v2;
edges.clear();
void Polygon2d::ComputeEdges() const {
sf::Vector2f v1, v2;
edges.clear();
for (std::size_t i = 0; i < vertices.size(); i++)
{
v1 = vertices[i];
if ((i + 1) >= vertices.size()) v2 = vertices[0];
else v2 = vertices[i + 1];
for (std::size_t i = 0; i < vertices.size(); i++) {
v1 = vertices[i];
if ((i + 1) >= vertices.size())
v2 = vertices[0];
else
v2 = vertices[i + 1];
edges.push_back(v2 - v1);
}
edges.push_back(v2 - v1);
}
}
bool Polygon2d::IsConvex() const
{
ComputeEdges();
if ( edges.size() < 3 ) return false;
bool Polygon2d::IsConvex() const {
ComputeEdges();
if (edges.size() < 3) return false;
bool zProductIsPositive = (edges[0].x*edges[0+1].y - edges[0].y*edges[0+1].x) > 0;
bool zProductIsPositive =
(edges[0].x * edges[0 + 1].y - edges[0].y * edges[0 + 1].x) > 0;
for (std::size_t i = 1;i<edges.size()-1;++i)
{
float zCrossProduct = edges[i].x*edges[i+1].y - edges[i].y*edges[i+1].x;
if ( (zCrossProduct > 0) != zProductIsPositive ) return false;
}
for (std::size_t i = 1; i < edges.size() - 1; ++i) {
float zCrossProduct =
edges[i].x * edges[i + 1].y - edges[i].y * edges[i + 1].x;
if ((zCrossProduct > 0) != zProductIsPositive) return false;
}
float lastZCrossProduct = edges[edges.size()-1].x*edges[0].y - edges[edges.size()-1].y*edges[0].x;
if ( (lastZCrossProduct > 0) != zProductIsPositive ) return false;
float lastZCrossProduct = edges[edges.size() - 1].x * edges[0].y -
edges[edges.size() - 1].y * edges[0].x;
if ((lastZCrossProduct > 0) != zProductIsPositive) return false;
return true;
return true;
}
sf::Vector2f Polygon2d::ComputeCenter() const
{
sf::Vector2f center;
sf::Vector2f Polygon2d::ComputeCenter() const {
sf::Vector2f center;
for (std::size_t i = 0; i < vertices.size(); i++)
{
center.x += vertices[i].x;
center.y += vertices[i].y;
}
center.x /= vertices.size();
center.y /= vertices.size();
for (std::size_t i = 0; i < vertices.size(); i++) {
center.x += vertices[i].x;
center.y += vertices[i].y;
}
center.x /= vertices.size();
center.y /= vertices.size();
return center;
return center;
}
Polygon2d Polygon2d::CreateRectangle(float width, float height)
{
Polygon2d rect;
rect.vertices.push_back(sf::Vector2f(-width/2.0f, -height/2.0f));
rect.vertices.push_back(sf::Vector2f(+width/2.0f, -height/2.0f));
rect.vertices.push_back(sf::Vector2f(+width/2.0f, +height/2.0f));
rect.vertices.push_back(sf::Vector2f(-width/2.0f, +height/2.0f));
Polygon2d Polygon2d::CreateRectangle(float width, float height) {
Polygon2d rect;
rect.vertices.push_back(sf::Vector2f(-width / 2.0f, -height / 2.0f));
rect.vertices.push_back(sf::Vector2f(+width / 2.0f, -height / 2.0f));
rect.vertices.push_back(sf::Vector2f(+width / 2.0f, +height / 2.0f));
rect.vertices.push_back(sf::Vector2f(-width / 2.0f, +height / 2.0f));
return rect;
return rect;
}

View File

@@ -1,81 +1,84 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_POLYGON_H
#define GDCORE_POLYGON_H
#include <vector>
#include <SFML/System/Vector2.hpp>
#include <vector>
/**
* \brief Represents a polygon. Usually used for collisions masks.
*
* This class stores the vertices of the polygon.
* It can also compute and store the edges ( needed by some collisions algorithms ) if ComputeEdges is called.
* It can also compute and store the edges ( needed by some collisions
* algorithms ) if ComputeEdges is called.
*
* \ingroup GameEngine
*/
class GD_CORE_API Polygon2d
{
public:
Polygon2d() {};
virtual ~Polygon2d() {};
class GD_CORE_API Polygon2d {
public:
Polygon2d(){};
virtual ~Polygon2d(){};
std::vector<sf::Vector2f> vertices; ///< The vertices composing the polygon
mutable std::vector<sf::Vector2f> edges; ///< Edges. Can be computed from vertices using ComputeEdges()
std::vector<sf::Vector2f> vertices; ///< The vertices composing the polygon
mutable std::vector<sf::Vector2f>
edges; ///< Edges. Can be computed from vertices using ComputeEdges()
/**
* \brief Get the vertices composing the polygon.
*/
std::vector<sf::Vector2f> & GetVertices() { return vertices; }
/**
* \brief Get the vertices composing the polygon.
*/
std::vector<sf::Vector2f>& GetVertices() { return vertices; }
/**
* \brief Get the vertices composing the polygon.
*/
const std::vector<sf::Vector2f> & GetVertices() const { return vertices; }
/**
* \brief Get the vertices composing the polygon.
*/
const std::vector<sf::Vector2f>& GetVertices() const { return vertices; }
/**
* \brief Moves each vertices from the given amount.
*
* \note Edges are updated, there is no need to call ComputeEdges after calling Move.
*/
void Move(float x, float y);
/**
* \brief Moves each vertices from the given amount.
*
* \note Edges are updated, there is no need to call ComputeEdges after
* calling Move.
*/
void Move(float x, float y);
/**
* \brief Rotate the polygon.
* \param angle Angle in radians
*
* \warning Rotation is made clockwise
* \warning edges vector is not updated, you have to call ComputeEdges if needed.
*/
void Rotate(float angle);
/**
* \brief Rotate the polygon.
* \param angle Angle in radians
*
* \warning Rotation is made clockwise
* \warning edges vector is not updated, you have to call ComputeEdges if
* needed.
*/
void Rotate(float angle);
/**
* \brief Automatically fill edges vector using vertices.
*/
void ComputeEdges() const;
/**
* \brief Automatically fill edges vector using vertices.
*/
void ComputeEdges() const;
/**
* \brief Check if the polygon is convex.
* \return true if the polygon is convex
*/
bool IsConvex() const;
/**
* \brief Check if the polygon is convex.
* \return true if the polygon is convex
*/
bool IsConvex() const;
/**
* \brief Return the position of the center of the polygon
*/
sf::Vector2f ComputeCenter() const;
/**
* \brief Return the position of the center of the polygon
*/
sf::Vector2f ComputeCenter() const;
/** \name Tools
* Tool functions
*/
///@{
/**
* \brief Create a rectangle
*/
static Polygon2d CreateRectangle(float width, float height);
///@}
/** \name Tools
* Tool functions
*/
///@{
/**
* \brief Create a rectangle
*/
static Polygon2d CreateRectangle(float width, float height);
///@}
};
#endif // GDCORE_POLYGON_H
#endif // GDCORE_POLYGON_H

View File

@@ -1,153 +1,135 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "GDCore/Extensions/Builtin/SpriteExtension/Polygon2d.h"
#include "GDCore/Extensions/Builtin/SpriteExtension/Sprite.h"
#include "GDCore/Project/ImageManager.h"
#include <SFML/Graphics/Sprite.hpp>
#include <iostream>
#include "GDCore/Extensions/Builtin/SpriteExtension/Polygon2d.h"
#include "GDCore/Project/ImageManager.h"
using namespace std;
namespace gd
{
namespace gd {
Point Sprite::badPoint("");
Sprite::Sprite() :
Sprite::Sprite()
:
#if !defined(EMSCRIPTEN)
hasItsOwnImage(false),
hasItsOwnImage(false),
#endif
automaticCollisionMask(true),
origine("origine"),
centre("centre"),
automaticCentre(true)
{
automaticCollisionMask(true),
origine("origine"),
centre("centre"),
automaticCentre(true) {
}
Sprite::~Sprite()
{
};
Sprite::~Sprite(){};
void Sprite::AddPoint( const Point & point )
{
if ( !HasPoint(point.GetName()))
points.push_back(point);
void Sprite::AddPoint(const Point& point) {
if (!HasPoint(point.GetName())) points.push_back(point);
}
void Sprite::DelPoint( const gd::String & name )
{
for (std::size_t i = 0;i<points.size();++i)
{
if ( name == points[i].GetName() )
points.erase(points.begin() + i);
}
void Sprite::DelPoint(const gd::String& name) {
for (std::size_t i = 0; i < points.size(); ++i) {
if (name == points[i].GetName()) points.erase(points.begin() + i);
}
}
bool Sprite::HasPoint( const gd::String & name ) const
{
if (name == "Origin") return true;
if (name == "Centre" || name == "Center") return true;
bool Sprite::HasPoint(const gd::String& name) const {
if (name == "Origin") return true;
if (name == "Centre" || name == "Center") return true;
for (std::size_t i = 0;i<points.size();++i)
{
if ( name == points[i].GetName() )
return true;
}
for (std::size_t i = 0; i < points.size(); ++i) {
if (name == points[i].GetName()) return true;
}
return false;
return false;
}
const Point & Sprite::GetPoint( const gd::String & name) const
{
if (name == "Origin") return origine;
if (name == "Centre" || name == "Center") return centre;
const Point& Sprite::GetPoint(const gd::String& name) const {
if (name == "Origin") return origine;
if (name == "Centre" || name == "Center") return centre;
for (std::size_t i = 0;i<points.size();++i)
{
if ( name == points[i].GetName() )
return points[i];
}
for (std::size_t i = 0; i < points.size(); ++i) {
if (name == points[i].GetName()) return points[i];
}
return badPoint;
return badPoint;
}
Point & Sprite::GetPoint(const gd::String & name)
{
if (name == "Origin") return origine;
if (name == "Centre" || name == "Center") return centre;
Point& Sprite::GetPoint(const gd::String& name) {
if (name == "Origin") return origine;
if (name == "Centre" || name == "Center") return centre;
for (std::size_t i = 0;i<points.size();++i)
{
if ( name == points[i].GetName() )
return points[i];
}
for (std::size_t i = 0; i < points.size(); ++i) {
if (name == points[i].GetName()) return points[i];
}
return badPoint;
return badPoint;
}
bool Sprite::SetDefaultCenterPoint(bool enabled) {
automaticCentre = enabled;
bool Sprite::SetDefaultCenterPoint(bool enabled)
{
automaticCentre = enabled;
#if !defined(EMSCRIPTEN)
if ( automaticCentre )
centre.SetXY(sfmlSprite.getLocalBounds().width/2, sfmlSprite.getLocalBounds().height/2);
#endif
return true;
}
std::vector<Polygon2d> Sprite::GetCollisionMask() const
{
//TODO(perf): Cache to avoid re-creating a mask at every call
#if !defined(EMSCRIPTEN)
if ( automaticCollisionMask )
{
std::vector<Polygon2d> mask;
Polygon2d rectangle;
rectangle.vertices.push_back(sf::Vector2f(0, 0));
rectangle.vertices.push_back(sf::Vector2f(sfmlSprite.getLocalBounds().width, 0));
rectangle.vertices.push_back(sf::Vector2f(sfmlSprite.getLocalBounds().width, sfmlSprite.getLocalBounds().height));
rectangle.vertices.push_back(sf::Vector2f(0, sfmlSprite.getLocalBounds().height));
mask.push_back(rectangle);
return mask;
}
if (automaticCentre)
centre.SetXY(sfmlSprite.getLocalBounds().width / 2,
sfmlSprite.getLocalBounds().height / 2);
#endif
return customCollisionMask;
return true;
}
void Sprite::SetCustomCollisionMask(const std::vector<Polygon2d> & collisionMask)
{
customCollisionMask = collisionMask;
std::vector<Polygon2d> Sprite::GetCollisionMask() const {
// TODO(perf): Cache to avoid re-creating a mask at every call
#if !defined(EMSCRIPTEN)
if (automaticCollisionMask) {
std::vector<Polygon2d> mask;
Polygon2d rectangle;
rectangle.vertices.push_back(sf::Vector2f(0, 0));
rectangle.vertices.push_back(
sf::Vector2f(sfmlSprite.getLocalBounds().width, 0));
rectangle.vertices.push_back(sf::Vector2f(
sfmlSprite.getLocalBounds().width, sfmlSprite.getLocalBounds().height));
rectangle.vertices.push_back(
sf::Vector2f(0, sfmlSprite.getLocalBounds().height));
mask.push_back(rectangle);
return mask;
}
#endif
return customCollisionMask;
}
void Sprite::SetCustomCollisionMask(
const std::vector<Polygon2d>& collisionMask) {
customCollisionMask = collisionMask;
}
#if !defined(EMSCRIPTEN)
void Sprite::LoadImage(std::shared_ptr<SFMLTextureWrapper> image_)
{
sfmlImage = image_;
sfmlSprite.setTexture(sfmlImage->texture, true);
hasItsOwnImage = false;
void Sprite::LoadImage(std::shared_ptr<SFMLTextureWrapper> image_) {
sfmlImage = image_;
sfmlSprite.setTexture(sfmlImage->texture, true);
hasItsOwnImage = false;
if ( automaticCentre )
centre.SetXY(sfmlSprite.getLocalBounds().width/2, sfmlSprite.getLocalBounds().height/2);
if (automaticCentre)
centre.SetXY(sfmlSprite.getLocalBounds().width / 2,
sfmlSprite.getLocalBounds().height / 2);
}
void Sprite::MakeSpriteOwnsItsImage()
{
if ( !hasItsOwnImage || sfmlImage == std::shared_ptr<SFMLTextureWrapper>() )
{
sfmlImage = std::make_shared<SFMLTextureWrapper>(sfmlImage->texture); //Copy the texture.
sfmlSprite.setTexture(sfmlImage->texture);
hasItsOwnImage = true;
}
void Sprite::MakeSpriteOwnsItsImage() {
if (!hasItsOwnImage || sfmlImage == std::shared_ptr<SFMLTextureWrapper>()) {
sfmlImage = std::make_shared<SFMLTextureWrapper>(
sfmlImage->texture); // Copy the texture.
sfmlSprite.setTexture(sfmlImage->texture);
hasItsOwnImage = true;
}
}
#endif
}
} // namespace gd

View File

@@ -1,21 +1,20 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef SPRITE_H
#define SPRITE_H
#include "GDCore/String.h"
#include <memory>
#include <SFML/Graphics/Sprite.hpp>
#include <memory>
#include "GDCore/Extensions/Builtin/SpriteExtension/Point.h"
#include "GDCore/Extensions/Builtin/SpriteExtension/Polygon2d.h"
#include "GDCore/String.h"
class SFMLTextureWrapper;
#undef LoadImage //prevent windows.h to be polluting everything
#undef LoadImage // prevent windows.h to be polluting everything
namespace gd
{
namespace gd {
/**
* \brief Represents a sprite to be displayed on the screen.
@@ -27,190 +26,205 @@ namespace gd
* \see SpriteObject
* \ingroup SpriteObjectExtension
*/
class GD_CORE_API Sprite
{
public:
Sprite();
virtual ~Sprite();
class GD_CORE_API Sprite {
public:
Sprite();
virtual ~Sprite();
/**
* \brief Change the name of the sprite image.
*/
inline void SetImageName(const gd::String & image_) { image = image_; }
/**
* \brief Change the name of the sprite image.
*/
inline void SetImageName(const gd::String& image_) { image = image_; }
/**
* \brief Get the name of the sprite image.
*/
inline const gd::String & GetImageName() const { return image; }
/**
* \brief Get the name of the sprite image.
*/
inline const gd::String& GetImageName() const { return image; }
/**
* \brief Get the name of the sprite image.
*/
inline gd::String & GetImageName() { return image; }
/**
* \brief Get the name of the sprite image.
*/
inline gd::String& GetImageName() { return image; }
/**
* \brief Get the collision mask (custom or automatically generated owing to IsCollisionMaskAutomatic())
*
* \warning If the image has not been loaded ( using LoadImage ) and the collision mask is set as automatic,
* the returned mask won't be correct.
*/
std::vector<Polygon2d> GetCollisionMask() const;
/**
* \brief Get the collision mask (custom or automatically generated owing to
* IsCollisionMaskAutomatic())
*
* \warning If the image has not been loaded ( using LoadImage ) and the
* collision mask is set as automatic, the returned mask won't be correct.
*/
std::vector<Polygon2d> GetCollisionMask() const;
/**
* \brief Get the custom collision mask.
*/
std::vector<Polygon2d> & GetCustomCollisionMask() { return customCollisionMask; };
/**
* \brief Get the custom collision mask.
*/
std::vector<Polygon2d>& GetCustomCollisionMask() {
return customCollisionMask;
};
/**
* \brief Get the custom collision mask.
*/
const std::vector<Polygon2d> & GetCustomCollisionMask() const { return customCollisionMask; };
/**
* \brief Get the custom collision mask.
*/
const std::vector<Polygon2d>& GetCustomCollisionMask() const {
return customCollisionMask;
};
/**
* \brief Set the custom collision mask.
* Call then `SetCollisionMaskAutomatic(false)` to use it.
*/
void SetCustomCollisionMask(const std::vector<Polygon2d> & collisionMask);
/**
* \brief Set the custom collision mask.
* Call then `SetCollisionMaskAutomatic(false)` to use it.
*/
void SetCustomCollisionMask(const std::vector<Polygon2d>& collisionMask);
/**
* \brief Return true if the collision mask is a bounding box, false if a custom collision mask is used.
*/
inline bool IsCollisionMaskAutomatic() const { return automaticCollisionMask; }
/**
* \brief Return true if the collision mask is a bounding box, false if a
* custom collision mask is used.
*/
inline bool IsCollisionMaskAutomatic() const {
return automaticCollisionMask;
}
/**
* \brief Un/set use of the custom collision mask.
*/
inline void SetCollisionMaskAutomatic(bool enabled) { automaticCollisionMask = enabled; };
/**
* \brief Un/set use of the custom collision mask.
*/
inline void SetCollisionMaskAutomatic(bool enabled) {
automaticCollisionMask = enabled;
};
/**
* \brief Return all points, excluding origin and center.
*/
inline std::vector < Point > & GetAllNonDefaultPoints() { return points; }
/**
* \brief Return all points, excluding origin and center.
*/
inline std::vector<Point>& GetAllNonDefaultPoints() { return points; }
/**
* \brief Return all points, excluding origin and center.
*/
inline const std::vector < Point > & GetAllNonDefaultPoints() const { return points; }
/**
* \brief Return all points, excluding origin and center.
*/
inline const std::vector<Point>& GetAllNonDefaultPoints() const {
return points;
}
/**
* \brief Add a point
*/
void AddPoint( const Point & point );
/**
* \brief Add a point
*/
void AddPoint(const Point& point);
/**
* \brief Delete a point
*/
void DelPoint( const gd::String & name );
/**
* \brief Delete a point
*/
void DelPoint(const gd::String& name);
/**
* \brief Get the specified point.
*/
const Point & GetPoint( const gd::String & name) const;
/**
* \brief Get the specified point.
*/
const Point& GetPoint(const gd::String& name) const;
/**
* \brief Get the specified point.
*/
Point & GetPoint(const gd::String & name);
/**
* \brief Get the specified point.
*/
Point& GetPoint(const gd::String& name);
/**
* \brief Return true if the point exists.
*/
bool HasPoint( const gd::String & name ) const;
/**
* \brief Return true if the point exists.
*/
bool HasPoint(const gd::String& name) const;
/**
* \brief Return Origin point.
*/
inline const Point & GetOrigin() const { return origine; }
/**
* \brief Return Origin point.
*/
inline const Point& GetOrigin() const { return origine; }
/**
* \brief Return Origin point.
*/
inline Point & GetOrigin() { return origine; }
/**
* \brief Return Origin point.
*/
inline Point& GetOrigin() { return origine; }
/**
* \brief Return Center point.
*
* \warning If the image has not been loaded (using LoadImage) and the center point is set as automatic,
* the returned point won't be correct.
*/
inline const Point & GetCenter() const { return centre; }
/**
* \brief Return Center point.
*
* \warning If the image has not been loaded (using LoadImage) and the center
* point is set as automatic, the returned point won't be correct.
*/
inline const Point& GetCenter() const { return centre; }
/**
* \brief Return Center point.
*
* \warning If the image has not been loaded (using LoadImage) and the center point is set as automatic,
* the returned point won't be correct.
*/
inline Point & GetCenter() { return centre; }
/**
* \brief Return Center point.
*
* \warning If the image has not been loaded (using LoadImage) and the center
* point is set as automatic, the returned point won't be correct.
*/
inline Point& GetCenter() { return centre; }
/**
* \brief Return true if the center point is automatically computed.
*/
inline bool IsDefaultCenterPoint() const { return automaticCentre; }
/**
* \brief Return true if the center point is automatically computed.
*/
inline bool IsDefaultCenterPoint() const { return automaticCentre; }
/**
* \brief Un/set center as being automatically computed.
*/
bool SetDefaultCenterPoint(bool enabled);
/**
* \brief Un/set center as being automatically computed.
*/
bool SetDefaultCenterPoint(bool enabled);
#if !defined(EMSCRIPTEN)
/** \name Sprite runtime management
* Functions used by the C++ game engine.
*/
///@{
/**
* \brief Get the SFML sprite associated with the sprite
*/
inline const sf::Sprite & GetSFMLSprite() const { return sfmlSprite; }
#if !defined(EMSCRIPTEN)
/** \name Sprite runtime management
* Functions used by the C++ game engine.
*/
///@{
/**
* \brief Get the SFML sprite associated with the sprite
*/
inline const sf::Sprite& GetSFMLSprite() const { return sfmlSprite; }
/**
* \brief Get the SFML sprite associated with the sprite
*/
inline sf::Sprite & GetSFMLSprite() { return sfmlSprite; }
/**
* \brief Get the SFML sprite associated with the sprite
*/
inline sf::Sprite& GetSFMLSprite() { return sfmlSprite; }
/**
* \brief Set the SFML texture of the sprite
*/
void LoadImage(std::shared_ptr<SFMLTextureWrapper> image);
/**
* \brief Set the SFML texture of the sprite
*/
void LoadImage(std::shared_ptr<SFMLTextureWrapper> image);
/**
* \brief Get SFML texture used by the sprite
*/
std::shared_ptr<SFMLTextureWrapper> GetSFMLTexture() { return sfmlImage; };
/**
* \brief Get SFML texture used by the sprite
*/
std::shared_ptr<SFMLTextureWrapper> GetSFMLTexture() { return sfmlImage; };
/**
* \brief Get SFML texture used by the sprite
*/
const std::shared_ptr<SFMLTextureWrapper> GetSFMLTexture() const { return sfmlImage; };
/**
* \brief Get SFML texture used by the sprite
*/
const std::shared_ptr<SFMLTextureWrapper> GetSFMLTexture() const {
return sfmlImage;
};
/**
* \brief Make the sprite, if it uses a texture from ImageManager,
* copy this texture and take ownership of it.
*/
void MakeSpriteOwnsItsImage();
///@}
#endif
/**
* \brief Make the sprite, if it uses a texture from ImageManager,
* copy this texture and take ownership of it.
*/
void MakeSpriteOwnsItsImage();
///@}
#endif
private:
private:
#if !defined(EMSCRIPTEN)
sf::Sprite sfmlSprite; ///< Displayed SFML sprite
std::shared_ptr<SFMLTextureWrapper>
sfmlImage; ///< Pointer to the image displayed by the sprite.
bool hasItsOwnImage; ///< True if sfmlImage is only owned by this Sprite.
#endif
gd::String image; ///< Name of the image to be loaded in Image Manager.
#if !defined(EMSCRIPTEN)
sf::Sprite sfmlSprite; ///< Displayed SFML sprite
std::shared_ptr<SFMLTextureWrapper> sfmlImage; ///< Pointer to the image displayed by the sprite.
bool hasItsOwnImage; ///< True if sfmlImage is only owned by this Sprite.
#endif
gd::String image; ///< Name of the image to be loaded in Image Manager.
bool automaticCollisionMask; ///< True to use the custom collision mask.
///< Otherwise, a basic bounding box is returned
///< by GetCollisionMask()
std::vector<Polygon2d> customCollisionMask; ///< Custom collision mask
bool automaticCollisionMask; ///< True to use the custom collision mask. Otherwise, a basic bounding box is returned by GetCollisionMask()
std::vector<Polygon2d> customCollisionMask; ///< Custom collision mask
std::vector<Point> points; ///< List of the points used by the sprite
Point origine; ///< Origin point
Point centre; ///< Center point
bool automaticCentre; ///< True to let the sprite compute its center
std::vector < Point > points; ///< List of the points used by the sprite
Point origine; ///< Origin point
Point centre; ///< Center point
bool automaticCentre; ///< True to let the sprite compute its center
static Point badPoint; ///< Returned when no other valid Point object is available.
static Point
badPoint; ///< Returned when no other valid Point object is available.
};
}
#endif // SPRITE_H
} // namespace gd
#endif // SPRITE_H

View File

@@ -1,213 +1,220 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the GNU Lesser General Public LicenFse.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the GNU Lesser General Public
* LicenFse.
*/
#include "GDCore/Extensions/Builtin/AllBuiltinExtensions.h"
#include "GDCore/Tools/Localization.h"
#include "GDCore/Project/Object.h"
#include "GDCore/Extensions/Builtin/SpriteExtension/SpriteObject.h"
#include "GDCore/Project/Object.h"
#include "GDCore/Tools/Localization.h"
using namespace std;
namespace gd
{
namespace gd {
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsSpriteExtension(gd::PlatformExtension & extension)
{
extension.SetExtensionInformation("Sprite",
_("Sprite"),
_("Extension for adding animated objects in the scene, which can contain animations with directions within each."),
"Florian Rival",
"Open source (MIT License)");
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsSpriteExtension(
gd::PlatformExtension& extension) {
extension.SetExtensionInformation(
"Sprite",
_("Sprite"),
_("Extension for adding animated objects in the scene, which can contain "
"animations with directions within each."),
"Florian Rival",
"Open source (MIT License)");
gd::ObjectMetadata & obj = extension.AddObject<SpriteObject>(
"Sprite",
_("Sprite"),
_("Animated object which can be used for most elements of a game"),
"CppPlatform/Extensions/spriteicon.png");
gd::ObjectMetadata& obj = extension.AddObject<SpriteObject>(
"Sprite",
_("Sprite"),
_("Animated object which can be used for most elements of a game"),
"CppPlatform/Extensions/spriteicon.png");
#if defined(GD_IDE_ONLY)
obj.AddAction("Opacity",
_("Change object's opacity"),
_("Change the opacity of an object."),
_("Do _PARAM1__PARAM2_ to the opacity of _PARAM0_"),
_("Visibility"),
"res/actions/opacity24.png",
"res/actions/opacity.png")
#if defined(GD_IDE_ONLY)
obj.AddAction("Opacity",
_("Change object's opacity"),
_("Change the opacity of an object."),
_("Do _PARAM1__PARAM2_ to the opacity of _PARAM0_"),
_("Visibility"),
"res/actions/opacity24.png",
"res/actions/opacity.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsSimple()
.SetManipulatedType("number");
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsSimple()
.SetManipulatedType("number");
obj.AddAction("ChangeAnimation",
_("Change the animation"),
_("Change the animation of the object, using the animation number in the animations list."),
_("Do _PARAM1__PARAM2_ to the number of current animation of _PARAM0_"),
_("Animations and images"),
"res/actions/animation24.png",
"res/actions/animation.png")
obj.AddAction("ChangeAnimation",
_("Change the animation"),
_("Change the animation of the object, using the animation "
"number in the animations list."),
_("Do _PARAM1__PARAM2_ to the number of current animation of "
"_PARAM0_"),
_("Animations and images"),
"res/actions/animation24.png",
"res/actions/animation.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsSimple()
.SetManipulatedType("number");
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsSimple()
.SetManipulatedType("number");
obj.AddAction("SetAnimationName",
_("Change the animation (by name)"),
_("Change the animation of the object, using the name of the animation."),
_("Set animation of _PARAM0_ to _PARAM1_"),
_("Animations and images"),
"res/actions/animation24.png",
"res/actions/animation.png")
obj.AddAction("SetAnimationName",
_("Change the animation (by name)"),
_("Change the animation of the object, using the name of the "
"animation."),
_("Set animation of _PARAM0_ to _PARAM1_"),
_("Animations and images"),
"res/actions/animation24.png",
"res/actions/animation.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("string", _("Animation name"))
.MarkAsAdvanced();
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("string", _("Animation name"))
.MarkAsAdvanced();
obj.AddAction("ChangeDirection",
_("Change the direction"),
_("Change the direction of the object.\nIf the object is set to automatically rotate, the direction is its angle.\nIf the object is in 8 directions mode, the valid directions are 0..7"),
_("Do _PARAM1__PARAM2_ to the direction of _PARAM0_"),
_("Direction"),
"res/actions/direction24.png",
"res/actions/direction.png")
obj.AddAction(
"ChangeDirection",
_("Change the direction"),
_("Change the direction of the object.\nIf the object is set to "
"automatically rotate, the direction is its angle.\nIf the object "
"is in 8 directions mode, the valid directions are 0..7"),
_("Do _PARAM1__PARAM2_ to the direction of _PARAM0_"),
_("Direction"),
"res/actions/direction24.png",
"res/actions/direction.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
obj.AddAction("ChangeSprite",
_("Current frame"),
_("Modify the current frame of the object"),
_("Do _PARAM1__PARAM2_ to animation frame of _PARAM0_"),
_("Animations and images"),
"res/actions/sprite24.png",
"res/actions/sprite.png")
obj.AddAction("ChangeSprite",
_("Current frame"),
_("Modify the current frame of the object"),
_("Do _PARAM1__PARAM2_ to animation frame of _PARAM0_"),
_("Animations and images"),
"res/actions/sprite24.png",
"res/actions/sprite.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
obj.AddAction("PauseAnimation",
_("Pause the animation"),
_("Pause the current animation of the object"),
_("Pause the current animation of _PARAM0_"),
_("Animations and images"),
"res/actions/animation24.png",
"res/actions/animation.png")
obj.AddAction("PauseAnimation",
_("Pause the animation"),
_("Pause the current animation of the object"),
_("Pause the current animation of _PARAM0_"),
_("Animations and images"),
"res/actions/animation24.png",
"res/actions/animation.png")
.AddParameter("object", _("Object"), "Sprite")
.MarkAsSimple();
.AddParameter("object", _("Object"), "Sprite")
.MarkAsSimple();
obj.AddAction("PlayAnimation",
_("Play the animation"),
_("Play the current animation of the object"),
_("Play the current animation of _PARAM0_"),
_("Animations and images"),
"res/actions/animation24.png",
"res/actions/animation.png")
.AddParameter("object", _("Object"), "Sprite")
.MarkAsSimple();
obj.AddAction("PlayAnimation",
_("Play the animation"),
_("Play the current animation of the object"),
_("Play the current animation of _PARAM0_"),
_("Animations and images"),
"res/actions/animation24.png",
"res/actions/animation.png")
obj.AddAction(
"ChangeAnimationSpeedScale",
_("Animation speed scale"),
_("Modify the animation speed scale (1 = the default speed, >1 = "
"faster and <1 = slower)."),
_("Do _PARAM1__PARAM2_ to the animation speed scale of _PARAM0_"),
_("Animations and images"),
"res/actions/animation24.png",
"res/actions/animation.png")
.AddParameter("object", _("Object"), "Sprite")
.MarkAsSimple();
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsSimple()
.SetManipulatedType("number");
obj.AddAction("ChangeAnimationSpeedScale",
_("Animation speed scale"),
_("Modify the animation speed scale (1 = the default speed, >1 = faster and <1 = slower)."),
_("Do _PARAM1__PARAM2_ to the animation speed scale of _PARAM0_"),
_("Animations and images"),
"res/actions/animation24.png",
"res/actions/animation.png")
obj.AddAction("TourneVersPos",
_("Rotate an object toward a position"),
_("Rotate an object towards a position."),
_("Rotate _PARAM0_ towards _PARAM1_;_PARAM2_"),
_("Direction"),
"res/actions/direction24.png",
"res/actions/direction.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsSimple()
.SetManipulatedType("number");
.AddParameter("object", _("Object to be rotated"), "Sprite")
.AddParameter("expression", _("X position"))
.AddParameter("expression", _("Y position"))
.AddParameter("expression", _("Angular speed (degrees per second)"))
.SetDefaultValue("0")
.AddCodeOnlyParameter("currentScene", "")
.SetHidden(); // Deprecated
obj.AddAction("TourneVersPos",
_("Rotate an object toward a position"),
_("Rotate an object towards a position."),
_("Rotate _PARAM0_ towards _PARAM1_;_PARAM2_"),
_("Direction"),
"res/actions/direction24.png",
"res/actions/direction.png")
obj.AddAction("ChangeScale",
_("Scale"),
_("Modify the scale of the specified object."),
_("Do _PARAM1__PARAM2_ to the scale of _PARAM0_"),
_("Size"),
"res/actions/scale24.png",
"res/actions/scale.png")
.AddParameter("object", _("Object to be rotated"), "Sprite")
.AddParameter("expression", _("X position"))
.AddParameter("expression", _("Y position"))
.AddParameter("expression", _("Angular speed (degrees per second)")).SetDefaultValue("0")
.AddCodeOnlyParameter("currentScene", "")
.SetHidden(); //Deprecated
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced();
obj.AddAction("ChangeScaleWidth",
_("Scale on X axis"),
_("Modify the scale of the width of an object."),
_("Do _PARAM1__PARAM2_ to the width's scale of _PARAM0_"),
_("Size"),
"res/actions/scale24.png",
"res/actions/scale.png")
obj.AddAction("ChangeScale",
_("Scale"),
_("Modify the scale of the specified object."),
_("Do _PARAM1__PARAM2_ to the scale of _PARAM0_"),
_("Size"),
"res/actions/scale24.png",
"res/actions/scale.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced();
obj.AddAction("ChangeScaleHeight",
_("Scale on Y axis"),
_("Modify the scale of the height of an object."),
_("Do _PARAM1__PARAM2_ to the height's scale of _PARAM0_"),
_("Size"),
"res/actions/scale24.png",
"res/actions/scale.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
obj.AddAction("ChangeScaleWidth",
_("Scale on X axis"),
_("Modify the scale of the width of an object."),
_("Do _PARAM1__PARAM2_ to the width's scale of _PARAM0_"),
_("Size"),
"res/actions/scale24.png",
"res/actions/scale.png")
obj.AddCondition(
"Animation",
_("Current animation"),
_("Compare the number of the current animation of the object."),
_("The number of the current animation of _PARAM0_ is "
"_PARAM1__PARAM2_"),
_("Animations and images"),
"res/conditions/animation24.png",
"res/conditions/animation.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Number to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
obj.AddAction("ChangeScaleHeight",
_("Scale on Y axis"),
_("Modify the scale of the height of an object."),
_("Do _PARAM1__PARAM2_ to the height's scale of _PARAM0_"),
_("Size"),
"res/actions/scale24.png",
"res/actions/scale.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
obj.AddCondition("Animation",
_("Current animation"),
_("Compare the number of the current animation of the object."),
_("The number of the current animation of _PARAM0_ is _PARAM1__PARAM2_"),
_("Animations and images"),
"res/conditions/animation24.png",
"res/conditions/animation.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Number to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
obj.AddCondition("AnimationName",
obj.AddCondition("AnimationName",
_("Current animation name"),
_("Check the current animation of the object."),
_("The animation of _PARAM0_ is _PARAM1_"),
@@ -215,24 +222,27 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsSpriteExtension(gd::Pla
"res/conditions/animation24.png",
"res/conditions/animation.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("string", _("Animation name"))
.MarkAsAdvanced();
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("string", _("Animation name"))
.MarkAsAdvanced();
obj.AddCondition("Direction",
_("Current direction"),
_("Compare the direction of the object. If 8 direction mode is activated for the sprite, the value taken for direction will be from 0 to 7. Otherwise, the direction is in degrees."),
_("Direction of _PARAM0_ is _PARAM1__PARAM2_"),
_("Direction"),
"res/conditions/direction24.png",
"res/conditions/direction.png")
obj.AddCondition(
"Direction",
_("Current direction"),
_("Compare the direction of the object. If 8 direction mode is "
"activated for the sprite, the value taken for direction will be "
"from 0 to 7. Otherwise, the direction is in degrees."),
_("Direction of _PARAM0_ is _PARAM1__PARAM2_"),
_("Direction"),
"res/conditions/direction24.png",
"res/conditions/direction.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Direction to test"))
.SetManipulatedType("number");
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Direction to test"))
.SetManipulatedType("number");
obj.AddCondition("Sprite",
obj.AddCondition("Sprite",
_("Current frame"),
_("Test the number of the current animation frame."),
_("The animation frame of _PARAM0_ is _PARAM1__PARAM2_"),
@@ -240,13 +250,13 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsSpriteExtension(gd::Pla
"res/conditions/sprite24.png",
"res/conditions/sprite.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Animation frame to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Animation frame to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
obj.AddCondition("AnimStopped",
obj.AddCondition("AnimStopped",
_("Animation paused"),
_("Test if the animation of an object is paused"),
_("The animation of _PARAM0_ is paused"),
@@ -254,21 +264,22 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsSpriteExtension(gd::Pla
"res/conditions/animation24.png",
"res/conditions/animation.png")
.AddParameter("object", _("Object"), "Sprite")
.MarkAsSimple();
.AddParameter("object", _("Object"), "Sprite")
.MarkAsSimple();
obj.AddCondition("AnimationEnded",
obj.AddCondition("AnimationEnded",
_("Animation finished"),
_("Check if the animation being played by the Sprite object is finished."),
_("Check if the animation being played by the Sprite object "
"is finished."),
_("The animation of _PARAM0_ is finished"),
_("Animations and images"),
"res/conditions/animation24.png",
"res/conditions/animation.png")
.AddParameter("object", _("Object"), "Sprite")
.MarkAsSimple();
.AddParameter("object", _("Object"), "Sprite")
.MarkAsSimple();
obj.AddCondition("ScaleWidth",
obj.AddCondition("ScaleWidth",
_("Scale on X axis"),
_("Compare the scale of the width of an object."),
_("The width's scale of _PARAM0_ is _PARAM1__PARAM2_"),
@@ -276,13 +287,13 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsSpriteExtension(gd::Pla
"res/conditions/scaleWidth24.png",
"res/conditions/scaleWidth.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
obj.AddCondition("ScaleHeight",
obj.AddCondition("ScaleHeight",
_("Scale on Y axis"),
_("Compare the scale of the height of an object."),
_("The height's scale of _PARAM0_ is _PARAM1__PARAM2_"),
@@ -290,118 +301,128 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsSpriteExtension(gd::Pla
"res/conditions/scaleHeight24.png",
"res/conditions/scaleHeight.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
obj.AddCondition("Opacity",
obj.AddCondition("Opacity",
_("Opacity"),
_("Compare the opacity of an object, between 0 (fully transparent) to 255 (opaque)"),
_("Compare the opacity of an object, between 0 (fully "
"transparent) to 255 (opaque)"),
_("The opacity of _PARAM0_ is _PARAM1__PARAM2_"),
_("Visibility"),
"res/conditions/opacity24.png",
"res/conditions/opacity.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.MarkAsSimple()
.SetManipulatedType("number");
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.MarkAsSimple()
.SetManipulatedType("number");
obj.AddCondition("BlendMode",
_("Blend mode"),
_("Compare the number of the blend mode currently used by an object"),
_("The number of the current blend mode of _PARAM0_ is _PARAM1__PARAM2_"),
_("Effects"),
"res/conditions/opacity24.png",
"res/conditions/opacity.png")
obj.AddCondition(
"BlendMode",
_("Blend mode"),
_("Compare the number of the blend mode currently used by an object"),
_("The number of the current blend mode of _PARAM0_ is "
"_PARAM1__PARAM2_"),
_("Effects"),
"res/conditions/opacity24.png",
"res/conditions/opacity.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test (0: Alpha, 1: Add, 2: Multiply, 3: None)"))
.MarkAsAdvanced()
.SetManipulatedType("number");
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression",
_("Value to test (0: Alpha, 1: Add, 2: Multiply, 3: None)"))
.MarkAsAdvanced()
.SetManipulatedType("number");
obj.AddAction("CopyImageOnImageOfSprite",
_("Copy an image on the current one of an object"),
_("Copy an image on the current image of an object.\nNote that the source image must be preferably kept loaded in memory."),
_("Copy image _PARAM2_ on the current of _PARAM0_ at _PARAM3_;_PARAM4_"),
_("Effects"),
"res/copy24.png",
"res/copyicon.png")
obj.AddAction("CopyImageOnImageOfSprite",
_("Copy an image on the current one of an object"),
_("Copy an image on the current image of an object.\nNote that "
"the source image must be preferably kept loaded in memory."),
_("Copy image _PARAM2_ on the current of _PARAM0_ at "
"_PARAM3_;_PARAM4_"),
_("Effects"),
"res/copy24.png",
"res/copyicon.png")
.AddParameter("object", _("Object"), "Sprite")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Name of the source image"))
.AddParameter("expression", _("X position"))
.AddParameter("expression", _("Y position"))
.AddParameter("yesorno", _("Should the copy take in account the source transparency\?"));
.AddParameter("object", _("Object"), "Sprite")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Name of the source image"))
.AddParameter("expression", _("X position"))
.AddParameter("expression", _("Y position"))
.AddParameter(
"yesorno",
_("Should the copy take in account the source transparency\?"));
obj.AddAction("CreateMaskFromColorOnActualImage", //Actual is indeed a mistake : Current should have been chosen.
_("Make a color of the image of an object transparent"),
_("Make a color of the image of an object transparent."),
_("Make color _PARAM1_ of the current image of _PARAM0_ transparent"),
_("Effects"),
"res/actions/opacity24.png",
"res/actions/opacity.png")
obj.AddAction(
"CreateMaskFromColorOnActualImage", // Actual is indeed a mistake :
// Current should have been
// chosen.
_("Make a color of the image of an object transparent"),
_("Make a color of the image of an object transparent."),
_("Make color _PARAM1_ of the current image of _PARAM0_ transparent"),
_("Effects"),
"res/actions/opacity24.png",
"res/actions/opacity.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("color", _("Color to make transparent"));
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("color", _("Color to make transparent"));
obj.AddAction(
"ChangeColor",
_("Global color"),
_("Change the global color of an object. The default color is white."),
_("Change color of _PARAM0_ to _PARAM1_"),
_("Effects"),
"res/actions/color24.png",
"res/actions/color.png")
obj.AddAction("ChangeColor",
_("Global color"),
_("Change the global color of an object. The default color is white."),
_("Change color of _PARAM0_ to _PARAM1_"),
_("Effects"),
"res/actions/color24.png",
"res/actions/color.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("color", _("Color"));
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("color", _("Color"));
obj.AddAction("ChangeBlendMode",
_("Blend mode"),
_("Change the number of the blend mode of an object.\nThe "
"default blend mode is 0 (Alpha)."),
_("Change Blend mode of _PARAM0_ to _PARAM1_"),
_("Effects"),
"res/actions/color24.png",
"res/actions/color.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("expression",
_("Mode (0 : Alpha, 1 : Add, 2 : Multiply, 3 : None)"))
.MarkAsSimple();
obj.AddAction("ChangeBlendMode",
_("Blend mode"),
_("Change the number of the blend mode of an object.\nThe default blend mode is 0 (Alpha)."),
_("Change Blend mode of _PARAM0_ to _PARAM1_"),
_("Effects"),
"res/actions/color24.png",
"res/actions/color.png")
obj.AddAction("FlipX",
_("Flip the object horizontally"),
_("Flip the object horizontally"),
_("Flip horizontally _PARAM0_ : _PARAM1_"),
_("Effects"),
"res/actions/flipX24.png",
"res/actions/flipX.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("expression", _("Mode (0 : Alpha, 1 : Add, 2 : Multiply, 3 : None)"))
.MarkAsSimple();
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("yesorno", _("Activate flipping"))
.MarkAsSimple();
obj.AddAction("FlipY",
_("Flip the object vertically"),
_("Flip the object vertically"),
_("Flip vertically _PARAM0_ : _PARAM1_"),
_("Effects"),
"res/actions/flipY24.png",
"res/actions/flipY.png")
obj.AddAction("FlipX",
_("Flip the object horizontally"),
_("Flip the object horizontally"),
_("Flip horizontally _PARAM0_ : _PARAM1_"),
_("Effects"),
"res/actions/flipX24.png",
"res/actions/flipX.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("yesorno", _("Activate flipping"))
.MarkAsSimple();
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("yesorno", _("Activate flipping"))
.MarkAsSimple();
obj.AddAction("FlipY",
_("Flip the object vertically"),
_("Flip the object vertically"),
_("Flip vertically _PARAM0_ : _PARAM1_"),
_("Effects"),
"res/actions/flipY24.png",
"res/actions/flipY.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("yesorno", _("Activate flipping"))
.MarkAsSimple();
obj.AddCondition("FlippedX",
obj.AddCondition("FlippedX",
_("Horizontally flipped"),
_("Return true if the object is horizontally flipped"),
_("_PARAM0_ is horizontally flipped"),
@@ -409,9 +430,9 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsSpriteExtension(gd::Pla
"res/actions/flipX24.png",
"res/actions/flipX.png")
.AddParameter("object", _("Object"), "Sprite");
.AddParameter("object", _("Object"), "Sprite");
obj.AddCondition("FlippedY",
obj.AddCondition("FlippedY",
_("Vertically flipped"),
_("Return true if the object is vertically flipped"),
_("_PARAM0_ is vertically flipped"),
@@ -419,81 +440,142 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsSpriteExtension(gd::Pla
"res/actions/flipY24.png",
"res/actions/flipY.png")
.AddParameter("object", _("Object"), "Sprite");
.AddParameter("object", _("Object"), "Sprite");
obj.AddAction("TourneVers",
_("Rotate an object toward another"),
_("Rotate an object towards another."),
_("Rotate _PARAM0_ towards _PARAM1_"),
_("Direction"),
"res/actions/direction24.png",
"res/actions/direction.png")
obj.AddAction("TourneVers",
_("Rotate an object toward another"),
_("Rotate an object towards another."),
_("Rotate _PARAM0_ towards _PARAM1_"),
_("Direction"),
"res/actions/direction24.png",
"res/actions/direction.png")
.AddParameter("object", _("Object to be rotated"), "Sprite")
.AddParameter("objectPtr", _("Rotate toward this object"))
.AddCodeOnlyParameter("currentScene", "")
.SetHidden(); //Deprecated
.AddParameter("object", _("Object to be rotated"), "Sprite")
.AddParameter("objectPtr", _("Rotate toward this object"))
.AddCodeOnlyParameter("currentScene", "")
.SetHidden(); // Deprecated
obj.AddExpression("X", _("X position of a point"), _("X position of a point"), _("Position"), "res/actions/position.png")
.SetHidden()
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("", _("Name of the point"), "", true);
obj.AddExpression("X",
_("X position of a point"),
_("X position of a point"),
_("Position"),
"res/actions/position.png")
.SetHidden()
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("", _("Name of the point"), "", true);
obj.AddExpression("Y", _("Y position of a point"), _("Y position of a point"), _("Position"), "res/actions/position.png")
.SetHidden()
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("", _("Name of the point"), "", true);
obj.AddExpression("Y",
_("Y position of a point"),
_("Y position of a point"),
_("Position"),
"res/actions/position.png")
.SetHidden()
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("", _("Name of the point"), "", true);
obj.AddExpression("PointX", _("X position of a point"), _("X position of a point"), _("Position"), "res/actions/position.png")
obj.AddExpression("PointX",
_("X position of a point"),
_("X position of a point"),
_("Position"),
"res/actions/position.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("", _("Name of the point"));
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("", _("Name of the point"));
obj.AddExpression("PointY", _("Y position of a point"), _("Y position of a point"), _("Position"), "res/actions/position.png")
obj.AddExpression("PointY",
_("Y position of a point"),
_("Y position of a point"),
_("Position"),
"res/actions/position.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("", _("Name of the point"));
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("", _("Name of the point"));
obj.AddExpression("Direc", _("Direction"), _("Direction of the object"), _("Direction"), "res/actions/direction.png")
.SetHidden()
.AddParameter("object", _("Object"), "Sprite");
obj.AddExpression("Direc",
_("Direction"),
_("Direction of the object"),
_("Direction"),
"res/actions/direction.png")
.SetHidden()
.AddParameter("object", _("Object"), "Sprite");
obj.AddExpression("Direction", _("Direction"), _("Direction of the object"), _("Direction"), "res/actions/direction.png")
.AddParameter("object", _("Object"), "Sprite");
obj.AddExpression("Direction",
_("Direction"),
_("Direction of the object"),
_("Direction"),
"res/actions/direction.png")
.AddParameter("object", _("Object"), "Sprite");
obj.AddExpression("Anim", _("Animation"), _("Animation of the object"), _("Animations and images"), "res/actions/animation.png")
.SetHidden()
.AddParameter("object", _("Object"), "Sprite");
obj.AddExpression("Anim",
_("Animation"),
_("Animation of the object"),
_("Animations and images"),
"res/actions/animation.png")
.SetHidden()
.AddParameter("object", _("Object"), "Sprite");
obj.AddExpression("Animation", _("Animation"), _("Animation of the object"), _("Animations and images"), "res/actions/animation.png")
.AddParameter("object", _("Object"), "Sprite");
obj.AddExpression("Animation",
_("Animation"),
_("Animation of the object"),
_("Animations and images"),
"res/actions/animation.png")
.AddParameter("object", _("Object"), "Sprite");
obj.AddStrExpression("AnimationName", _("Animation name"), _("Name of the animation of the object"), _("Animations and images"), "res/actions/animation.png")
.AddParameter("object", _("Object"), "Sprite");
obj.AddStrExpression("AnimationName",
_("Animation name"),
_("Name of the animation of the object"),
_("Animations and images"),
"res/actions/animation.png")
.AddParameter("object", _("Object"), "Sprite");
obj.AddExpression("Sprite", _("Image"), _("Animation frame of the object"), _("Animations and images"), "res/actions/sprite.png")
.AddParameter("object", _("Object"), "Sprite");
obj.AddExpression("Sprite",
_("Image"),
_("Animation frame of the object"),
_("Animations and images"),
"res/actions/sprite.png")
.AddParameter("object", _("Object"), "Sprite");
obj.AddExpression("AnimationSpeedScale", _("Animation speed scale"), _("Animation speed scale"), _("Animations and images"), "res/actions/animation.png")
.AddParameter("object", _("Object"), "Sprite");
obj.AddExpression("AnimationSpeedScale",
_("Animation speed scale"),
_("Animation speed scale"),
_("Animations and images"),
"res/actions/animation.png")
.AddParameter("object", _("Object"), "Sprite");
obj.AddExpression("ScaleX", _("Scale of the width of an object"), _("Scale of the width of an object"), _("Size"), "res/actions/scaleWidth.png")
.AddParameter("object", _("Object"), "Sprite");
obj.AddExpression("ScaleX",
_("Scale of the width of an object"),
_("Scale of the width of an object"),
_("Size"),
"res/actions/scaleWidth.png")
.AddParameter("object", _("Object"), "Sprite");
obj.AddExpression("ScaleY", _("Scale of the height of an object"), _("Scale of the height of an object"), _("Size"), "res/actions/scaleHeight.png")
.AddParameter("object", _("Object"), "Sprite");
obj.AddExpression("ScaleY",
_("Scale of the height of an object"),
_("Scale of the height of an object"),
_("Size"),
"res/actions/scaleHeight.png")
.AddParameter("object", _("Object"), "Sprite");
extension.AddCondition("Collision",
_("Collision (Pixel perfect)"),
_("The condition is true if there is a collision between the two objects.\nThe test is pixel-perfect."),
_("_PARAM0_ is in collision with _PARAM1_ (pixel perfect)"),
_("Collision"),
"res/conditions/collision24.png",
"res/conditions/collision.png")
.AddParameter("objectList", _("Object 1"), "Sprite")
.AddParameter("objectList", _("Object 2"), "Sprite")
.AddCodeOnlyParameter("conditionInverted", "");
#endif
obj.AddExpression("Opacity",
_("Opacity"),
_("Opacity"),
_("Opacity"),
"res/actions/opacity.png")
.AddParameter("object", _("Object"), "Sprite");
extension
.AddCondition("Collision",
_("Collision (Pixel perfect)"),
_("The condition is true if there is a collision between "
"the two objects.\nThe test is pixel-perfect."),
_("_PARAM0_ is in collision with _PARAM1_ (pixel perfect)"),
_("Collision"),
"res/conditions/collision24.png",
"res/conditions/collision.png")
.AddParameter("objectList", _("Object 1"), "Sprite")
.AddParameter("objectList", _("Object 2"), "Sprite")
.AddCodeOnlyParameter("conditionInverted", "");
#endif
}
}
} // namespace gd

View File

@@ -1,329 +1,373 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
#include <wx/wx.h> //Must be placed first, otherwise we get nice errors relative to "cannot convert 'const TCHAR*'..." in wx/msw/winundef.h
#include <wx/wx.h> //Must be placed first, otherwise we get nice errors relative to "cannot convert 'const TCHAR*'..." in wx/msw/winundef.h
#endif
#include <algorithm>
#include "GDCore/Tools/Localization.h"
#include "GDCore/Extensions/Builtin/SpriteExtension/SpriteObject.h"
#include "GDCore/CommonTools.h"
#include "GDCore/Extensions/Builtin/SpriteExtension/Animation.h"
#include "GDCore/Extensions/Builtin/SpriteExtension/Direction.h"
#include "GDCore/Extensions/Builtin/SpriteExtension/Sprite.h"
#include "GDCore/Project/Project.h"
#include "GDCore/Extensions/Builtin/SpriteExtension/SpriteObject.h"
#include "GDCore/Project/ImageManager.h"
#include "GDCore/Project/InitialInstance.h"
#include "GDCore/Project/Layout.h"
#include "GDCore/Project/Object.h"
#include "GDCore/Project/ImageManager.h"
#include "GDCore/Project/Project.h"
#include "GDCore/Serialization/SerializerElement.h"
#include "GDCore/Project/InitialInstance.h"
#include "GDCore/CommonTools.h"
#include "GDCore/Tools/Localization.h"
#if defined(GD_IDE_ONLY)
#include <SFML/Graphics.hpp>
#include "GDCore/IDE/Project/ArbitraryResourceWorker.h"
#include "GDCore/Extensions/Builtin/SpriteExtension/Dialogs/SpriteObjectEditor.h"
#include "GDCore/IDE/Dialogs/MainFrameWrapper.h"
#include "GDCore/IDE/Dialogs/PropertyDescriptor.h"
#include "GDCore/Extensions/Builtin/SpriteExtension/Dialogs/SpriteObjectEditor.h"
#include "GDCore/IDE/Project/ArbitraryResourceWorker.h"
#endif
namespace gd {
Animation SpriteObject::badAnimation;
SpriteObject::SpriteObject(gd::String name_) :
Object(name_),
updateIfNotVisible(false)
{
}
SpriteObject::SpriteObject(gd::String name_)
: Object(name_), updateIfNotVisible(false) {}
SpriteObject::~SpriteObject()
{
};
SpriteObject::~SpriteObject(){};
void SpriteObject::DoUnserializeFrom(gd::Project & project, const gd::SerializerElement & element)
{
updateIfNotVisible = element.GetBoolAttribute("updateIfNotVisible", true);
void SpriteObject::DoUnserializeFrom(gd::Project& project,
const gd::SerializerElement& element) {
updateIfNotVisible = element.GetBoolAttribute("updateIfNotVisible", true);
RemoveAllAnimations();
const gd::SerializerElement & animationsElement = element.GetChild("animations", 0, "Animations");
animationsElement.ConsiderAsArrayOf("animation", "Animation");
for (std::size_t i = 0; i < animationsElement.GetChildrenCount(); ++i)
{
const gd::SerializerElement & animationElement = animationsElement.GetChild(i);
Animation newAnimation;
RemoveAllAnimations();
const gd::SerializerElement& animationsElement =
element.GetChild("animations", 0, "Animations");
animationsElement.ConsiderAsArrayOf("animation", "Animation");
for (std::size_t i = 0; i < animationsElement.GetChildrenCount(); ++i) {
const gd::SerializerElement& animationElement =
animationsElement.GetChild(i);
Animation newAnimation;
newAnimation.useMultipleDirections = animationElement.GetBoolAttribute("useMultipleDirections", false, "typeNormal");
newAnimation.SetName(animationElement.GetStringAttribute("name", ""));
newAnimation.useMultipleDirections = animationElement.GetBoolAttribute(
"useMultipleDirections", false, "typeNormal");
newAnimation.SetName(animationElement.GetStringAttribute("name", ""));
//Compatibility with GD <= 3.3
if (animationElement.HasChild("Direction"))
{
for (std::size_t j = 0; j < animationElement.GetChildrenCount("Direction"); ++j)
{
Direction direction;
direction.UnserializeFrom(animationElement.GetChild("Direction", j));
// Compatibility with GD <= 3.3
if (animationElement.HasChild("Direction")) {
for (std::size_t j = 0;
j < animationElement.GetChildrenCount("Direction");
++j) {
Direction direction;
direction.UnserializeFrom(animationElement.GetChild("Direction", j));
newAnimation.SetDirectionsCount(newAnimation.GetDirectionsCount()+1);
newAnimation.SetDirection(direction, newAnimation.GetDirectionsCount()-1);
}
}
//End of compatibility code
else
{
const gd::SerializerElement & directionsElement = animationElement.GetChild("directions");
directionsElement.ConsiderAsArrayOf("direction");
for (std::size_t j = 0; j < directionsElement.GetChildrenCount(); ++j)
{
Direction direction;
direction.UnserializeFrom(directionsElement.GetChild(j));
newAnimation.SetDirectionsCount(newAnimation.GetDirectionsCount()+1);
newAnimation.SetDirection(direction, newAnimation.GetDirectionsCount()-1);
}
}
AddAnimation( newAnimation );
newAnimation.SetDirectionsCount(newAnimation.GetDirectionsCount() + 1);
newAnimation.SetDirection(direction,
newAnimation.GetDirectionsCount() - 1);
}
}
// End of compatibility code
else {
const gd::SerializerElement& directionsElement =
animationElement.GetChild("directions");
directionsElement.ConsiderAsArrayOf("direction");
for (std::size_t j = 0; j < directionsElement.GetChildrenCount(); ++j) {
Direction direction;
direction.UnserializeFrom(directionsElement.GetChild(j));
newAnimation.SetDirectionsCount(newAnimation.GetDirectionsCount() + 1);
newAnimation.SetDirection(direction,
newAnimation.GetDirectionsCount() - 1);
}
}
AddAnimation(newAnimation);
}
}
#if defined(GD_IDE_ONLY)
void SpriteObject::DoSerializeTo(gd::SerializerElement & element) const
{
element.SetAttribute("updateIfNotVisible", updateIfNotVisible);
void SpriteObject::DoSerializeTo(gd::SerializerElement& element) const {
element.SetAttribute("updateIfNotVisible", updateIfNotVisible);
//Animations
gd::SerializerElement & animationsElement = element.AddChild("animations");
animationsElement.ConsiderAsArrayOf("animation");
for ( std::size_t k = 0;k < GetAnimationsCount();k++ )
{
gd::SerializerElement & animationElement = animationsElement.AddChild("animation");
// Animations
gd::SerializerElement& animationsElement = element.AddChild("animations");
animationsElement.ConsiderAsArrayOf("animation");
for (std::size_t k = 0; k < GetAnimationsCount(); k++) {
gd::SerializerElement& animationElement =
animationsElement.AddChild("animation");
animationElement.SetAttribute( "useMultipleDirections", GetAnimation(k).useMultipleDirections);
animationElement.SetAttribute( "name", GetAnimation(k).GetName());
animationElement.SetAttribute("useMultipleDirections",
GetAnimation(k).useMultipleDirections);
animationElement.SetAttribute("name", GetAnimation(k).GetName());
gd::SerializerElement & directionsElement = animationElement.AddChild("directions");
directionsElement.ConsiderAsArrayOf("direction");
for ( std::size_t l = 0;l < GetAnimation(k).GetDirectionsCount();l++ )
{
GetAnimation(k).GetDirection(l).SerializeTo(directionsElement.AddChild("direction"));
}
gd::SerializerElement& directionsElement =
animationElement.AddChild("directions");
directionsElement.ConsiderAsArrayOf("direction");
for (std::size_t l = 0; l < GetAnimation(k).GetDirectionsCount(); l++) {
GetAnimation(k).GetDirection(l).SerializeTo(
directionsElement.AddChild("direction"));
}
}
}
std::map<gd::String, gd::PropertyDescriptor> SpriteObject::GetProperties(gd::Project & project) const
{
std::map<gd::String, gd::PropertyDescriptor> properties;
properties[_("Animate even if hidden or far from the screen")].SetValue(updateIfNotVisible ? "true" : "false").SetType("Boolean");
properties[_("PLEASE_ALSO_SHOW_EDIT_BUTTON_THANKS")].SetValue("");
std::map<gd::String, gd::PropertyDescriptor> SpriteObject::GetProperties(
gd::Project& project) const {
std::map<gd::String, gd::PropertyDescriptor> properties;
properties[_("Animate even if hidden or far from the screen")]
.SetValue(updateIfNotVisible ? "true" : "false")
.SetType("Boolean");
properties[_("PLEASE_ALSO_SHOW_EDIT_BUTTON_THANKS")].SetValue("");
return properties;
return properties;
}
bool SpriteObject::UpdateProperty(const gd::String & name, const gd::String & value, gd::Project & project)
{
if (name == _("Animate even if hidden or far from the screen")) updateIfNotVisible = value == "1";
bool SpriteObject::UpdateProperty(const gd::String& name,
const gd::String& value,
gd::Project& project) {
if (name == _("Animate even if hidden or far from the screen"))
updateIfNotVisible = value == "1";
return true;
return true;
}
#if !defined(EMSCRIPTEN)
void SpriteObject::LoadResources(gd::Project & project, gd::Layout & layout)
{
for ( std::size_t j = 0; j < animations.size();j++ )
{
Animation & anim = animations[j];
for ( std::size_t k = 0;k < anim.GetDirectionsCount();k++ )
{
for ( std::size_t l = 0;l < anim.GetDirection(k).GetSpritesCount();l++ )
{
Sprite & sprite = anim.GetDirection(k).GetSprite(l);
void SpriteObject::LoadResources(gd::Project& project, gd::Layout& layout) {
for (std::size_t j = 0; j < animations.size(); j++) {
Animation& anim = animations[j];
for (std::size_t k = 0; k < anim.GetDirectionsCount(); k++) {
for (std::size_t l = 0; l < anim.GetDirection(k).GetSpritesCount(); l++) {
Sprite& sprite = anim.GetDirection(k).GetSprite(l);
sprite.LoadImage(project.GetImageManager()->GetSFMLTexture(sprite.GetImageName()));
}
}
sprite.LoadImage(
project.GetImageManager()->GetSFMLTexture(sprite.GetImageName()));
}
}
}
}
const Sprite * SpriteObject::GetInitialInstanceSprite(gd::InitialInstance & instance, gd::Project & project, gd::Layout & layout, bool * shouldNotRotate) const
{
if ( HasNoAnimations() ) return NULL;
const Sprite* SpriteObject::GetInitialInstanceSprite(
gd::InitialInstance& instance,
gd::Project& project,
gd::Layout& layout,
bool* shouldNotRotate) const {
if (HasNoAnimations()) return NULL;
//Search the first sprite of the current animation/direction.
std::size_t animationId = instance.floatInfos.find("animation") != instance.floatInfos.end() ? instance.floatInfos.find("animation")->second : 0;
if ( animationId >= GetAnimationsCount() ) animationId = 0;
// Search the first sprite of the current animation/direction.
std::size_t animationId =
instance.floatInfos.find("animation") != instance.floatInfos.end()
? instance.floatInfos.find("animation")->second
: 0;
if (animationId >= GetAnimationsCount()) animationId = 0;
const Animation & animation = GetAnimation(animationId);
if ( animation.HasNoDirections() ) return NULL;
const Animation& animation = GetAnimation(animationId);
if (animation.HasNoDirections()) return NULL;
std::size_t directionId = 0;
if ( animation.useMultipleDirections ) {
std::size_t directionId = 0;
if (animation.useMultipleDirections) {
float normalizedAngle = static_cast<int>(instance.GetAngle()) % 360;
if (normalizedAngle < 0) normalizedAngle += 360;
float normalizedAngle = static_cast<int>(instance.GetAngle())%360;
if ( normalizedAngle < 0 ) normalizedAngle += 360;
directionId = static_cast<int>(gd::Round(normalizedAngle / 45.f)) % 8;
}
directionId = static_cast<int>(gd::Round(normalizedAngle/45.f))%8;
}
if (directionId >= animation.GetDirectionsCount()) directionId = 0;
if ( directionId >= animation.GetDirectionsCount() ) directionId = 0;
const Direction& direction = animation.GetDirection(directionId);
const Direction & direction = animation.GetDirection(directionId);
if ( shouldNotRotate ) *shouldNotRotate = animation.useMultipleDirections;
return direction.HasNoSprites() ? NULL : &direction.GetSprite(0);
if (shouldNotRotate) *shouldNotRotate = animation.useMultipleDirections;
return direction.HasNoSprites() ? NULL : &direction.GetSprite(0);
}
void SpriteObject::DrawInitialInstance(gd::InitialInstance & instance, sf::RenderTarget & renderTarget, gd::Project & project, gd::Layout & layout)
{
bool shouldNotRotate = false;
const Sprite * associatedSprite = GetInitialInstanceSprite(instance, project, layout, &shouldNotRotate);
if ( associatedSprite == NULL || !associatedSprite->GetSFMLTexture() ) return;
void SpriteObject::DrawInitialInstance(gd::InitialInstance& instance,
sf::RenderTarget& renderTarget,
gd::Project& project,
gd::Layout& layout) {
bool shouldNotRotate = false;
const Sprite* associatedSprite =
GetInitialInstanceSprite(instance, project, layout, &shouldNotRotate);
if (associatedSprite == NULL || !associatedSprite->GetSFMLTexture()) return;
sf::Sprite sprite(associatedSprite->GetSFMLTexture()->texture);
sf::Sprite sprite(associatedSprite->GetSFMLTexture()->texture);
float scaleX = instance.HasCustomSize() ? instance.GetCustomWidth()/associatedSprite->GetSFMLTexture()->texture.getSize().x : 1;
float scaleY = instance.HasCustomSize() ? instance.GetCustomHeight()/associatedSprite->GetSFMLTexture()->texture.getSize().y : 1;
float scaleX =
instance.HasCustomSize()
? instance.GetCustomWidth() /
associatedSprite->GetSFMLTexture()->texture.getSize().x
: 1;
float scaleY =
instance.HasCustomSize()
? instance.GetCustomHeight() /
associatedSprite->GetSFMLTexture()->texture.getSize().y
: 1;
sprite.setOrigin( associatedSprite->GetCenter().GetX(), associatedSprite->GetCenter().GetY() ); ;
sprite.setRotation( shouldNotRotate ? 0 : instance.GetAngle() );
sprite.setPosition( instance.GetX() + (associatedSprite->GetCenter().GetX() - associatedSprite->GetOrigin().GetX())*fabs(scaleX),
instance.GetY() + (associatedSprite->GetCenter().GetY() - associatedSprite->GetOrigin().GetY())*fabs(scaleY) );
sprite.setScale(scaleX, scaleY);
sprite.setOrigin(associatedSprite->GetCenter().GetX(),
associatedSprite->GetCenter().GetY());
;
sprite.setRotation(shouldNotRotate ? 0 : instance.GetAngle());
sprite.setPosition(instance.GetX() + (associatedSprite->GetCenter().GetX() -
associatedSprite->GetOrigin().GetX()) *
fabs(scaleX),
instance.GetY() + (associatedSprite->GetCenter().GetY() -
associatedSprite->GetOrigin().GetY()) *
fabs(scaleY));
sprite.setScale(scaleX, scaleY);
renderTarget.draw(sprite);
renderTarget.draw(sprite);
}
sf::Vector2f SpriteObject::GetInitialInstanceDefaultSize(gd::InitialInstance & instance, gd::Project & project, gd::Layout & layout) const
{
const Sprite * associatedSprite = GetInitialInstanceSprite(instance, project, layout);
if ( associatedSprite == NULL || !associatedSprite->GetSFMLTexture() ) return sf::Vector2f(32,32);
sf::Vector2f SpriteObject::GetInitialInstanceDefaultSize(
gd::InitialInstance& instance,
gd::Project& project,
gd::Layout& layout) const {
const Sprite* associatedSprite =
GetInitialInstanceSprite(instance, project, layout);
if (associatedSprite == NULL || !associatedSprite->GetSFMLTexture())
return sf::Vector2f(32, 32);
sf::Vector2u size = associatedSprite->GetSFMLTexture()->texture.getSize();
return sf::Vector2f(size.x, size.y);
sf::Vector2u size = associatedSprite->GetSFMLTexture()->texture.getSize();
return sf::Vector2f(size.x, size.y);
}
sf::Vector2f SpriteObject::GetInitialInstanceOrigin(gd::InitialInstance & instance, gd::Project & project, gd::Layout & layout) const
{
const Sprite * associatedSprite = GetInitialInstanceSprite(instance, project, layout);
if ( associatedSprite == NULL || !associatedSprite->GetSFMLTexture() ) return sf::Vector2f(0,0);
sf::Vector2f SpriteObject::GetInitialInstanceOrigin(
gd::InitialInstance& instance,
gd::Project& project,
gd::Layout& layout) const {
const Sprite* associatedSprite =
GetInitialInstanceSprite(instance, project, layout);
if (associatedSprite == NULL || !associatedSprite->GetSFMLTexture())
return sf::Vector2f(0, 0);
float scaleX = instance.HasCustomSize() ? instance.GetCustomWidth()/associatedSprite->GetSFMLTexture()->texture.getSize().x : 1;
float scaleY = instance.HasCustomSize() ? instance.GetCustomHeight()/associatedSprite->GetSFMLTexture()->texture.getSize().y : 1;
float scaleX =
instance.HasCustomSize()
? instance.GetCustomWidth() /
associatedSprite->GetSFMLTexture()->texture.getSize().x
: 1;
float scaleY =
instance.HasCustomSize()
? instance.GetCustomHeight() /
associatedSprite->GetSFMLTexture()->texture.getSize().y
: 1;
return sf::Vector2f(((float)associatedSprite->GetOrigin().GetX())*fabs(scaleX),
((float)associatedSprite->GetOrigin().GetY())*fabs(scaleY));
return sf::Vector2f(
((float)associatedSprite->GetOrigin().GetX()) * fabs(scaleX),
((float)associatedSprite->GetOrigin().GetY()) * fabs(scaleY));
}
#endif
bool SpriteObject::GenerateThumbnail(const gd::Project & project, wxBitmap & thumbnail) const
{
bool SpriteObject::GenerateThumbnail(const gd::Project& project,
wxBitmap& thumbnail) const {
#if !defined(GD_NO_WX_GUI)
//Generate a thumbnail from the first animation
if ( !HasNoAnimations() && !GetAnimation(0).HasNoDirections() && !GetAnimation(0).GetDirection(0).HasNoSprites() )
{
gd::String imageName = GetAnimation(0).GetDirection(0).GetSprite(0).GetImageName();
// Generate a thumbnail from the first animation
if (!HasNoAnimations() && !GetAnimation(0).HasNoDirections() &&
!GetAnimation(0).GetDirection(0).HasNoSprites()) {
gd::String imageName =
GetAnimation(0).GetDirection(0).GetSprite(0).GetImageName();
if ( project.GetResourcesManager().HasResource(imageName) && wxFileExists(project.GetResourcesManager().GetResource(imageName).GetAbsoluteFile(project)) )
{
thumbnail = wxBitmap( project.GetResourcesManager().GetResource(imageName).GetAbsoluteFile(project), wxBITMAP_TYPE_ANY);
if (project.GetResourcesManager().HasResource(imageName) &&
wxFileExists(project.GetResourcesManager()
.GetResource(imageName)
.GetAbsoluteFile(project))) {
thumbnail = wxBitmap(
project.GetResourcesManager().GetResource(imageName).GetAbsoluteFile(
project),
wxBITMAP_TYPE_ANY);
wxImage thumbImage = thumbnail.ConvertToImage();
thumbnail = wxBitmap(thumbImage.Scale(24, 24));
wxImage thumbImage = thumbnail.ConvertToImage();
thumbnail = wxBitmap(thumbImage.Scale(24, 24));
return true;
}
return true;
}
}
#endif
return false;
return false;
}
void SpriteObject::ExposeResources(gd::ArbitraryResourceWorker & worker)
{
for ( std::size_t j = 0; j < GetAnimationsCount();j++ )
{
for ( std::size_t k = 0;k < GetAnimation( j ).GetDirectionsCount();k++ )
{
for ( std::size_t l = 0;l < GetAnimation( j ).GetDirection(k).GetSpritesCount();l++ ) {
worker.ExposeImage(GetAnimation( j ).GetDirection(k).GetSprite(l).GetImageName());
}
}
void SpriteObject::ExposeResources(gd::ArbitraryResourceWorker& worker) {
for (std::size_t j = 0; j < GetAnimationsCount(); j++) {
for (std::size_t k = 0; k < GetAnimation(j).GetDirectionsCount(); k++) {
for (std::size_t l = 0;
l < GetAnimation(j).GetDirection(k).GetSpritesCount();
l++) {
worker.ExposeImage(
GetAnimation(j).GetDirection(k).GetSprite(l).GetImageName());
}
}
}
}
void SpriteObject::EditObject( wxWindow* parent, gd::Project & project, gd::MainFrameWrapper & mainFrameWrapper )
{
void SpriteObject::EditObject(wxWindow* parent,
gd::Project& project,
gd::MainFrameWrapper& mainFrameWrapper) {
#if !defined(GD_NO_WX_GUI)
SpriteObjectEditor dialog( parent, project, *this, mainFrameWrapper );
dialog.ShowModal();
SpriteObjectEditor dialog(parent, project, *this, mainFrameWrapper);
dialog.ShowModal();
#endif
}
std::map<gd::String, gd::PropertyDescriptor>
SpriteObject::GetInitialInstanceProperties(const gd::InitialInstance& position,
gd::Project& project,
gd::Layout& scene) {
std::map<gd::String, gd::PropertyDescriptor> properties;
properties[_("Animation")] =
position.floatInfos.find("animation") != position.floatInfos.end()
? gd::String::From(position.floatInfos.find("animation")->second)
: gd::String("0");
std::map<gd::String, gd::PropertyDescriptor> SpriteObject::GetInitialInstanceProperties(const gd::InitialInstance & position, gd::Project & project, gd::Layout & scene)
{
std::map<gd::String, gd::PropertyDescriptor> properties;
properties[_("Animation")] = position.floatInfos.find("animation") != position.floatInfos.end() ?
gd::String::From(position.floatInfos.find("animation")->second) :
gd::String("0");
return properties;
return properties;
}
bool SpriteObject::UpdateInitialInstanceProperty(gd::InitialInstance & position, const gd::String & name, const gd::String & value, gd::Project & project, gd::Layout & scene)
{
if ( name == _("Animation") ) position.floatInfos["animation"] = value.To<int>();
bool SpriteObject::UpdateInitialInstanceProperty(gd::InitialInstance& position,
const gd::String& name,
const gd::String& value,
gd::Project& project,
gd::Layout& scene) {
if (name == _("Animation"))
position.floatInfos["animation"] = value.To<int>();
return true;
return true;
}
#endif
const Animation & SpriteObject::GetAnimation(std::size_t nb) const
{
if ( nb >= animations.size())
return badAnimation;
const Animation& SpriteObject::GetAnimation(std::size_t nb) const {
if (nb >= animations.size()) return badAnimation;
return animations[nb];
return animations[nb];
}
Animation & SpriteObject::GetAnimation(std::size_t nb)
{
if ( nb >= animations.size())
return badAnimation;
Animation& SpriteObject::GetAnimation(std::size_t nb) {
if (nb >= animations.size()) return badAnimation;
return animations[nb];
return animations[nb];
}
void SpriteObject::AddAnimation(const Animation & animation)
{
animations.push_back(animation);
void SpriteObject::AddAnimation(const Animation& animation) {
animations.push_back(animation);
}
bool SpriteObject::RemoveAnimation(std::size_t nb)
{
if ( nb >= GetAnimationsCount() )
return false;
bool SpriteObject::RemoveAnimation(std::size_t nb) {
if (nb >= GetAnimationsCount()) return false;
animations.erase( animations.begin() + nb );
return true;
animations.erase(animations.begin() + nb);
return true;
}
void SpriteObject::SwapAnimations(std::size_t firstIndex, std::size_t secondIndex)
{
if ( firstIndex < animations.size() && secondIndex < animations.size() && firstIndex != secondIndex)
std::swap(animations[firstIndex], animations[secondIndex]);
void SpriteObject::SwapAnimations(std::size_t firstIndex,
std::size_t secondIndex) {
if (firstIndex < animations.size() && secondIndex < animations.size() &&
firstIndex != secondIndex)
std::swap(animations[firstIndex], animations[secondIndex]);
}
void SpriteObject::MoveAnimation(std::size_t oldIndex, std::size_t newIndex)
{
if ( oldIndex >= animations.size() || newIndex >= animations.size())
return;
void SpriteObject::MoveAnimation(std::size_t oldIndex, std::size_t newIndex) {
if (oldIndex >= animations.size() || newIndex >= animations.size()) return;
auto animation = animations[oldIndex];
animations.erase(animations.begin() + oldIndex);
animations.insert(animations.begin() + newIndex, animation);
auto animation = animations[oldIndex];
animations.erase(animations.begin() + oldIndex);
animations.insert(animations.begin() + newIndex, animation);
}
}
} // namespace gd

View File

@@ -1,36 +1,53 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_SPRITEOBJECT_H
#define GDCORE_SPRITEOBJECT_H
#include "GDCore/Project/Object.h"
#include "GDCore/Extensions/Builtin/SpriteExtension/Animation.h"
#include "GDCore/Extensions/Builtin/SpriteExtension/Direction.h"
#include "GDCore/Extensions/Builtin/SpriteExtension/Sprite.h"
namespace gd { class InitialInstance; }
namespace gd { class Object; }
namespace gd { class Layout; }
namespace gd { class Sprite; }
namespace gd { class Animation; }
namespace gd { class MainFrameWrapper; }
namespace gd { class SerializerElement; }
namespace gd { class PropertyDescriptor; }
#include "GDCore/Project/Object.h"
namespace gd {
class InitialInstance;
}
namespace gd {
class Object;
}
namespace gd {
class Layout;
}
namespace gd {
class Sprite;
}
namespace gd {
class Animation;
}
namespace gd {
class MainFrameWrapper;
}
namespace gd {
class SerializerElement;
}
namespace gd {
class PropertyDescriptor;
}
#if defined(GD_IDE_ONLY)
class wxBitmap;
class wxWindow;
#endif
namespace gd
{
namespace gd {
/**
* \brief Standard sprite object for extensions that implements the standard SpriteExtension
* (see gd::BuiltinExtensionsImplementer::ImplementsSpriteExtension).
* \brief Standard sprite object for extensions that implements the standard
* SpriteExtension (see
* gd::BuiltinExtensionsImplementer::ImplementsSpriteExtension).
*
* A Sprite object is an object composed of animations, containing directions with images.
* A Sprite object is an object composed of animations, containing directions
* with images.
*
* \see Animation
* \see Direction
@@ -38,104 +55,131 @@ namespace gd
* \see gd::BuiltinExtensionsImplementer::ImplementsSpriteExtension
* \ingroup SpriteObjectExtension
*/
class GD_CORE_API SpriteObject : public gd::Object
{
public :
class GD_CORE_API SpriteObject : public gd::Object {
public:
SpriteObject(gd::String name_);
virtual ~SpriteObject();
std::unique_ptr<gd::Object> Clone() const override {
return gd::make_unique<SpriteObject>(*this);
}
SpriteObject(gd::String name_);
virtual ~SpriteObject();
std::unique_ptr<gd::Object> Clone() const override { return gd::make_unique<SpriteObject>(*this); }
#if defined(GD_IDE_ONLY)
bool GenerateThumbnail(const gd::Project& project,
wxBitmap& thumbnail) const override;
void ExposeResources(gd::ArbitraryResourceWorker& worker) override;
#if defined(GD_IDE_ONLY)
bool GenerateThumbnail(const gd::Project & project, wxBitmap & thumbnail) const override;
void ExposeResources(gd::ArbitraryResourceWorker & worker) override;
std::map<gd::String, gd::PropertyDescriptor> GetProperties(
gd::Project& project) const override;
bool UpdateProperty(const gd::String& name,
const gd::String& value,
gd::Project& project) override;
std::map<gd::String, gd::PropertyDescriptor> GetProperties(gd::Project & project) const override;
bool UpdateProperty(const gd::String & name, const gd::String & value, gd::Project & project) override;
std::map<gd::String, gd::PropertyDescriptor> GetInitialInstanceProperties(
const gd::InitialInstance& position,
gd::Project& project,
gd::Layout& scene) override;
bool UpdateInitialInstanceProperty(gd::InitialInstance& position,
const gd::String& name,
const gd::String& value,
gd::Project& project,
gd::Layout& scene) override;
void EditObject(wxWindow* parent,
gd::Project& project,
gd::MainFrameWrapper& mainFrameWrapper_) override;
#if !defined(EMSCRIPTEN)
void DrawInitialInstance(gd::InitialInstance& instance,
sf::RenderTarget& renderTarget,
gd::Project& project,
gd::Layout& layout) override;
sf::Vector2f GetInitialInstanceDefaultSize(gd::InitialInstance& instance,
gd::Project& project,
gd::Layout& layout) const override;
sf::Vector2f GetInitialInstanceOrigin(gd::InitialInstance& instance,
gd::Project& project,
gd::Layout& layout) const override;
void LoadResources(gd::Project& project, gd::Layout& layout) override;
#endif
std::map<gd::String, gd::PropertyDescriptor> GetInitialInstanceProperties(const gd::InitialInstance & position, gd::Project & project, gd::Layout & scene) override;
bool UpdateInitialInstanceProperty(gd::InitialInstance & position, const gd::String & name, const gd::String & value, gd::Project & project, gd::Layout & scene) override;
void EditObject( wxWindow* parent, gd::Project & project, gd::MainFrameWrapper & mainFrameWrapper_ ) override;
#if !defined(EMSCRIPTEN)
void DrawInitialInstance(gd::InitialInstance & instance, sf::RenderTarget & renderTarget, gd::Project & project, gd::Layout & layout) override;
sf::Vector2f GetInitialInstanceDefaultSize(gd::InitialInstance & instance, gd::Project & project, gd::Layout & layout) const override;
sf::Vector2f GetInitialInstanceOrigin(gd::InitialInstance & instance, gd::Project & project, gd::Layout & layout) const override;
void LoadResources(gd::Project & project, gd::Layout & layout) override;
#endif
bool SupportShaders() override { return true; };
#endif
bool SupportShaders() override { return true; };
#endif
/** \name Animations
* Methods related to animations management
*/
///@{
/**
* \brief Return the animation at the specified index.
* If the index is out of bound, a "bad animation" object is returned.
*/
const Animation& GetAnimation(std::size_t nb) const;
/** \name Animations
* Methods related to animations management
*/
///@{
/**
* \brief Return the animation at the specified index.
* If the index is out of bound, a "bad animation" object is returned.
*/
const Animation & GetAnimation(std::size_t nb) const;
/**
* \brief Return the animation at the specified index.
* If the index is out of bound, a "bad animation" object is returned.
*/
Animation& GetAnimation(std::size_t nb);
/**
* \brief Return the animation at the specified index.
* If the index is out of bound, a "bad animation" object is returned.
*/
Animation & GetAnimation(std::size_t nb);
/**
* \brief Return the number of animations this object has.
*/
std::size_t GetAnimationsCount() const { return animations.size(); };
/**
* \brief Return the number of animations this object has.
*/
std::size_t GetAnimationsCount() const { return animations.size(); };
/**
* \brief Add an animation at the end of the existing ones.
*/
void AddAnimation(const Animation& animation);
/**
* \brief Add an animation at the end of the existing ones.
*/
void AddAnimation(const Animation & animation);
/**
* \brief Remove an animation.
*/
bool RemoveAnimation(std::size_t nb);
/**
* \brief Remove an animation.
*/
bool RemoveAnimation(std::size_t nb);
/**
* \brief Remove all animations.
*/
void RemoveAllAnimations() { animations.clear(); }
/**
* \brief Remove all animations.
*/
void RemoveAllAnimations() { animations.clear(); }
/**
* \brief Return true if the object hasn't any animation.
*/
bool HasNoAnimations() const { return animations.empty(); }
/**
* \brief Return true if the object hasn't any animation.
*/
bool HasNoAnimations() const { return animations.empty(); }
/**
* \brief Swap the position of two animations
*/
void SwapAnimations(std::size_t firstIndex, std::size_t secondIndex);
/**
* \brief Swap the position of two animations
*/
void SwapAnimations(std::size_t firstIndex, std::size_t secondIndex);
/**
* \brief Change the position of the specified animation
*/
void MoveAnimation(std::size_t oldIndex, std::size_t newIndex);
/**
* \brief Change the position of the specified animation
*/
void MoveAnimation(std::size_t oldIndex, std::size_t newIndex);
/**
* \brief Return a read-only reference to the vector containing all the
* animation of the object.
*/
const std::vector<Animation>& GetAllAnimations() const { return animations; }
///@}
/**
* \brief Return a read-only reference to the vector containing all the animation of the object.
*/
const std::vector < Animation > & GetAllAnimations() const { return animations; }
///@}
private:
void DoUnserializeFrom(gd::Project& project,
const gd::SerializerElement& element) override;
#if defined(GD_IDE_ONLY)
void DoSerializeTo(gd::SerializerElement& element) const override;
#endif
private:
const Sprite* GetInitialInstanceSprite(gd::InitialInstance& instance,
gd::Project& project,
gd::Layout& layout,
bool* shouldNotRotate = NULL) const;
mutable std::vector<Animation> animations;
bool updateIfNotVisible; ///< If set to true, ask the game engine to play
///< object animation even if hidden or far from the
///< screen.
void DoUnserializeFrom(gd::Project & project, const gd::SerializerElement & element) override;
#if defined(GD_IDE_ONLY)
void DoSerializeTo(gd::SerializerElement & element) const override;
#endif
const Sprite * GetInitialInstanceSprite(gd::InitialInstance & instance, gd::Project & project, gd::Layout & layout, bool * shouldNotRotate = NULL) const;
mutable std::vector < Animation > animations;
bool updateIfNotVisible; ///< If set to true, ask the game engine to play object animation even if hidden or far from the screen.
static Animation badAnimation; //< Bad animation when an out of bound animation is requested.
static Animation badAnimation; //< Bad animation when an out of bound
// animation is requested.
};
}
#endif // GDCORE_SPRITEOBJECT_H
} // namespace gd
#endif // GDCORE_SPRITEOBJECT_H

View File

@@ -1,136 +1,155 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "AllBuiltinExtensions.h"
#include "GDCore/Tools/Localization.h"
using namespace std;
namespace gd
{
namespace gd {
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsStringInstructionsExtension(gd::PlatformExtension & extension)
{
extension.SetExtensionInformation("BuiltinStringInstructions",
_("Text manipulation"),
_("Built-in extension providing expressions for manipulating text objects."),
"Florian Rival",
"Open source (MIT License)");
void GD_CORE_API
BuiltinExtensionsImplementer::ImplementsStringInstructionsExtension(
gd::PlatformExtension& extension) {
extension.SetExtensionInformation(
"BuiltinStringInstructions",
_("Text manipulation"),
_("Built-in extension providing expressions for manipulating text "
"objects."),
"Florian Rival",
"Open source (MIT License)");
#if defined(GD_IDE_ONLY)
extension.AddStrExpression("NewLine",
_("Insert a new line"),
_("Insert a new line"),
_("Manipulation of text"),
"res/conditions/toujours24.png");
#if defined(GD_IDE_ONLY)
extension.AddStrExpression("NewLine",
_("Insert a new line"),
_("Insert a new line"),
_("Manipulation of text"),
"res/conditions/toujours24.png");
extension.AddStrExpression("FromCodePoint",
_("Get character from code point"),
_("Get character from code point"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
extension
.AddStrExpression("FromCodePoint",
_("Get character from code point"),
_("Get character from code point"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
.AddParameter("expression", _("Code point"));
.AddParameter("expression", _("Code point"));
extension.AddStrExpression("ToUpperCase",
_("Uppercase a text"),
_("Uppercase a text"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
extension
.AddStrExpression("ToUpperCase",
_("Uppercase a text"),
_("Uppercase a text"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
.AddParameter("string", _("Text"));
.AddParameter("string", _("Text"));
extension.AddStrExpression("ToLowerCase",
_("Lowercase a text"),
_("Lowercase a text"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
extension
.AddStrExpression("ToLowerCase",
_("Lowercase a text"),
_("Lowercase a text"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
.AddParameter("string", _("Text"));
.AddParameter("string", _("Text"));
extension.AddStrExpression("SubStr",
_("Get a portion of a text"),
_("Get a portion of a text"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
extension
.AddStrExpression("SubStr",
_("Get a portion of a text"),
_("Get a portion of a text"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
.AddParameter("string", _("Text"))
.AddParameter("expression", _("Start position of the portion (the first letter is at position 0)"))
.AddParameter("expression", _("Length of the portion"));
.AddParameter("string", _("Text"))
.AddParameter("expression",
_("Start position of the portion (the first letter is at "
"position 0)"))
.AddParameter("expression", _("Length of the portion"));
extension.AddStrExpression("StrAt",
_("Get a character from a text"),
_("Get a character from a text"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
extension
.AddStrExpression("StrAt",
_("Get a character from a text"),
_("Get a character from a text"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
.AddParameter("string", _("Text"))
.AddParameter("expression", _("Position of the character (the first letter is at position 0)"));
.AddParameter("string", _("Text"))
.AddParameter(
"expression",
_("Position of the character (the first letter is at position 0)"));
extension.AddStrExpression("StrRepeat",
_("Repeat a text"),
_("Repeat a text"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
extension
.AddStrExpression("StrRepeat",
_("Repeat a text"),
_("Repeat a text"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
.AddParameter("string", _("Text to repeat"))
.AddParameter("expression", _("Repetition count"));
.AddParameter("string", _("Text to repeat"))
.AddParameter("expression", _("Repetition count"));
extension.AddExpression("StrLength",
_("Length of a text"),
_("Length of a text"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
extension
.AddExpression("StrLength",
_("Length of a text"),
_("Length of a text"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
.AddParameter("string", _("Text"));
.AddParameter("string", _("Text"));
extension
.AddExpression("StrFind",
_("Search in a text"),
_("Search in a text (return the position of the result or "
"-1 if not found)"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
extension.AddExpression("StrFind",
_("Search in a text"),
_("Search in a text (return the position of the result or -1 if not found)"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
.AddParameter("string", _("Text"))
.AddParameter("string", _("Text to search for"));
.AddParameter("string", _("Text"))
.AddParameter("string", _("Text to search for"));
extension
.AddExpression("StrRFind",
_("Search in a text from the end"),
_("Search in a text from the end (return the position of "
"the result or -1 if not found)"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
.AddParameter("string", _("Text"))
.AddParameter("string", _("Text to search for"));
extension.AddExpression("StrRFind",
_("Search in a text from the end"),
_("Search in a text from the end (return the position of the result or -1 if not found)"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
extension
.AddExpression("StrFindFrom",
_("Search in a text, starting from a position"),
_("Search in a text, starting from a position (return the "
"position of the result or -1 if not found)"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
.AddParameter("string", _("Text"))
.AddParameter("string", _("Text to search for"));
.AddParameter("string", _("Text"))
.AddParameter("string", _("Text to search for"))
.AddParameter("expression",
_("Position of the first character in the string to be "
"considered in the search"));
extension
.AddExpression(
"StrRFindFrom",
_("Search in a text from the end, starting from a position"),
_("Search in a text from the end, starting from a position (return "
"the position of the result or -1 if not found)"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
.AddParameter("string", _("Text"))
.AddParameter("string", _("Text to search for"))
.AddParameter("expression",
_("Position of the last character in the string to be "
"considered in the search"));
extension.AddExpression("StrFindFrom",
_("Search in a text, starting from a position"),
_("Search in a text, starting from a position (return the position of the result or -1 if not found)"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
.AddParameter("string", _("Text"))
.AddParameter("string", _("Text to search for"))
.AddParameter("expression", _("Position of the first character in the string to be considered in the search"));
extension.AddExpression("StrRFindFrom",
_("Search in a text from the end, starting from a position"),
_("Search in a text from the end, starting from a position (return the position of the result or -1 if not found)"),
_("Manipulation of text"),
"res/conditions/toujours24.png")
.AddParameter("string", _("Text"))
.AddParameter("string", _("Text to search for"))
.AddParameter("expression", _("Position of the last character in the string to be considered in the search"));
#endif
#endif
}
}
} // namespace gd

View File

@@ -1,154 +1,205 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "AllBuiltinExtensions.h"
#include "GDCore/Tools/Localization.h"
using namespace std;
namespace gd
{
namespace gd {
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsTimeExtension(gd::PlatformExtension & extension)
{
extension.SetExtensionInformation("BuiltinTime",
_("Time"),
_("Built-in extension providing actions and conditions related to time."),
"Florian Rival",
"Open source (MIT License)");
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsTimeExtension(
gd::PlatformExtension& extension) {
extension.SetExtensionInformation(
"BuiltinTime",
_("Time"),
_("Built-in extension providing actions and conditions related to time."),
"Florian Rival",
"Open source (MIT License)");
#if defined(GD_IDE_ONLY)
#if defined(GD_IDE_ONLY)
extension.AddCondition("Timer",
_("Value of a timer"),
_("Test the elapsed time of a timer."),
_("The timer _PARAM2_ is greater than _PARAM1_ seconds"),
_("Timers and time"),
"res/conditions/timer24.png",
"res/conditions/timer.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Time in seconds"))
.AddParameter("string", _("Timer's name"));
extension
.AddCondition("Timer",
_("Value of a timer"),
_("Test the elapsed time of a timer."),
_("The timer _PARAM2_ is greater than _PARAM1_ seconds"),
_("Timers and time"),
"res/conditions/timer24.png",
"res/conditions/timer.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Time in seconds"))
.AddParameter("string", _("Timer's name"));
extension.AddCondition("TimeScale",
_("Time scale"),
_("Test the time scale."),
_("The time scale is _PARAM1__PARAM2_"),
_("Timers and time"),
"res/conditions/time24.png",
"res/conditions/time.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddCondition("TimeScale",
_("Time scale"),
_("Test the time scale."),
_("The time scale is _PARAM1__PARAM2_"),
_("Timers and time"),
"res/conditions/time24.png",
"res/conditions/time.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddCondition("TimerPaused",
_("State of a timer"),
_("Test if specified timer is paused."),
_("The timer _PARAM1_ is paused"),
_("Timers and time"),
"res/conditions/timerPaused24.png",
"res/conditions/timerPaused.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Timer's name"))
.MarkAsAdvanced();
extension
.AddCondition("TimerPaused",
_("State of a timer"),
_("Test if specified timer is paused."),
_("The timer _PARAM1_ is paused"),
_("Timers and time"),
"res/conditions/timerPaused24.png",
"res/conditions/timerPaused.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Timer's name"))
.MarkAsAdvanced();
extension.AddAction("ResetTimer",
_("Reset a timer"),
_("Reset the specified timer."),
_("Reset the timer _PARAM1_"),
_("Timers and time"),
"res/actions/timer24.png",
"res/actions/timer.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Timer's name"));
extension
.AddAction("ResetTimer",
_("Reset a timer"),
_("Reset the specified timer."),
_("Reset the timer _PARAM1_"),
_("Timers and time"),
"res/actions/timer24.png",
"res/actions/timer.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Timer's name"));
extension.AddAction("PauseTimer",
_("Pause a timer"),
_("Pause a timer."),
_("Pause timer _PARAM1_"),
_("Timers and time"),
"res/actions/pauseTimer24.png",
"res/actions/pauseTimer.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Timer's name"))
.MarkAsAdvanced();
extension
.AddAction("PauseTimer",
_("Pause a timer"),
_("Pause a timer."),
_("Pause timer _PARAM1_"),
_("Timers and time"),
"res/actions/pauseTimer24.png",
"res/actions/pauseTimer.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Timer's name"))
.MarkAsAdvanced();
extension.AddAction("UnPauseTimer",
_("Unpause a timer"),
_("Unpause a timer."),
_("Unpause timer _PARAM1_"),
_("Timers and time"),
"res/actions/unPauseTimer24.png",
"res/actions/unPauseTimer.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Timer's name"))
.MarkAsAdvanced();
extension
.AddAction("UnPauseTimer",
_("Unpause a timer"),
_("Unpause a timer."),
_("Unpause timer _PARAM1_"),
_("Timers and time"),
"res/actions/unPauseTimer24.png",
"res/actions/unPauseTimer.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Timer's name"))
.MarkAsAdvanced();
extension.AddAction("RemoveTimer",
_("Delete a timer"),
_("Delete a timer from memory."),
_("Delete timer _PARAM1_ from memory"),
_("Timers and time"),
"res/actions/timer24.png",
"res/actions/timer.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Timer's name"))
.MarkAsAdvanced();
extension
.AddAction("RemoveTimer",
_("Delete a timer"),
_("Delete a timer from memory."),
_("Delete timer _PARAM1_ from memory"),
_("Timers and time"),
"res/actions/timer24.png",
"res/actions/timer.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Timer's name"))
.MarkAsAdvanced();
extension.AddAction("ChangeTimeScale",
_("Change time scale"),
_("Change the time scale of the game."),
_("Set time scale to _PARAM1_"),
_("Timers and time"),
"res/actions/time24.png",
"res/actions/time.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Scale (1: Default, 2: 2x faster, 0.5: 2x slower...)"));
extension
.AddAction("ChangeTimeScale",
_("Change time scale"),
_("Change the time scale of the game."),
_("Set time scale to _PARAM1_"),
_("Timers and time"),
"res/actions/time24.png",
"res/actions/time.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression",
_("Scale (1: Default, 2: 2x faster, 0.5: 2x slower...)"));
extension.AddExpression("TimeDelta", _("Time elapsed since the last image"), _("Time elapsed since the last image"), _("Time"), "res/actions/time.png")
.AddCodeOnlyParameter("currentScene", "");
extension
.AddExpression("TimeDelta",
_("Time elapsed since the last image"),
_("Time elapsed since the last image"),
_("Time"),
"res/actions/time.png")
.AddCodeOnlyParameter("currentScene", "");
extension.AddExpression("TempsFrame", _("Time elapsed since the last image"), _("Time elapsed since the last image"), _("Time"), "res/actions/time.png")
.SetHidden()
.AddCodeOnlyParameter("currentScene", "");
extension
.AddExpression("TempsFrame",
_("Time elapsed since the last image"),
_("Time elapsed since the last image"),
_("Time"),
"res/actions/time.png")
.SetHidden()
.AddCodeOnlyParameter("currentScene", "");
extension.AddExpression("ElapsedTime", _("Time elapsed since the last image"), _("Time elapsed since the last image"), _("Time"), "res/actions/time.png")
.SetHidden()
.AddCodeOnlyParameter("currentScene", "");
extension
.AddExpression("ElapsedTime",
_("Time elapsed since the last image"),
_("Time elapsed since the last image"),
_("Time"),
"res/actions/time.png")
.SetHidden()
.AddCodeOnlyParameter("currentScene", "");
extension
.AddExpression("TimerElapsedTime",
_("Timer value"),
_("Value of a timer"),
_("Time"),
"res/actions/time.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Timer's name"));
extension.AddExpression("TimerElapsedTime", _("Timer value"), _("Value of a timer"), _("Time"), "res/actions/time.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Timer's name"));
extension
.AddExpression("TimeFromStart",
_("Time elapsed since the beginning of the scene"),
_("Time elapsed since the beginning of the scene"),
_("Time"),
"res/actions/time.png")
.AddCodeOnlyParameter("currentScene", "");
extension
.AddExpression("TempsDebut",
_("Time elapsed since the beginning of the scene"),
_("Time elapsed since the beginning of the scene"),
_("Time"),
"res/actions/time.png")
.SetHidden()
.AddCodeOnlyParameter("currentScene", "");
extension.AddExpression("TimeFromStart", _("Time elapsed since the beginning of the scene"), _("Time elapsed since the beginning of the scene"), _("Time"), "res/actions/time.png")
.AddCodeOnlyParameter("currentScene", "")
;
extension
.AddExpression("TimeScale",
_("Time scale"),
_("Time scale"),
_("Time"),
"res/actions/time.png")
.AddCodeOnlyParameter("currentScene", "");
extension.AddExpression("TempsDebut", _("Time elapsed since the beginning of the scene"), _("Time elapsed since the beginning of the scene"), _("Time"), "res/actions/time.png")
.SetHidden()
.AddCodeOnlyParameter("currentScene", "")
;
extension
.AddExpression("TimeScale",
_("Time scale"),
_("Time scale"),
_("Time"),
"res/actions/time.png")
.SetHidden()
.AddCodeOnlyParameter("currentScene", "");
extension
.AddExpression("Time",
_("Current time"),
_("Current time"),
_("Time"),
"res/actions/time.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter(
"",
_("Hour : hour\nMinutes : min\nSeconds : sec\nDay of the month : "
"mday\nMonths since January : mon\nYear since 1900 : year\nDays "
"since sunday :wday\nDays since January 1st : yday"));
extension.AddExpression("TimeScale", _("Time scale"), _("Time scale"), _("Time"), "res/actions/time.png")
.AddCodeOnlyParameter("currentScene", "")
;
extension.AddExpression("TimeScale", _("Time scale"), _("Time scale"), _("Time"), "res/actions/time.png")
.SetHidden()
.AddCodeOnlyParameter("currentScene", "");
extension.AddExpression("Time", _("Current time"), _("Current time"), _("Time"), "res/actions/time.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("", _("Hour : hour\nMinutes : min\nSeconds : sec\nDay of the month : mday\nMonths since January : mon\nYear since 1900 : year\nDays since sunday :wday\nDays since January 1st : yday"));
#endif
#endif
}
}
} // namespace gd

View File

@@ -1,229 +1,279 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "AllBuiltinExtensions.h"
#include "GDCore/Tools/Localization.h"
using namespace std;
namespace gd
{
namespace gd {
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsVariablesExtension(gd::PlatformExtension & extension)
{
extension.SetExtensionInformation("BuiltinVariables",
_("Variable features"),
_("This Built-in extension allows the manipulation of variables"),
"Florian Rival",
"Open source (MIT License)");
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsVariablesExtension(
gd::PlatformExtension& extension) {
extension.SetExtensionInformation(
"BuiltinVariables",
_("Variable features"),
_("This Built-in extension allows the manipulation of variables"),
"Florian Rival",
"Open source (MIT License)");
#if defined(GD_IDE_ONLY)
extension.AddCondition("VarScene",
_("Value of a variable"),
_("Compare the value of a scene variable."),
_("Variable _PARAM0_ is _PARAM1__PARAM2_"),
_("Variables"),
"res/conditions/var24.png",
"res/conditions/var.png")
.AddParameter("scenevar", _("Variable"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to compare"))
.SetManipulatedType("number");
#if defined(GD_IDE_ONLY)
extension
.AddCondition("VarScene",
_("Value of a variable"),
_("Compare the value of a scene variable."),
_("Variable _PARAM0_ is _PARAM1__PARAM2_"),
_("Variables"),
"res/conditions/var24.png",
"res/conditions/var.png")
.AddParameter("scenevar", _("Variable"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to compare"))
.SetManipulatedType("number");
extension.AddCondition("VarSceneTxt",
_("Text of a variable"),
_("Compare the text of a scene variable."),
_("The text of variable _PARAM0_ is _PARAM1__PARAM2_"),
_("Variables"),
"res/conditions/var24.png",
"res/conditions/var.png")
.AddParameter("scenevar", _("Variable"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("string", _("Text to compare"))
.SetManipulatedType("string");
extension
.AddCondition("VarSceneTxt",
_("Text of a variable"),
_("Compare the text of a scene variable."),
_("The text of variable _PARAM0_ is _PARAM1__PARAM2_"),
_("Variables"),
"res/conditions/var24.png",
"res/conditions/var.png")
.AddParameter("scenevar", _("Variable"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("string", _("Text to compare"))
.SetManipulatedType("string");
extension.AddCondition("VariableChildExists",
_("Child existence"),
_("Return true if the specified child of the variable exists."),
_("Child _PARAM1_ of variable _PARAM0_ exists"),
_("Variables/Structures"),
"res/conditions/var24.png",
"res/conditions/var.png")
.AddParameter("scenevar", _("Variable"))
.AddParameter("string", _("Name of the child"))
.MarkAsAdvanced();
extension
.AddCondition(
"VariableChildExists",
_("Child existence"),
_("Return true if the specified child of the variable exists."),
_("Child _PARAM1_ of variable _PARAM0_ exists"),
_("Variables/Structures"),
"res/conditions/var24.png",
"res/conditions/var.png")
.AddParameter("scenevar", _("Variable"))
.AddParameter("string", _("Name of the child"))
.MarkAsAdvanced();
extension.AddCondition("GlobalVariableChildExists",
_("Child existence"),
_("Return true if the specified child of the global variable exists."),
_("Child _PARAM1_ of global variable _PARAM0_ exists"),
_("Variables/Global variables/Structures"),
"res/conditions/var24.png",
"res/conditions/var.png")
.AddParameter("globalvar", _("Variable"))
.AddParameter("string", _("Name of the child"))
.MarkAsAdvanced();
extension
.AddCondition("GlobalVariableChildExists",
_("Child existence"),
_("Return true if the specified child of the global "
"variable exists."),
_("Child _PARAM1_ of global variable _PARAM0_ exists"),
_("Variables/Global variables/Structures"),
"res/conditions/var24.png",
"res/conditions/var.png")
.AddParameter("globalvar", _("Variable"))
.AddParameter("string", _("Name of the child"))
.MarkAsAdvanced();
extension.AddCondition("VarSceneDef",
_("Test if a scene variable is defined"),
_("Test if the scene variable exist."),
_("Variable _PARAM0_ is defined"),
_("Variables"),
"res/conditions/var24.png",
"res/conditions/var.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Variable"))
.SetHidden();
extension
.AddCondition("VarSceneDef",
_("Test if a scene variable is defined"),
_("Test if the scene variable exist."),
_("Variable _PARAM0_ is defined"),
_("Variables"),
"res/conditions/var24.png",
"res/conditions/var.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Variable"))
.SetHidden();
extension.AddCondition("VarGlobal",
_("Value of a global variable"),
_("Compare the value of a global variable."),
_("Global variable _PARAM0_ is _PARAM1__PARAM2_"),
_("Variables/Global variables"),
"res/conditions/var24.png",
"res/conditions/var.png")
.AddParameter("globalvar", _("Variable"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to compare"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddCondition("VarGlobal",
_("Value of a global variable"),
_("Compare the value of a global variable."),
_("Global variable _PARAM0_ is _PARAM1__PARAM2_"),
_("Variables/Global variables"),
"res/conditions/var24.png",
"res/conditions/var.png")
.AddParameter("globalvar", _("Variable"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to compare"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddCondition("VarGlobalTxt",
_("Text of a global variable"),
_("Compare the text of a global variable."),
_("The text of the global variable _PARAM0_ is _PARAM1__PARAM2_"),
_("Variables/Global variables"),
"res/conditions/var24.png",
"res/conditions/var.png")
.AddParameter("globalvar", _("Variable"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("string", _("Text to compare"))
.MarkAsAdvanced()
.SetManipulatedType("string");
extension
.AddCondition(
"VarGlobalTxt",
_("Text of a global variable"),
_("Compare the text of a global variable."),
_("The text of the global variable _PARAM0_ is _PARAM1__PARAM2_"),
_("Variables/Global variables"),
"res/conditions/var24.png",
"res/conditions/var.png")
.AddParameter("globalvar", _("Variable"))
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("string", _("Text to compare"))
.MarkAsAdvanced()
.SetManipulatedType("string");
extension.AddCondition("VarGlobalDef",
_("Test if a global variable is defined"),
_("Test if a global variable exists"),
_("Global variable _PARAM0_ is defined"),
_("Variables/Global variables"),
"res/conditions/var24.png",
"res/conditions/var.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Variable"))
.MarkAsAdvanced()
.SetHidden();
extension
.AddCondition("VarGlobalDef",
_("Test if a global variable is defined"),
_("Test if a global variable exists"),
_("Global variable _PARAM0_ is defined"),
_("Variables/Global variables"),
"res/conditions/var24.png",
"res/conditions/var.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Variable"))
.MarkAsAdvanced()
.SetHidden();
extension.AddAction("ModVarScene",
_("Value of a variable"),
_("Modify the value of a scene variable."),
_("Do _PARAM1__PARAM2_ to variable _PARAM0_"),
_("Variables"),
"res/actions/var24.png",
"res/actions/var.png")
.AddParameter("scenevar", _("Variable"))
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.SetManipulatedType("number");
extension
.AddAction("ModVarScene",
_("Value of a variable"),
_("Modify the value of a scene variable."),
_("Do _PARAM1__PARAM2_ to variable _PARAM0_"),
_("Variables"),
"res/actions/var24.png",
"res/actions/var.png")
.AddParameter("scenevar", _("Variable"))
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.SetManipulatedType("number");
extension.AddAction("ModVarSceneTxt",
_("String of a variable"),
_("Modify the text of a scene variable."),
_("Do _PARAM1__PARAM2_ to the text of variable _PARAM0_"),
_("Variables"),
"res/actions/var24.png",
"res/actions/var.png")
.AddParameter("scenevar", _("Variable"))
.AddParameter("operator", _("Modification's sign"))
.AddParameter("string", _("Text"))
.SetManipulatedType("string");
extension
.AddAction("ModVarSceneTxt",
_("String of a variable"),
_("Modify the text of a scene variable."),
_("Do _PARAM1__PARAM2_ to the text of variable _PARAM0_"),
_("Variables"),
"res/actions/var24.png",
"res/actions/var.png")
.AddParameter("scenevar", _("Variable"))
.AddParameter("operator", _("Modification's sign"))
.AddParameter("string", _("Text"))
.SetManipulatedType("string");
extension.AddAction("ModVarGlobal",
_("Value of a global variable"),
_("Modify the value of a global variable"),
_("Do _PARAM1__PARAM2_ to global variable _PARAM0_"),
_("Variables/Global variables"),
"res/actions/var24.png",
"res/actions/var.png")
.AddParameter("globalvar", _("Variable"))
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension
.AddAction("ModVarGlobal",
_("Value of a global variable"),
_("Modify the value of a global variable"),
_("Do _PARAM1__PARAM2_ to global variable _PARAM0_"),
_("Variables/Global variables"),
"res/actions/var24.png",
"res/actions/var.png")
.AddParameter("globalvar", _("Variable"))
.AddParameter("operator", _("Modification's sign"))
.AddParameter("expression", _("Value"))
.MarkAsAdvanced()
.SetManipulatedType("number");
extension.AddAction("ModVarGlobalTxt",
_("String of a global variable"),
_("Modify the text of a global variable."),
_("Do _PARAM1__PARAM2_ to the text of global variable _PARAM0_"),
_("Variables/Global variables"),
"res/actions/var24.png",
"res/actions/var.png")
.AddParameter("globalvar", _("Variable"))
.AddParameter("operator", _("Modification's sign"))
.AddParameter("string", _("Text"))
.MarkAsAdvanced()
.SetManipulatedType("string");
extension
.AddAction(
"ModVarGlobalTxt",
_("String of a global variable"),
_("Modify the text of a global variable."),
_("Do _PARAM1__PARAM2_ to the text of global variable _PARAM0_"),
_("Variables/Global variables"),
"res/actions/var24.png",
"res/actions/var.png")
.AddParameter("globalvar", _("Variable"))
.AddParameter("operator", _("Modification's sign"))
.AddParameter("string", _("Text"))
.MarkAsAdvanced()
.SetManipulatedType("string");
extension.AddAction("VariableRemoveChild",
_("Remove a child"),
_("Remove a child from a variable."),
_("Remove child _PARAM1_ from variable _PARAM0_"),
_("Variables/Structure"),
"res/actions/var24.png",
"res/actions/var.png")
.AddParameter("scenevar", _("Variable"))
.AddParameter("string", _("Child's name"))
.MarkAsAdvanced();
extension
.AddAction("VariableRemoveChild",
_("Remove a child"),
_("Remove a child from a variable."),
_("Remove child _PARAM1_ from variable _PARAM0_"),
_("Variables/Structure"),
"res/actions/var24.png",
"res/actions/var.png")
.AddParameter("scenevar", _("Variable"))
.AddParameter("string", _("Child's name"))
.MarkAsAdvanced();
extension.AddAction("GlobalVariableRemoveChild",
_("Remove a child"),
_("Remove a child from a global variable."),
_("Remove child _PARAM1_ from global variable _PARAM0_"),
_("Variables/Global variables/Structure"),
"res/actions/var24.png",
"res/actions/var.png")
.AddParameter("globalvar", _("Variable"))
.AddParameter("string", _("Child's name"))
.MarkAsAdvanced();
extension
.AddAction("GlobalVariableRemoveChild",
_("Remove a child"),
_("Remove a child from a global variable."),
_("Remove child _PARAM1_ from global variable _PARAM0_"),
_("Variables/Global variables/Structure"),
"res/actions/var24.png",
"res/actions/var.png")
.AddParameter("globalvar", _("Variable"))
.AddParameter("string", _("Child's name"))
.MarkAsAdvanced();
extension.AddAction("VariableClearChildren",
_("Clear variable"),
_("Remove all the children from the variable."),
_("Clear children from variable _PARAM0_"),
_("Variables/Structure"),
"res/actions/var24.png",
"res/actions/var.png")
.AddParameter("scenevar", _("Variable"))
.MarkAsAdvanced();
extension
.AddAction("VariableClearChildren",
_("Clear variable"),
_("Remove all the children from the variable."),
_("Clear children from variable _PARAM0_"),
_("Variables/Structure"),
"res/actions/var24.png",
"res/actions/var.png")
.AddParameter("scenevar", _("Variable"))
.MarkAsAdvanced();
extension.AddAction("GlobalVariableClearChildren",
_("Clear global variable"),
_("Remove all the children from the global variable."),
_("Clear children from global variable _PARAM0_"),
_("Variables/Global variables/Structure"),
"res/actions/var24.png",
"res/actions/var.png")
.AddParameter("globalvar", _("Variable"))
.MarkAsAdvanced();
extension
.AddAction("GlobalVariableClearChildren",
_("Clear global variable"),
_("Remove all the children from the global variable."),
_("Clear children from global variable _PARAM0_"),
_("Variables/Global variables/Structure"),
"res/actions/var24.png",
"res/actions/var.png")
.AddParameter("globalvar", _("Variable"))
.MarkAsAdvanced();
extension.AddExpression("GlobalVariableChildCount", _("Global variable number of children"), _("Get the number of children of a global variable"), _("Variables"), "res/actions/var.png")
.AddParameter("globalvar", _("Variable"));
extension
.AddExpression("GlobalVariableChildCount",
_("Global variable number of children"),
_("Get the number of children of a global variable"),
_("Variables"),
"res/actions/var.png")
.AddParameter("globalvar", _("Variable"));
extension.AddExpression("VariableChildCount", _("Scene variable number of children"), _("Get the number of children of a scene variable"), _("Variables"), "res/actions/var.png")
.AddParameter("scenevar", _("Variable"));
extension
.AddExpression("VariableChildCount",
_("Scene variable number of children"),
_("Get the number of children of a scene variable"),
_("Variables"),
"res/actions/var.png")
.AddParameter("scenevar", _("Variable"));
extension.AddExpression("Variable", _("Scene variables"), _("Scene variables"), _("Variables"), "res/actions/var.png")
.AddParameter("scenevar", _("Variable"));
extension
.AddExpression("Variable",
_("Scene variables"),
_("Scene variables"),
_("Variables"),
"res/actions/var.png")
.AddParameter("scenevar", _("Variable"));
extension.AddStrExpression("VariableString", _("Scene variables"), _("Text of a scene variable"), _("Variables"), "res/actions/var.png")
.AddParameter("scenevar", _("Variable"));
extension
.AddStrExpression("VariableString",
_("Scene variables"),
_("Text of a scene variable"),
_("Variables"),
"res/actions/var.png")
.AddParameter("scenevar", _("Variable"));
extension.AddExpression("GlobalVariable", _("Global variables"), _("Global variable"), _("Variables"), "res/actions/var.png")
.AddParameter("globalvar", _("Name of the global variable"));
extension
.AddExpression("GlobalVariable",
_("Global variables"),
_("Global variable"),
_("Variables"),
"res/actions/var.png")
.AddParameter("globalvar", _("Name of the global variable"));
extension.AddStrExpression("GlobalVariableString", _("Global variables"), _("Text of a global variable"), _("Variables"), "res/actions/var.png")
.AddParameter("globalvar", _("Variable"));
#endif
extension
.AddStrExpression("GlobalVariableString",
_("Global variables"),
_("Text of a global variable"),
_("Variables"),
"res/actions/var.png")
.AddParameter("globalvar", _("Variable"));
#endif
}
}
} // namespace gd

View File

@@ -1,95 +1,142 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "AllBuiltinExtensions.h"
#include "GDCore/Tools/Localization.h"
using namespace std;
namespace gd
{
namespace gd {
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsWindowExtension(gd::PlatformExtension & extension)
{
extension.SetExtensionInformation("BuiltinWindow",
_("Window features"),
_("This Built-in extension enables the manipulation of the game's window"),
"Florian Rival",
"Open source (MIT License)");
void GD_CORE_API BuiltinExtensionsImplementer::ImplementsWindowExtension(
gd::PlatformExtension& extension) {
extension.SetExtensionInformation("BuiltinWindow",
_("Window features"),
_("This Built-in extension enables the "
"manipulation of the game's window"),
"Florian Rival",
"Open source (MIT License)");
#if defined(GD_IDE_ONLY)
extension.AddAction("SetFullScreen",
_("De/activate fullscreen"),
_("This action activates or deactivates fullscreen."),
_("Activate fullscreen: _PARAM1_ (keep aspect ratio: _PARAM2_)"),
_("Game's window"),
"res/actions/fullscreen24.png",
"res/actions/fullscreen.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("yesorno", _("Activate fullscreen"))
.AddParameter("yesorno", _("Keep aspect ratio (HTML5 games only, yes by default)"), "",true).SetDefaultValue("yes");
#if defined(GD_IDE_ONLY)
extension
.AddAction(
"SetFullScreen",
_("De/activate fullscreen"),
_("This action activates or deactivates fullscreen."),
_("Activate fullscreen: _PARAM1_ (keep aspect ratio: _PARAM2_)"),
_("Game's window"),
"res/actions/fullscreen24.png",
"res/actions/fullscreen.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("yesorno", _("Activate fullscreen"))
.AddParameter("yesorno",
_("Keep aspect ratio (HTML5 games only, yes by default)"),
"",
true)
.SetDefaultValue("yes");
extension.AddAction("SetWindowMargins",
_("Change the window's margins"),
_("This action changes the margins, in pixels, of the game's window."),
_("Set margins of game window to _PARAM1_;_PARAM2_;_PARAM3_;_PARAM4_"),
_("Game's window"),
"res/actions/window24.png",
"res/actions/window.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Top"))
.AddParameter("expression", _("Right"))
.AddParameter("expression", _("Bottom"))
.AddParameter("expression", _("Left"));
extension
.AddAction("SetWindowMargins",
_("Change the window's margins"),
_("This action changes the margins, in pixels, of the game's "
"window."),
_("Set margins of game window to "
"_PARAM1_;_PARAM2_;_PARAM3_;_PARAM4_"),
_("Game's window"),
"res/actions/window24.png",
"res/actions/window.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Top"))
.AddParameter("expression", _("Right"))
.AddParameter("expression", _("Bottom"))
.AddParameter("expression", _("Left"));
extension.AddAction("SetWindowSize",
_("Change the size of the window"),
_("This action changes the size of the game's window."),
_("Change window size: _PARAM1_x_PARAM2_"),
_("Game's window"),
"res/actions/window24.png",
"res/actions/window.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Width"))
.AddParameter("expression", _("Height"))
.AddParameter("yesorno", _("Do you want to use this size as the default size for new scene cameras\?\n(Yes to change the size of the game's viewable area,\nNo to stretch the game to the window's size)."));
extension
.AddAction("SetWindowSize",
_("Change the size of the window"),
_("This action changes the size of the game's window."),
_("Change window size: _PARAM1_x_PARAM2_"),
_("Game's window"),
"res/actions/window24.png",
"res/actions/window.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Width"))
.AddParameter("expression", _("Height"))
.AddParameter(
"yesorno",
_("Do you want to use this size as the default size for new scene "
"cameras\?\n(Yes to change the size of the game's viewable "
"area,\nNo to stretch the game to the window's size)."));
extension.AddAction("SetWindowIcon",
_("Change the window's icon"),
_("This action changes the icon of the game's window."),
_("Use _PARAM1_ as the icon for the game's window."),
_("Game's window"),
"res/actions/window24.png",
"res/actions/window.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Name of the image to be used as the icon"));
extension
.AddAction("SetWindowIcon",
_("Change the window's icon"),
_("This action changes the icon of the game's window."),
_("Use _PARAM1_ as the icon for the game's window."),
_("Game's window"),
"res/actions/window24.png",
"res/actions/window.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Name of the image to be used as the icon"));
extension.AddAction("SetWindowTitle",
_("Change the window's title"),
_("This action changes the title of the game's window."),
_("Change window title to _PARAM1_"),
_("Game's window"),
"res/actions/window24.png",
"res/actions/window.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("New title"));
extension
.AddAction("SetWindowTitle",
_("Change the window's title"),
_("This action changes the title of the game's window."),
_("Change window title to _PARAM1_"),
_("Game's window"),
"res/actions/window24.png",
"res/actions/window.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("New title"));
extension.AddExpression("SceneWindowWidth", _("Width of the scene window"), _("Width of the scene window (or scene canvas for HTML5 games)"), _("Screen"), "res/window.png")
.AddCodeOnlyParameter("currentScene", "");
extension
.AddExpression(
"SceneWindowWidth",
_("Width of the scene window"),
_("Width of the scene window (or scene canvas for HTML5 games)"),
_("Screen"),
"res/window.png")
.AddCodeOnlyParameter("currentScene", "");
extension.AddExpression("SceneWindowHeight", _("Height of the scene window"), _("Height of the scene window (or scene canvas for HTML5 games)"), _("Screen"), "res/window.png")
.AddCodeOnlyParameter("currentScene", "");
extension
.AddExpression(
"SceneWindowHeight",
_("Height of the scene window"),
_("Height of the scene window (or scene canvas for HTML5 games)"),
_("Screen"),
"res/window.png")
.AddCodeOnlyParameter("currentScene", "");
extension.AddExpression("ScreenWidth", _("Width of the screen/page"), _("Width of the screen (or the page for HTML5 games in browser)"), _("Screen"), "res/display16.png");
extension.AddExpression(
"ScreenWidth",
_("Width of the screen/page"),
_("Width of the screen (or the page for HTML5 games in browser)"),
_("Screen"),
"res/display16.png");
extension.AddExpression("ScreenHeight", _("Height of the screen/page"), _("Height of the screen (or the page for HTML5 games in browser)"), _("Screen"), "res/display16.png");
extension.AddExpression(
"ScreenHeight",
_("Height of the screen/page"),
_("Height of the screen (or the page for HTML5 games in browser)"),
_("Screen"),
"res/display16.png");
extension.AddExpression("ColorDepth", _("Color depth"), _("Color depth"), _("Screen"), "res/display16.png");
extension.AddExpression("ColorDepth",
_("Color depth"),
_("Color depth"),
_("Screen"),
"res/display16.png");
extension.AddStrExpression("WindowTitle", _("Window's title"), _("Window's title"), _("Screen"), "res/window.png")
.AddCodeOnlyParameter("currentScene", "");
#endif
extension
.AddStrExpression("WindowTitle",
_("Window's title"),
_("Window's title"),
_("Screen"),
"res/window.png")
.AddCodeOnlyParameter("currentScene", "");
#endif
}
}
} // namespace gd

View File

@@ -1,169 +1,186 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "BehaviorMetadata.h"
#include "GDCore/Extensions/Metadata/InstructionMetadata.h"
#include "GDCore/Extensions/Metadata/ExpressionMetadata.h"
#include "GDCore/Project/Behavior.h"
#include "GDCore/Project/BehaviorsSharedData.h"
#include <algorithm>
#include <iostream>
#include "GDCore/Extensions/Metadata/ExpressionMetadata.h"
#include "GDCore/Extensions/Metadata/InstructionMetadata.h"
#include "GDCore/Project/Behavior.h"
#include "GDCore/Project/BehaviorsSharedData.h"
#if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
#include "GDCore/IDE/wxTools/SkinHelper.h"
#include <wx/file.h>
#include <wx/bitmap.h>
#include <wx/file.h>
#include "GDCore/IDE/wxTools/SkinHelper.h"
#endif
namespace gd
{
namespace gd {
BehaviorMetadata::BehaviorMetadata(const gd::String & extensionNamespace_,
const gd::String & name_,
const gd::String & fullname_,
const gd::String & defaultName_,
const gd::String & description_,
const gd::String & group_,
const gd::String & icon24x24,
const gd::String & className_,
std::shared_ptr<gd::Behavior> instance_,
std::shared_ptr<gd::BehaviorsSharedData> sharedDatasInstance_) :
extensionNamespace(extensionNamespace_),
instance(instance_),
sharedDatasInstance(sharedDatasInstance_)
{
BehaviorMetadata::BehaviorMetadata(
const gd::String& extensionNamespace_,
const gd::String& name_,
const gd::String& fullname_,
const gd::String& defaultName_,
const gd::String& description_,
const gd::String& group_,
const gd::String& icon24x24,
const gd::String& className_,
std::shared_ptr<gd::Behavior> instance_,
std::shared_ptr<gd::BehaviorsSharedData> sharedDatasInstance_)
: extensionNamespace(extensionNamespace_),
instance(instance_),
sharedDatasInstance(sharedDatasInstance_) {
#if defined(GD_IDE_ONLY)
SetFullName(gd::String(fullname_));
SetDescription(gd::String(description_));
SetDefaultName(gd::String(defaultName_));
SetGroup(group_);
className = className_;
iconFilename = icon24x24;
SetFullName(gd::String(fullname_));
SetDescription(gd::String(description_));
SetDefaultName(gd::String(defaultName_));
SetGroup(group_);
className = className_;
iconFilename = icon24x24;
#if !defined(GD_NO_WX_GUI)
if ( gd::SkinHelper::IconExists(iconFilename, 24) )
SetBitmapIcon(gd::SkinHelper::GetIcon(iconFilename, 24));
else if ( wxFile::Exists(iconFilename) )
SetBitmapIcon(wxBitmap(iconFilename, wxBITMAP_TYPE_ANY));
else {
std::cout << "Warning: The icon file for behavior \"" << name_
<< " was not found in the current skin icons"
<< " and the specified name is not an existing filename.";
SetBitmapIcon(wxBitmap(24,24));
}
if (gd::SkinHelper::IconExists(iconFilename, 24))
SetBitmapIcon(gd::SkinHelper::GetIcon(iconFilename, 24));
else if (wxFile::Exists(iconFilename))
SetBitmapIcon(wxBitmap(iconFilename, wxBITMAP_TYPE_ANY));
else {
std::cout << "Warning: The icon file for behavior \"" << name_
<< " was not found in the current skin icons"
<< " and the specified name is not an existing filename.";
SetBitmapIcon(wxBitmap(24, 24));
}
#endif
#endif
if ( instance ) instance->SetTypeName(name_);
if ( sharedDatasInstance ) sharedDatasInstance->SetTypeName(name_);
if (instance) instance->SetTypeName(name_);
if (sharedDatasInstance) sharedDatasInstance->SetTypeName(name_);
}
gd::InstructionMetadata & BehaviorMetadata::AddCondition(const gd::String & name,
const gd::String & fullname,
const gd::String & description,
const gd::String & sentence,
const gd::String & group,
const gd::String & icon,
const gd::String & smallicon)
{
gd::InstructionMetadata& BehaviorMetadata::AddCondition(
const gd::String& name,
const gd::String& fullname,
const gd::String& description,
const gd::String& sentence,
const gd::String& group,
const gd::String& icon,
const gd::String& smallicon) {
#if defined(GD_IDE_ONLY)
gd::String nameWithNamespace = extensionNamespace.empty() ? name : extensionNamespace+name;
conditionsInfos[nameWithNamespace] = InstructionMetadata(extensionNamespace, nameWithNamespace, fullname, description, sentence, group, icon, smallicon);
return conditionsInfos[nameWithNamespace];
gd::String nameWithNamespace =
extensionNamespace.empty() ? name : extensionNamespace + name;
conditionsInfos[nameWithNamespace] = InstructionMetadata(extensionNamespace,
nameWithNamespace,
fullname,
description,
sentence,
group,
icon,
smallicon);
return conditionsInfos[nameWithNamespace];
#endif
}
gd::InstructionMetadata & BehaviorMetadata::AddAction(const gd::String & name,
const gd::String & fullname,
const gd::String & description,
const gd::String & sentence,
const gd::String & group,
const gd::String & icon,
const gd::String & smallicon)
{
gd::InstructionMetadata& BehaviorMetadata::AddAction(
const gd::String& name,
const gd::String& fullname,
const gd::String& description,
const gd::String& sentence,
const gd::String& group,
const gd::String& icon,
const gd::String& smallicon) {
#if defined(GD_IDE_ONLY)
gd::String nameWithNamespace = extensionNamespace.empty() ? name : extensionNamespace+name;
actionsInfos[nameWithNamespace] = InstructionMetadata(extensionNamespace, nameWithNamespace, fullname, description, sentence, group, icon, smallicon);
return actionsInfos[nameWithNamespace];
gd::String nameWithNamespace =
extensionNamespace.empty() ? name : extensionNamespace + name;
actionsInfos[nameWithNamespace] = InstructionMetadata(extensionNamespace,
nameWithNamespace,
fullname,
description,
sentence,
group,
icon,
smallicon);
return actionsInfos[nameWithNamespace];
#endif
}
gd::ExpressionMetadata & BehaviorMetadata::AddExpression(const gd::String & name,
const gd::String & fullname,
const gd::String & description,
const gd::String & group,
const gd::String & smallicon)
{
gd::ExpressionMetadata& BehaviorMetadata::AddExpression(
const gd::String& name,
const gd::String& fullname,
const gd::String& description,
const gd::String& group,
const gd::String& smallicon) {
#if defined(GD_IDE_ONLY)
//Be careful, behaviors expression do not have namespace ( not necessary as we refer to the auomatism name in the expression )
expressionsInfos[name] = ExpressionMetadata(extensionNamespace, name, fullname, description, group, smallicon);
return expressionsInfos[name];
// Be careful, behaviors expression do not have namespace ( not necessary as
// we refer to the auomatism name in the expression )
expressionsInfos[name] = ExpressionMetadata(
extensionNamespace, name, fullname, description, group, smallicon);
return expressionsInfos[name];
#endif
}
gd::ExpressionMetadata & BehaviorMetadata::AddStrExpression(const gd::String & name,
const gd::String & fullname,
const gd::String & description,
const gd::String & group,
const gd::String & smallicon)
{
gd::ExpressionMetadata& BehaviorMetadata::AddStrExpression(
const gd::String& name,
const gd::String& fullname,
const gd::String& description,
const gd::String& group,
const gd::String& smallicon) {
#if defined(GD_IDE_ONLY)
//Be careful, behaviors expression do not have namespace ( not necessary as we refer to the auomatism name in the expression )
strExpressionsInfos[name] = ExpressionMetadata(extensionNamespace, name, fullname, description, group, smallicon);
return strExpressionsInfos[name];
// Be careful, behaviors expression do not have namespace ( not necessary as
// we refer to the auomatism name in the expression )
strExpressionsInfos[name] = ExpressionMetadata(
extensionNamespace, name, fullname, description, group, smallicon);
return strExpressionsInfos[name];
#endif
}
BehaviorMetadata & BehaviorMetadata::SetFullName(const gd::String & fullname_)
{
BehaviorMetadata& BehaviorMetadata::SetFullName(const gd::String& fullname_) {
#if defined(GD_IDE_ONLY)
fullname = fullname_;
fullname = fullname_;
#endif
return *this;
return *this;
}
BehaviorMetadata & BehaviorMetadata::SetDefaultName(const gd::String & defaultName_)
{
BehaviorMetadata& BehaviorMetadata::SetDefaultName(
const gd::String& defaultName_) {
#if defined(GD_IDE_ONLY)
defaultName = defaultName_;
defaultName = defaultName_;
#endif
return *this;
return *this;
}
BehaviorMetadata & BehaviorMetadata::SetDescription(const gd::String & description_)
{
BehaviorMetadata& BehaviorMetadata::SetDescription(
const gd::String& description_) {
#if defined(GD_IDE_ONLY)
description = description_;
description = description_;
#endif
return *this;
return *this;
}
BehaviorMetadata & BehaviorMetadata::SetGroup(const gd::String & group_)
{
BehaviorMetadata& BehaviorMetadata::SetGroup(const gd::String& group_) {
#if defined(GD_IDE_ONLY)
group = group_;
group = group_;
#endif
return *this;
return *this;
}
BehaviorMetadata & BehaviorMetadata::SetBitmapIcon(const wxBitmap & bitmap_)
{
BehaviorMetadata& BehaviorMetadata::SetBitmapIcon(const wxBitmap& bitmap_) {
#if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
icon = bitmap_;
icon = bitmap_;
#endif
return *this;
return *this;
}
BehaviorMetadata & BehaviorMetadata::SetIncludeFile(const gd::String & includeFile)
{
BehaviorMetadata& BehaviorMetadata::SetIncludeFile(
const gd::String& includeFile) {
#if defined(GD_IDE_ONLY)
includeFiles.clear();
includeFiles.clear();
includeFiles.push_back(includeFile);
#endif
return *this;
}
BehaviorMetadata& BehaviorMetadata::AddIncludeFile(
const gd::String& includeFile) {
#if defined(GD_IDE_ONLY)
if (std::find(includeFiles.begin(), includeFiles.end(), includeFile) ==
includeFiles.end())
includeFiles.push_back(includeFile);
#endif
return *this;
}
BehaviorMetadata & BehaviorMetadata::AddIncludeFile(const gd::String & includeFile)
{
#if defined(GD_IDE_ONLY)
if ( std::find(includeFiles.begin(), includeFiles.end(), includeFile) == includeFiles.end())
includeFiles.push_back(includeFile);
#endif
return *this;
return *this;
}
}
} // namespace gd

View File

@@ -1,146 +1,156 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef BEHAVIORMETADATA_H
#define BEHAVIORMETADATA_H
#include "GDCore/String.h"
#include <map>
#include "GDCore/Extensions/Metadata/InstructionMetadata.h"
#include "GDCore/Extensions/Metadata/ExpressionMetadata.h"
#include "GDCore/Extensions/Metadata/InstructionMetadata.h"
#include "GDCore/String.h"
#if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
#include <wx/bitmap.h>
#endif
namespace gd { class Behavior; }
namespace gd { class BehaviorsSharedData; }
namespace gd { class InstructionMetadata; }
namespace gd { class ExpressionMetadata; }
namespace gd {
class Behavior;
}
namespace gd {
class BehaviorsSharedData;
}
namespace gd {
class InstructionMetadata;
}
namespace gd {
class ExpressionMetadata;
}
class wxBitmap;
namespace gd
{
namespace gd {
/**
* \brief Contains user-friendly information about a behavior type
*
* Implementations may derive from this class so as to provide more complete metadata if needed.
* ( For example, GDevelop C++ Platform is shared pointers to objects that will be cloned so as to create the behaviors... )
* Implementations may derive from this class so as to provide more complete
* metadata if needed. ( For example, GDevelop C++ Platform is shared pointers
* to objects that will be cloned so as to create the behaviors... )
*
* \ingroup Events
*/
class GD_CORE_API BehaviorMetadata
{
public:
BehaviorMetadata(const gd::String & extensionNamespace,
const gd::String & name_,
const gd::String & fullname_,
const gd::String & defaultName_,
const gd::String & description_,
const gd::String & group_,
const gd::String & icon24x24_,
const gd::String & className_,
std::shared_ptr<gd::Behavior> instance,
std::shared_ptr<gd::BehaviorsSharedData> sharedDatasInstance);
BehaviorMetadata() {};
virtual ~BehaviorMetadata() {};
class GD_CORE_API BehaviorMetadata {
public:
BehaviorMetadata(
const gd::String& extensionNamespace,
const gd::String& name_,
const gd::String& fullname_,
const gd::String& defaultName_,
const gd::String& description_,
const gd::String& group_,
const gd::String& icon24x24_,
const gd::String& className_,
std::shared_ptr<gd::Behavior> instance,
std::shared_ptr<gd::BehaviorsSharedData> sharedDatasInstance);
BehaviorMetadata(){};
virtual ~BehaviorMetadata(){};
/**
* Declare a new condition as being part of the extension.
*/
gd::InstructionMetadata & AddCondition(const gd::String & name_,
const gd::String & fullname_,
const gd::String & description_,
const gd::String & sentence_,
const gd::String & group_,
const gd::String & icon_,
const gd::String & smallicon_);
/**
* Declare a new condition as being part of the extension.
*/
gd::InstructionMetadata& AddCondition(const gd::String& name_,
const gd::String& fullname_,
const gd::String& description_,
const gd::String& sentence_,
const gd::String& group_,
const gd::String& icon_,
const gd::String& smallicon_);
/**
* Declare a new action as being part of the extension.
*/
gd::InstructionMetadata & AddAction(const gd::String & name_,
const gd::String & fullname_,
const gd::String & description_,
const gd::String & sentence_,
const gd::String & group_,
const gd::String & icon_,
const gd::String & smallicon_);
/**
* Declare a new action as being part of the extension.
*/
gd::ExpressionMetadata & AddExpression(const gd::String & name_,
const gd::String & fullname_,
const gd::String & description_,
const gd::String & group_,
const gd::String & smallicon_);
/**
* Declare a new action as being part of the extension.
*/
gd::InstructionMetadata& AddAction(const gd::String& name_,
const gd::String& fullname_,
const gd::String& description_,
const gd::String& sentence_,
const gd::String& group_,
const gd::String& icon_,
const gd::String& smallicon_);
/**
* Declare a new action as being part of the extension.
*/
gd::ExpressionMetadata& AddExpression(const gd::String& name_,
const gd::String& fullname_,
const gd::String& description_,
const gd::String& group_,
const gd::String& smallicon_);
/**
* Declare a new string expression as being part of the extension.
*/
gd::ExpressionMetadata & AddStrExpression(const gd::String & name_,
const gd::String & fullname_,
const gd::String & description_,
const gd::String & group_,
const gd::String & smallicon_);
/**
* Declare a new string expression as being part of the extension.
*/
gd::ExpressionMetadata& AddStrExpression(const gd::String& name_,
const gd::String& fullname_,
const gd::String& description_,
const gd::String& group_,
const gd::String& smallicon_);
BehaviorMetadata & SetFullName(const gd::String & fullname_);
BehaviorMetadata & SetDefaultName(const gd::String & defaultName_);
BehaviorMetadata & SetDescription(const gd::String & description_);
BehaviorMetadata & SetGroup(const gd::String & group_);
BehaviorMetadata & SetBitmapIcon(const wxBitmap & bitmap_);
BehaviorMetadata& SetFullName(const gd::String& fullname_);
BehaviorMetadata& SetDefaultName(const gd::String& defaultName_);
BehaviorMetadata& SetDescription(const gd::String& description_);
BehaviorMetadata& SetGroup(const gd::String& group_);
BehaviorMetadata& SetBitmapIcon(const wxBitmap& bitmap_);
/**
* \brief Erase any existing include file and add the specified include.
* \note The requirement may vary depending on the platform: Most of the time, the include
* file contains the declaration of the behavior.
*/
BehaviorMetadata & SetIncludeFile(const gd::String & includeFile);
/**
* \brief Erase any existing include file and add the specified include.
* \note The requirement may vary depending on the platform: Most of the time,
* the include file contains the declaration of the behavior.
*/
BehaviorMetadata& SetIncludeFile(const gd::String& includeFile);
/**
* \brief Add a file to the already existing include files.
*/
BehaviorMetadata & AddIncludeFile(const gd::String & includeFile);
/**
* \brief Add a file to the already existing include files.
*/
BehaviorMetadata& AddIncludeFile(const gd::String& includeFile);
#if defined(GD_IDE_ONLY)
const gd::String & GetFullName() const { return fullname; }
const gd::String & GetDefaultName() const { return defaultName; }
const gd::String & GetDescription() const { return description; }
const gd::String & GetGroup() const { return group; }
const gd::String & GetIconFilename() const { return iconFilename; }
const gd::String& GetFullName() const { return fullname; }
const gd::String& GetDefaultName() const { return defaultName; }
const gd::String& GetDescription() const { return description; }
const gd::String& GetGroup() const { return group; }
const gd::String& GetIconFilename() const { return iconFilename; }
#if !defined(GD_NO_WX_GUI)
const wxBitmap & GetBitmapIcon() const { return icon; }
const wxBitmap& GetBitmapIcon() const { return icon; }
#endif
#endif
std::shared_ptr<gd::Behavior> Get() const { return instance; }
std::shared_ptr<gd::BehaviorsSharedData> GetSharedDataInstance() const { return sharedDatasInstance; }
std::shared_ptr<gd::Behavior> Get() const { return instance; }
std::shared_ptr<gd::BehaviorsSharedData> GetSharedDataInstance() const {
return sharedDatasInstance;
}
#if defined(GD_IDE_ONLY)
std::map<gd::String, gd::InstructionMetadata > conditionsInfos;
std::map<gd::String, gd::InstructionMetadata > actionsInfos;
std::map<gd::String, gd::ExpressionMetadata > expressionsInfos;
std::map<gd::String, gd::ExpressionMetadata > strExpressionsInfos;
std::map<gd::String, gd::InstructionMetadata> conditionsInfos;
std::map<gd::String, gd::InstructionMetadata> actionsInfos;
std::map<gd::String, gd::ExpressionMetadata> expressionsInfos;
std::map<gd::String, gd::ExpressionMetadata> strExpressionsInfos;
std::vector<gd::String> includeFiles;
gd::String className;
std::vector<gd::String> includeFiles;
gd::String className;
#endif
private:
gd::String extensionNamespace;
private:
gd::String extensionNamespace;
#if defined(GD_IDE_ONLY)
gd::String fullname;
gd::String defaultName;
gd::String description;
gd::String group;
gd::String iconFilename;
gd::String fullname;
gd::String defaultName;
gd::String description;
gd::String group;
gd::String iconFilename;
#if !defined(GD_NO_WX_GUI)
wxBitmap icon;
wxBitmap icon;
#endif
#endif
std::shared_ptr<gd::Behavior> instance;
std::shared_ptr<gd::BehaviorsSharedData> sharedDatasInstance;
std::shared_ptr<gd::Behavior> instance;
std::shared_ptr<gd::BehaviorsSharedData> sharedDatasInstance;
};
}
} // namespace gd
#endif // BEHAVIORMETADATA_H
#endif // BEHAVIORMETADATA_H

View File

@@ -1,38 +1,41 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#if defined(GD_IDE_ONLY)
#include "GDCore/Extensions/Metadata/EventMetadata.h"
#include "GDCore/Events/EventsList.h"
#include "GDCore/Events/Event.h"
#include "GDCore/Events/EventsList.h"
namespace gd
{
namespace gd {
EventMetadata::EventMetadata(const gd::String & name_, const gd::String & fullname_,
const gd::String & description_, const gd::String & group_, const gd::String & smallicon_,
std::shared_ptr<gd::BaseEvent> instance_) :
fullname(fullname_),
description(description_),
group(group_),
instance(instance_)
{
ClearCodeGenerationAndPreprocessing();
if (instance) instance->SetType(name_);
EventMetadata::EventMetadata(const gd::String &name_,
const gd::String &fullname_,
const gd::String &description_,
const gd::String &group_,
const gd::String &smallicon_,
std::shared_ptr<gd::BaseEvent> instance_)
: fullname(fullname_),
description(description_),
group(group_),
instance(instance_) {
ClearCodeGenerationAndPreprocessing();
if (instance) instance->SetType(name_);
}
void EventMetadata::ClearCodeGenerationAndPreprocessing()
{
hasCustomCodeGenerator = false;
codeGeneration = [](gd::BaseEvent &, gd::EventsCodeGenerator &, gd::EventsCodeGenerationContext &) {
return "";
};
preprocessing = [](gd::BaseEvent &, gd::EventsCodeGenerator &, gd::EventsList &, std::size_t) {
//Do nothing
};
void EventMetadata::ClearCodeGenerationAndPreprocessing() {
hasCustomCodeGenerator = false;
codeGeneration = [](gd::BaseEvent &,
gd::EventsCodeGenerator &,
gd::EventsCodeGenerationContext &) { return ""; };
preprocessing = [](gd::BaseEvent &,
gd::EventsCodeGenerator &,
gd::EventsList &,
std::size_t) {
// Do nothing
};
}
}
} // namespace gd
#endif

View File

@@ -1,100 +1,117 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#if defined(GD_IDE_ONLY)
#ifndef EVENTMETADATA_H
#define EVENTMETADATA_H
#include "GDCore/String.h"
#include <vector>
#include <memory>
#include <functional>
#include <memory>
#include <vector>
#include "GDCore/String.h"
#if !defined(GD_NO_WX_GUI)
#include <wx/bitmap.h>
#endif
class wxBitmap;
namespace gd { class EventsList; }
namespace gd { class BaseEvent; }
namespace gd { class EventsCodeGenerator; }
namespace gd { class EventsCodeGenerationContext; }
namespace gd {
class EventsList;
}
namespace gd {
class BaseEvent;
}
namespace gd {
class EventsCodeGenerator;
}
namespace gd {
class EventsCodeGenerationContext;
}
namespace gd
{
namespace gd {
/**
* \brief Describe an event provided by an extension of a platform.
*
* Extensions writers, you should most of the time be using PlatformExtension::AddEvent method
* to add events.
* Extensions writers, you should most of the time be using
* PlatformExtension::AddEvent method to add events.
*/
class GD_CORE_API EventMetadata
{
public:
/**
* \brief Set the code generator used when generating code from events.
*/
EventMetadata & SetCodeGenerator(std::function<gd::String(gd::BaseEvent & event, gd::EventsCodeGenerator & codeGenerator,
gd::EventsCodeGenerationContext & context)> function) {
hasCustomCodeGenerator = true;
codeGeneration = function;
return *this;
}
class GD_CORE_API EventMetadata {
public:
/**
* \brief Set the code generator used when generating code from events.
*/
EventMetadata& SetCodeGenerator(
std::function<gd::String(gd::BaseEvent& event,
gd::EventsCodeGenerator& codeGenerator,
gd::EventsCodeGenerationContext& context)>
function) {
hasCustomCodeGenerator = true;
codeGeneration = function;
return *this;
}
/**
* \brief Set the code to preprocess the event.
*/
EventMetadata & SetPreprocessing(std::function<void(gd::BaseEvent & event, gd::EventsCodeGenerator & codeGenerator,
gd::EventsList & eventList, std::size_t indexOfTheEventInThisList)> function) {
preprocessing = function;
return *this;
}
/**
* \brief Set the code to preprocess the event.
*/
EventMetadata& SetPreprocessing(
std::function<void(gd::BaseEvent& event,
gd::EventsCodeGenerator& codeGenerator,
gd::EventsList& eventList,
std::size_t indexOfTheEventInThisList)> function) {
preprocessing = function;
return *this;
}
/**
* \brief Reset the code generation and preprocessing functions of the event.
*/
void ClearCodeGenerationAndPreprocessing();
/**
* \brief Reset the code generation and preprocessing functions of the event.
*/
void ClearCodeGenerationAndPreprocessing();
/**
* \brief Return true if SetCodeGenerator was called to set a function to call
* to generate the event code.
*/
bool HasCustomCodeGenerator() const { return hasCustomCodeGenerator; }
/**
* \brief Return true if SetCodeGenerator was called to set a function to call
* to generate the event code.
*/
bool HasCustomCodeGenerator() const { return hasCustomCodeGenerator; }
EventMetadata(const gd::String & name_,
const gd::String & fullname_,
const gd::String & description_,
const gd::String & group_,
const gd::String & smallicon_,
std::shared_ptr<gd::BaseEvent> instance);
EventMetadata(const gd::String& name_,
const gd::String& fullname_,
const gd::String& description_,
const gd::String& group_,
const gd::String& smallicon_,
std::shared_ptr<gd::BaseEvent> instance);
EventMetadata() {};
virtual ~EventMetadata() {};
EventMetadata(){};
virtual ~EventMetadata(){};
const gd::String & GetFullName() const { return fullname; }
const gd::String & GetDescription() const { return description; }
const gd::String & GetGroup() const { return group; }
const gd::String& GetFullName() const { return fullname; }
const gd::String& GetDescription() const { return description; }
const gd::String& GetGroup() const { return group; }
#if !defined(GD_NO_WX_GUI)
const wxBitmap & GetBitmapIcon() const { return smallicon; }
const wxBitmap& GetBitmapIcon() const { return smallicon; }
#endif
gd::String fullname;
gd::String description;
gd::String group;
gd::String fullname;
gd::String description;
gd::String group;
#if !defined(GD_NO_WX_GUI)
wxBitmap smallicon;
wxBitmap smallicon;
#endif
std::shared_ptr<gd::BaseEvent> instance;
bool hasCustomCodeGenerator;
std::function<gd::String(gd::BaseEvent & event, gd::EventsCodeGenerator & codeGenerator,
gd::EventsCodeGenerationContext & context)> codeGeneration;
std::function<void(gd::BaseEvent & event, gd::EventsCodeGenerator & codeGenerator,
gd::EventsList & eventList, std::size_t indexOfTheEventInThisList)> preprocessing;
std::shared_ptr<gd::BaseEvent> instance;
bool hasCustomCodeGenerator;
std::function<gd::String(gd::BaseEvent& event,
gd::EventsCodeGenerator& codeGenerator,
gd::EventsCodeGenerationContext& context)>
codeGeneration;
std::function<void(gd::BaseEvent& event,
gd::EventsCodeGenerator& codeGenerator,
gd::EventsList& eventList,
std::size_t indexOfTheEventInThisList)>
preprocessing;
};
}
} // namespace gd
#endif // EVENTMETADATA_H
#endif // EVENTMETADATA_H
#endif

View File

@@ -1,68 +1,70 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "ExpressionMetadata.h"
#include "GDCore/CommonTools.h"
#include "GDCore/String.h"
#if !defined(GD_NO_WX_GUI)
#include <wx/file.h>
#include <wx/bitmap.h>
#include <wx/file.h>
#endif
namespace gd
{
namespace gd {
ExpressionMetadata::ExpressionMetadata(const gd::String & extensionNamespace_,
const gd::String & name_,
const gd::String & fullname_,
const gd::String & description_,
const gd::String & group_,
const gd::String & smallicon_) :
fullname(fullname_),
description(description_),
group(group_),
shown(true),
smallIconFilename(smallicon_),
extensionNamespace(extensionNamespace_)
{
ExpressionMetadata::ExpressionMetadata(const gd::String& extensionNamespace_,
const gd::String& name_,
const gd::String& fullname_,
const gd::String& description_,
const gd::String& group_,
const gd::String& smallicon_)
: fullname(fullname_),
description(description_),
group(group_),
shown(true),
smallIconFilename(smallicon_),
extensionNamespace(extensionNamespace_) {
#if !defined(GD_NO_WX_GUI)
if ( wxFile::Exists(smallicon_) )
{
smallicon = wxBitmap(smallicon_, wxBITMAP_TYPE_ANY);
} else { smallicon = wxBitmap(16,16);}
if (wxFile::Exists(smallicon_)) {
smallicon = wxBitmap(smallicon_, wxBITMAP_TYPE_ANY);
} else {
smallicon = wxBitmap(16, 16);
}
#endif
}
ExpressionMetadata & ExpressionMetadata::SetHidden()
{
shown = false;
return *this;
ExpressionMetadata& ExpressionMetadata::SetHidden() {
shown = false;
return *this;
}
gd::ExpressionMetadata & ExpressionMetadata::AddParameter(const gd::String & type, const gd::String & description, const gd::String & optionalObjectType, bool parameterIsOptional)
{
gd::ParameterMetadata info;
info.type = type;
info.description = description;
info.codeOnly = false;
info.optional = parameterIsOptional;
info.supplementaryInformation = optionalObjectType.empty() ? "" : extensionNamespace+optionalObjectType;
gd::ExpressionMetadata& ExpressionMetadata::AddParameter(
const gd::String& type,
const gd::String& description,
const gd::String& optionalObjectType,
bool parameterIsOptional) {
gd::ParameterMetadata info;
info.type = type;
info.description = description;
info.codeOnly = false;
info.optional = parameterIsOptional;
info.supplementaryInformation =
optionalObjectType.empty() ? "" : extensionNamespace + optionalObjectType;
parameters.push_back(info);
return *this;
parameters.push_back(info);
return *this;
}
gd::ExpressionMetadata & ExpressionMetadata::AddCodeOnlyParameter(const gd::String & type, const gd::String & supplementaryInformation)
{
gd::ParameterMetadata info;
info.type = type;
info.codeOnly = true;
info.supplementaryInformation = supplementaryInformation;
gd::ExpressionMetadata& ExpressionMetadata::AddCodeOnlyParameter(
const gd::String& type, const gd::String& supplementaryInformation) {
gd::ParameterMetadata info;
info.type = type;
info.codeOnly = true;
info.supplementaryInformation = supplementaryInformation;
parameters.push_back(info);
return *this;
parameters.push_back(info);
return *this;
}
}
} // namespace gd

View File

@@ -1,209 +1,224 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef EXPRESSIONMETADATA_H
#define EXPRESSIONMETADATA_H
#if defined(GD_IDE_ONLY)
#include "GDCore/String.h"
#include <functional>
#include <memory>
#include "GDCore/Events/Instruction.h"
#include "GDCore/Extensions/Metadata/InstructionMetadata.h"
#include <memory>
#include <functional>
#include "GDCore/String.h"
#if !defined(GD_NO_WX_GUI)
#include <wx/bitmap.h>
#endif
class wxBitmap;
namespace gd { class Layout; }
namespace gd {
class Layout;
}
namespace gd
{
namespace gd {
/**
* \brief Information about how generate code for an expression
*/
class ExpressionCodeGenerationInformation
{
public:
ExpressionCodeGenerationInformation() : staticFunction(false), hasCustomCodeGenerator(false) {};
virtual ~ExpressionCodeGenerationInformation() {};
class ExpressionCodeGenerationInformation {
public:
ExpressionCodeGenerationInformation()
: staticFunction(false), hasCustomCodeGenerator(false){};
virtual ~ExpressionCodeGenerationInformation(){};
/**
* \brief Set the function name which will be used when generating the code.
* \param functionName the name of the function to call
*/
ExpressionCodeGenerationInformation & SetFunctionName(const gd::String & functionName)
{
functionCallName = functionName;
return *this;
}
/**
* \brief Set the function name which will be used when generating the code.
* \param functionName the name of the function to call
*/
ExpressionCodeGenerationInformation& SetFunctionName(
const gd::String& functionName) {
functionCallName = functionName;
return *this;
}
/**
* \brief Set that the function is static
*/
ExpressionCodeGenerationInformation & SetStatic()
{
staticFunction = true;
return *this;
}
/**
* \brief Set that the function is static
*/
ExpressionCodeGenerationInformation& SetStatic() {
staticFunction = true;
return *this;
}
/**
* \brief Erase any existing include file and add the specified include.
*/
ExpressionCodeGenerationInformation & SetIncludeFile(const gd::String & includeFile)
{
includeFiles.clear();
includeFiles.push_back(includeFile);
return *this;
}
/**
* \brief Erase any existing include file and add the specified include.
*/
ExpressionCodeGenerationInformation& SetIncludeFile(
const gd::String& includeFile) {
includeFiles.clear();
includeFiles.push_back(includeFile);
return *this;
}
/**
* \brief Add a file to the already existing include files.
*/
ExpressionCodeGenerationInformation & AddIncludeFile(const gd::String & includeFile)
{
if ( std::find(includeFiles.begin(), includeFiles.end(), includeFile) == includeFiles.end())
includeFiles.push_back(includeFile);
/**
* \brief Add a file to the already existing include files.
*/
ExpressionCodeGenerationInformation& AddIncludeFile(
const gd::String& includeFile) {
if (std::find(includeFiles.begin(), includeFiles.end(), includeFile) ==
includeFiles.end())
includeFiles.push_back(includeFile);
return *this;
}
return *this;
}
/**
* \brief Get the files that must be included to use the instruction.
*/
const std::vector<gd::String> & GetIncludeFiles() const { return includeFiles; };
/**
* \brief Get the files that must be included to use the instruction.
*/
const std::vector<gd::String>& GetIncludeFiles() const {
return includeFiles;
};
/**
* \brief Set that the function must be generated using a custom code generator.
*/
ExpressionCodeGenerationInformation & SetCustomCodeGenerator(std::function<gd::String(const std::vector<gd::Expression> & parameters,
gd::EventsCodeGenerator & codeGenerator, gd::EventsCodeGenerationContext & context)> codeGenerator)
{
hasCustomCodeGenerator = true;
customCodeGenerator = codeGenerator;
return *this;
}
/**
* \brief Set that the function must be generated using a custom code
* generator.
*/
ExpressionCodeGenerationInformation& SetCustomCodeGenerator(
std::function<gd::String(const std::vector<gd::Expression>& parameters,
gd::EventsCodeGenerator& codeGenerator,
gd::EventsCodeGenerationContext& context)>
codeGenerator) {
hasCustomCodeGenerator = true;
customCodeGenerator = codeGenerator;
return *this;
}
ExpressionCodeGenerationInformation & RemoveCustomCodeGenerator()
{
hasCustomCodeGenerator = false;
std::function<gd::String(const std::vector<gd::Expression> & parameters,
gd::EventsCodeGenerator & codeGenerator, gd::EventsCodeGenerationContext & context)> emptyFunction;
customCodeGenerator = emptyFunction;
return *this;
}
ExpressionCodeGenerationInformation& RemoveCustomCodeGenerator() {
hasCustomCodeGenerator = false;
std::function<gd::String(const std::vector<gd::Expression>& parameters,
gd::EventsCodeGenerator& codeGenerator,
gd::EventsCodeGenerationContext& context)>
emptyFunction;
customCodeGenerator = emptyFunction;
return *this;
}
bool HasCustomCodeGenerator() const { return hasCustomCodeGenerator; }
bool HasCustomCodeGenerator() const { return hasCustomCodeGenerator; }
bool staticFunction;
gd::String functionCallName;
bool hasCustomCodeGenerator;
std::function<gd::String(
const std::vector<gd::Expression> & parameters,
gd::EventsCodeGenerator & codeGenerator,
gd::EventsCodeGenerationContext & context)> customCodeGenerator;
bool staticFunction;
gd::String functionCallName;
bool hasCustomCodeGenerator;
std::function<gd::String(const std::vector<gd::Expression>& parameters,
gd::EventsCodeGenerator& codeGenerator,
gd::EventsCodeGenerationContext& context)>
customCodeGenerator;
private:
std::vector<gd::String> includeFiles;
private:
std::vector<gd::String> includeFiles;
};
/**
* \brief Contains user-friendly infos about expressions and members needed to setup an expression
* \brief Contains user-friendly infos about expressions and members needed to
* setup an expression
*
* \ingroup Events
*/
class GD_CORE_API ExpressionMetadata
{
public:
class GD_CORE_API ExpressionMetadata {
public:
ExpressionMetadata(const gd::String& extensionNamespace,
const gd::String& name,
const gd::String& fullname,
const gd::String& description,
const gd::String& group,
const gd::String& smallicon);
virtual ~ExpressionMetadata(){};
ExpressionMetadata(const gd::String & extensionNamespace,
const gd::String & name,
const gd::String & fullname,
const gd::String & description,
const gd::String & group,
const gd::String & smallicon);
virtual ~ExpressionMetadata() {};
/**
* \brief Set the expression as not shown in the IDE.
*/
ExpressionMetadata& SetHidden();
/**
* \brief Set the expression as not shown in the IDE.
*/
ExpressionMetadata & SetHidden();
/**
* \brief Set the group of the instruction in the IDE.
*/
ExpressionMetadata& SetGroup(const gd::String& str) {
group = str;
return *this;
}
/**
* \brief Set the group of the instruction in the IDE.
*/
ExpressionMetadata & SetGroup(const gd::String & str)
{
group = str;
return *this;
}
/**
* \see gd::InstructionMetadata::AddParameter
*/
gd::ExpressionMetadata& AddParameter(
const gd::String& type,
const gd::String& description,
const gd::String& optionalObjectType = "",
bool parameterIsOptional = false);
/**
* \see gd::InstructionMetadata::AddParameter
*/
gd::ExpressionMetadata & AddParameter(const gd::String & type, const gd::String & description, const gd::String & optionalObjectType = "", bool parameterIsOptional = false);
/**
* \see gd::InstructionMetadata::AddCodeOnlyParameter
*/
gd::ExpressionMetadata& AddCodeOnlyParameter(
const gd::String& type, const gd::String& supplementaryInformation);
/**
* \see gd::InstructionMetadata::AddCodeOnlyParameter
*/
gd::ExpressionMetadata & AddCodeOnlyParameter(const gd::String & type, const gd::String & supplementaryInformation);
/**
* Set the default value used in editor (or if an optional parameter is empty
* during code generation) for the latest added parameter.
*
* \see AddParameter
*/
ExpressionMetadata& SetDefaultValue(gd::String defaultValue_) {
if (!parameters.empty()) parameters.back().defaultValue = defaultValue_;
return *this;
};
/**
* Set the default value used in editor (or if an optional parameter is empty during code generation) for the latest added parameter.
*
* \see AddParameter
*/
ExpressionMetadata & SetDefaultValue(gd::String defaultValue_)
{
if ( !parameters.empty() ) parameters.back().defaultValue = defaultValue_;
return *this;
};
/**
* \brief Set the function that should be called when generating the source
* code from events.
* \param functionName the name of the function to call
* \note Shortcut for `codeExtraInformation.SetFunctionName`.
*/
ExpressionCodeGenerationInformation& SetFunctionName(
const gd::String& functionName) {
return codeExtraInformation.SetFunctionName(functionName);
}
/**
* \brief Set the function that should be called when generating the source
* code from events.
* \param functionName the name of the function to call
* \note Shortcut for `codeExtraInformation.SetFunctionName`.
*/
ExpressionCodeGenerationInformation & SetFunctionName(const gd::String & functionName)
{
return codeExtraInformation.SetFunctionName(functionName);
}
ExpressionCodeGenerationInformation codeExtraInformation;
ExpressionCodeGenerationInformation codeExtraInformation;
/** Don't use this constructor. Only here to fullfil std::map requirements
*/
ExpressionMetadata() : shown(false){};
/** Don't use this constructor. Only here to fullfil std::map requirements
*/
ExpressionMetadata() : shown(false) {};
bool IsShown() const { return shown; }
const gd::String & GetFullName() const { return fullname; }
const gd::String & GetDescription() const { return description; }
const gd::String & GetGroup() const { return group; }
const gd::String & GetSmallIconFilename() const { return smallIconFilename; }
bool IsShown() const { return shown; }
const gd::String& GetFullName() const { return fullname; }
const gd::String& GetDescription() const { return description; }
const gd::String& GetGroup() const { return group; }
const gd::String& GetSmallIconFilename() const { return smallIconFilename; }
#if !defined(GD_NO_WX_GUI)
const wxBitmap & GetBitmapIcon() const { return smallicon; }
const wxBitmap& GetBitmapIcon() const { return smallicon; }
#endif
const gd::ParameterMetadata & GetParameter(std::size_t id) const { return parameters[id]; };
gd::ParameterMetadata & GetParameter(std::size_t id) { return parameters[id]; };
std::size_t GetParametersCount() const { return parameters.size(); };
const gd::ParameterMetadata& GetParameter(std::size_t id) const {
return parameters[id];
};
gd::ParameterMetadata& GetParameter(std::size_t id) {
return parameters[id];
};
std::size_t GetParametersCount() const { return parameters.size(); };
std::vector < gd::ParameterMetadata > parameters;
private:
gd::String fullname;
gd::String description;
gd::String group;
bool shown;
std::vector<gd::ParameterMetadata> parameters;
private:
gd::String fullname;
gd::String description;
gd::String group;
bool shown;
#if !defined(GD_NO_WX_GUI)
wxBitmap smallicon;
wxBitmap smallicon;
#endif
gd::String smallIconFilename;
gd::String extensionNamespace;
gd::String smallIconFilename;
gd::String extensionNamespace;
};
}
} // namespace gd
#endif
#endif // EXPRESSIONMETADATA_H
#endif // EXPRESSIONMETADATA_H

View File

@@ -1,86 +1,84 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#if !defined(GD_NO_WX_GUI)
#include <wx/file.h>
#include <wx/bitmap.h>
#include <wx/file.h>
#endif
#include <algorithm>
#include "InstructionMetadata.h"
#include "GDCore/CommonTools.h"
#include "GDCore/Tools/Localization.h"
#include "InstructionMetadata.h"
namespace gd
{
InstructionMetadata::InstructionMetadata() :
sentence(_("Unknown or unsupported instruction")),
canHaveSubInstructions(false),
hidden(true)
{
}
namespace gd {
InstructionMetadata::InstructionMetadata()
: sentence(_("Unknown or unsupported instruction")),
canHaveSubInstructions(false),
hidden(true) {}
InstructionMetadata::InstructionMetadata(const gd::String & extensionNamespace_,
const gd::String & name_,
const gd::String & fullname_,
const gd::String & description_,
const gd::String & sentence_,
const gd::String & group_,
const gd::String & icon_,
const gd::String & smallIcon_) :
fullname(fullname_),
description(description_),
helpPage(),
sentence(sentence_),
group(group_),
iconFilename(icon_),
smallIconFilename(smallIcon_),
canHaveSubInstructions(false),
extensionNamespace(extensionNamespace_),
hidden(false),
usageComplexity(5)
{
InstructionMetadata::InstructionMetadata(const gd::String& extensionNamespace_,
const gd::String& name_,
const gd::String& fullname_,
const gd::String& description_,
const gd::String& sentence_,
const gd::String& group_,
const gd::String& icon_,
const gd::String& smallIcon_)
: fullname(fullname_),
description(description_),
helpPage(),
sentence(sentence_),
group(group_),
iconFilename(icon_),
smallIconFilename(smallIcon_),
canHaveSubInstructions(false),
extensionNamespace(extensionNamespace_),
hidden(false),
usageComplexity(5) {
#if !defined(GD_NO_WX_GUI)
if ( wxFile::Exists(icon_) )
{
icon = wxBitmap(icon_, wxBITMAP_TYPE_ANY);
} else { icon = wxBitmap(24,24);}
if ( wxFile::Exists(smallIcon_) )
{
smallicon = wxBitmap(smallIcon_, wxBITMAP_TYPE_ANY);
} else { smallicon = wxBitmap(16,16);}
if (wxFile::Exists(icon_)) {
icon = wxBitmap(icon_, wxBITMAP_TYPE_ANY);
} else {
icon = wxBitmap(24, 24);
}
if (wxFile::Exists(smallIcon_)) {
smallicon = wxBitmap(smallIcon_, wxBITMAP_TYPE_ANY);
} else {
smallicon = wxBitmap(16, 16);
}
#endif
}
ParameterMetadata::ParameterMetadata() :
optional(false),
codeOnly(false)
{
ParameterMetadata::ParameterMetadata() : optional(false), codeOnly(false) {}
InstructionMetadata& InstructionMetadata::AddParameter(
const gd::String& type,
const gd::String& description,
const gd::String& optionalObjectType,
bool parameterIsOptional) {
ParameterMetadata info;
info.type = type;
info.description = description;
info.codeOnly = false;
info.optional = parameterIsOptional;
info.supplementaryInformation =
optionalObjectType.empty() ? "" : extensionNamespace + optionalObjectType;
parameters.push_back(info);
return *this;
}
InstructionMetadata & InstructionMetadata::AddParameter(const gd::String & type, const gd::String & description, const gd::String & optionalObjectType, bool parameterIsOptional)
{
ParameterMetadata info;
info.type = type;
info.description = description;
info.codeOnly = false;
info.optional = parameterIsOptional;
info.supplementaryInformation = optionalObjectType.empty() ? "" : extensionNamespace+optionalObjectType;
InstructionMetadata& InstructionMetadata::AddCodeOnlyParameter(
const gd::String& type, const gd::String& supplementaryInformation) {
ParameterMetadata info;
info.type = type;
info.codeOnly = true;
info.supplementaryInformation = supplementaryInformation;
parameters.push_back(info);
return *this;
parameters.push_back(info);
return *this;
}
InstructionMetadata & InstructionMetadata::AddCodeOnlyParameter(const gd::String & type, const gd::String & supplementaryInformation)
{
ParameterMetadata info;
info.type = type;
info.codeOnly = true;
info.supplementaryInformation = supplementaryInformation;
parameters.push_back(info);
return *this;
}
}
} // namespace gd

View File

@@ -1,402 +1,426 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef INSTRUCTIONMETADATA_H
#define INSTRUCTIONMETADATA_H
#if defined(GD_IDE_ONLY)
#include "GDCore/String.h"
#include "GDCore/Events/Instruction.h"
#include <memory>
#include <functional>
#include <map>
#include <memory>
#include "GDCore/Events/Instruction.h"
#include "GDCore/String.h"
#if !defined(GD_NO_WX_GUI)
#include <wx/bitmap.h>
#endif
#include "GDCore/String.h"
class wxBitmap;
namespace gd { class Project; }
namespace gd { class Layout; }
namespace gd { class EventsCodeGenerator; }
namespace gd { class EventsCodeGenerationContext; }
namespace gd
{
/**
* \brief Contains user-friendly info about a parameter, and information about what a parameter need
*
* \ingroup Events
*/
class GD_CORE_API ParameterMetadata
{
public:
ParameterMetadata();
virtual ~ParameterMetadata() {};
/**
* \brief Return the type of the parameter.
* \see gd::ParameterMetadata::IsObject
*/
const gd::String & GetType() const { return type; }
/**
* \brief Return an optional additional information, used for some parameters with special
* type (For example, it can contains the type of object accepted by the parameter).
*/
const gd::String & GetExtraInfo() const { return supplementaryInformation; }
/**
* \brief Return true if the parameter is optional.
*/
bool IsOptional() const { return optional; }
/**
* \brief Return the description of the parameter
*/
const gd::String & GetDescription() const { return description; }
/**
* \brief Return true if the parameter is only meant to be completed during compilation
* and must not be displayed to the user.
*/
bool IsCodeOnly() const { return codeOnly; }
/**
* \brief Get the default value for the parameter.
*/
const gd::String & GetDefaultValue() const { return defaultValue; }
gd::String type; ///< Parameter type
gd::String supplementaryInformation; ///< Used if needed
bool optional; ///< True if the parameter is optional
gd::String description; ///< Description shown in editor
bool codeOnly; ///< True if parameter is relative to code generation only, i.e. must not be shown in editor
gd::String defaultValue; ///< Used as a default value in editor or if an optional parameter is empty.
/**
* \brief Return true if the type of the parameter is "object", "objectPtr" or "objectList".
* \see gd::ParameterMetadata::GetType
*/
static bool IsObject(const gd::String & type) { return type == "object" || type == "objectPtr" || type == "objectList" || type == "objectListWithoutPicking"; }
};
/**
* \brief Contains user-friendly infos about actions/conditions, and members needed to setup an instruction
*
* \ingroup Events
*/
class GD_CORE_API InstructionMetadata
{
public:
InstructionMetadata(const gd::String & extensionNamespace,
const gd::String & name,
const gd::String & fullname,
const gd::String & description,
const gd::String & sentence,
const gd::String & group,
const gd::String & icon,
const gd::String & smallIcon);
virtual ~InstructionMetadata() {};
const gd::String & GetFullName() const { return fullname; }
const gd::String & GetDescription() const { return description; }
const gd::String & GetSentence() const { return sentence; }
const gd::String & GetGroup() const { return group; }
const ParameterMetadata & GetParameter(size_t i) const { return parameters[i]; }
size_t GetParametersCount() const { return parameters.size(); }
#if !defined(GD_NO_WX_GUI)
const wxBitmap & GetBitmapIcon() const { return icon; }
const wxBitmap & GetSmallBitmapIcon() const { return smallicon; }
#endif
const gd::String & GetIconFilename() const { return iconFilename; }
const gd::String & GetSmallIconFilename() const { return smallIconFilename; }
bool CanHaveSubInstructions() const { return canHaveSubInstructions; }
/**
* Get the help page of the instruction.
*/
const gd::String & GetHelpPage() const { return helpPage; }
/**
* Set the help page of the instruction.
*/
InstructionMetadata & SetHelpPage(const gd::String &page)
{
helpPage = page;
return *this;
}
/**
* Notify that the instruction can have sub instructions.
*/
InstructionMetadata & SetCanHaveSubInstructions()
{
canHaveSubInstructions = true;
return *this;
}
/**
* \brief Set the instruction to be hidden in the IDE.
*
* Used mainly when an instruction is deprecated.
*/
InstructionMetadata & SetHidden()
{
hidden = true;
return *this;
}
/**
* \brief Set the group of the instruction in the IDE.
*/
InstructionMetadata & SetGroup(const gd::String & str)
{
group = str;
return *this;
}
/**
* \brief Return true if the instruction must be hidden in the IDE.
*/
bool IsHidden() const { return hidden; }
/**
* \brief Add a parameter to the instruction ( condition or action ) information class.
* \param type One of the type handled by GDevelop.
* This will also determine the type of the argument used when calling the function in the generated code. \see EventsCodeGenerator::GenerateParametersCodes
* \param description Description for parameter
* \param optionalObjectType If type is "object", this parameter will describe which objects are allowed. If it is empty, all objects are allowed.
* \param parameterIsOptional true if the parameter must be optional, false otherwise.
*/
InstructionMetadata & AddParameter(const gd::String & type, const gd::String & description, const gd::String & optionalObjectType = "", bool parameterIsOptional = false);
/**
* \brief Add a parameter not displayed in editor.
* \param type One of the type handled by GDevelop. This will also determine the type of the argument used when calling the function in C++ code. \see EventsCodeGenerator::GenerateParametersCodes
* \param supplementaryInformation Can be used if needed. For example, when type == "inlineCode", the content of supplementaryInformation is inserted in the generated C++ code.
*/
InstructionMetadata & AddCodeOnlyParameter(const gd::String & type, const gd::String & supplementaryInformation);
/**
* \brief Set the default value used in editor (or if an optional parameter is empty during code generation) for the latest added parameter.
*
* \see AddParameter
*/
InstructionMetadata & SetDefaultValue(gd::String defaultValue_)
{
if ( !parameters.empty() ) parameters.back().defaultValue = defaultValue_;
return *this;
};
/**
* \brief Consider that the instruction is easy for an user to understand.
*/
InstructionMetadata & MarkAsSimple()
{
usageComplexity = 2;
return *this;
}
/**
* \brief Consider that the instruction is harder for an user to understand
* than a normal instruction.
*/
InstructionMetadata & MarkAsAdvanced()
{
usageComplexity = 7;
return *this;
}
/**
* \brief Consider that the instruction is complex for an user to understand.
*/
InstructionMetadata & MarkAsComplex()
{
usageComplexity = 9;
return *this;
}
/**
* \brief Return the usage complexity of this instruction for the user,
* from 0 (simple&easy to use) to 10 (complex to understand).
*/
int GetUsageComplexity() const { return usageComplexity; }
/**
* \brief Defines information about how generate the code for an instruction
*/
class ExtraInformation
{
public:
enum AccessType {Reference, MutatorAndOrAccessor, Mutators};
ExtraInformation() : accessType(Reference), hasCustomCodeGenerator(false) {};
virtual ~ExtraInformation() {};
/**
* Set the function name which will be used when generating the code.
* \param functionName the name of the function to call
*/
ExtraInformation & SetFunctionName(const gd::String & functionName_)
{
functionCallName = functionName_;
return *this;
}
/**
* Declare if the instruction being declared is somewhat manipulating in a standard way.
*/
ExtraInformation & SetManipulatedType(const gd::String & type_)
{
type = type_;
return *this;
}
/**
* If InstructionMetadata::ExtraInformation::SetManipulatedType was called with "number" or "string", this function will tell the code generator
* the name of the getter function used to retrieve the data value.
*
* Usage example:
* \code
* obj.AddAction("String",
* _("Change the string"),
* _("Change the string of a text"),
* _("Do _PARAM1__PARAM2_ to the string of _PARAM0_"),
* _("Text"),
* "CppPlatform/Extensions/text24.png",
* "CppPlatform/Extensions/text.png");
*
* .AddParameter("object", _("Object"), "Text", false)
* .AddParameter("operator", _("Modification operator"))
* .AddParameter("string", _("String"))
* .SetFunctionName("SetString").SetManipulatedType("string").SetGetter("GetString").SetIncludeFile("MyExtension/TextObject.h");
*
* DECLARE_END_OBJECT_ACTION()
* \endcode
*/
ExtraInformation & SetGetter(const gd::String & getter)
{
optionalAssociatedInstruction = getter;
accessType = MutatorAndOrAccessor;
return *this;
}
ExtraInformation & SetMutators(const std::map<gd::String, gd::String> & mutators)
{
optionalMutators = mutators;
accessType = Mutators;
return *this;
}
/**
* \brief Erase any existing include file and add the specified include.
*/
ExtraInformation & SetIncludeFile(const gd::String & includeFile)
{
includeFiles.clear();
includeFiles.push_back(includeFile);
return *this;
}
/**
* \brief Add a file to the already existing include files.
*/
ExtraInformation & AddIncludeFile(const gd::String & includeFile)
{
if ( std::find(includeFiles.begin(), includeFiles.end(), includeFile) == includeFiles.end())
includeFiles.push_back(includeFile);
return *this;
}
/**
* \brief Get the files that must be included to use the instruction.
*/
const std::vector<gd::String> & GetIncludeFiles() const { return includeFiles; };
ExtraInformation & SetCustomCodeGenerator(std::function<gd::String(Instruction & instruction,
gd::EventsCodeGenerator & codeGenerator, gd::EventsCodeGenerationContext & context)> codeGenerator)
{
hasCustomCodeGenerator = true;
customCodeGenerator = codeGenerator;
return *this;
}
ExtraInformation & RemoveCustomCodeGenerator()
{
hasCustomCodeGenerator = false;
std::function<gd::String(Instruction & instruction,
gd::EventsCodeGenerator & codeGenerator, gd::EventsCodeGenerationContext & context)> emptyFunction;
customCodeGenerator = emptyFunction;
return *this;
}
bool HasCustomCodeGenerator() const { return hasCustomCodeGenerator; }
gd::String functionCallName;
gd::String type;
AccessType accessType;
gd::String optionalAssociatedInstruction;
std::map<gd::String, gd::String> optionalMutators;
bool hasCustomCodeGenerator;
std::function<gd::String(Instruction & instruction,
gd::EventsCodeGenerator & codeGenerator, gd::EventsCodeGenerationContext & context)> customCodeGenerator;
private:
std::vector<gd::String> includeFiles;
};
ExtraInformation codeExtraInformation; ///< Information about how generate code for the instruction
/**
* \brief Declare if the instruction being declared is somewhat manipulating in a standard way.
* \param type "number" or "string"
* \note Shortcut for `codeExtraInformation.SetManipulatedType(type)`.
*/
ExtraInformation & SetManipulatedType(const gd::String & type_)
{
return codeExtraInformation.SetManipulatedType(type_);
}
/**
* \brief Set the function that should be called when generating the source
* code from events.
* \param functionName the name of the function to call
* \note Shortcut for `codeExtraInformation.SetFunctionName`.
*/
ExtraInformation & SetFunctionName(const gd::String & functionName)
{
return codeExtraInformation.SetFunctionName(functionName);
}
/** \brief DefaultConstructor.
* \warning Please do not use this constructor. Only here to fulfill std::map requirements.
*/
InstructionMetadata();
std::vector < ParameterMetadata > parameters;
private:
gd::String fullname;
gd::String description;
gd::String helpPage;
gd::String sentence;
gd::String group;
#if !defined(GD_NO_WX_GUI)
wxBitmap icon;
wxBitmap smallicon;
#endif
gd::String iconFilename;
gd::String smallIconFilename;
bool canHaveSubInstructions;
gd::String extensionNamespace;
bool hidden;
int usageComplexity; ///< Evaluate the instruction from 0 (simple&easy to use) to 10 (complex to understand)
};
namespace gd {
class Project;
}
namespace gd {
class Layout;
}
namespace gd {
class EventsCodeGenerator;
}
namespace gd {
class EventsCodeGenerationContext;
}
namespace gd {
/**
* \brief Contains user-friendly info about a parameter, and information about
* what a parameter need
*
* \ingroup Events
*/
class GD_CORE_API ParameterMetadata {
public:
ParameterMetadata();
virtual ~ParameterMetadata(){};
/**
* \brief Return the type of the parameter.
* \see gd::ParameterMetadata::IsObject
*/
const gd::String &GetType() const { return type; }
/**
* \brief Return an optional additional information, used for some parameters
* with special type (For example, it can contains the type of object accepted
* by the parameter).
*/
const gd::String &GetExtraInfo() const { return supplementaryInformation; }
/**
* \brief Return true if the parameter is optional.
*/
bool IsOptional() const { return optional; }
/**
* \brief Return the description of the parameter
*/
const gd::String &GetDescription() const { return description; }
/**
* \brief Return true if the parameter is only meant to be completed during
* compilation and must not be displayed to the user.
*/
bool IsCodeOnly() const { return codeOnly; }
/**
* \brief Get the default value for the parameter.
*/
const gd::String &GetDefaultValue() const { return defaultValue; }
gd::String type; ///< Parameter type
gd::String supplementaryInformation; ///< Used if needed
bool optional; ///< True if the parameter is optional
gd::String description; ///< Description shown in editor
bool codeOnly; ///< True if parameter is relative to code generation only,
///< i.e. must not be shown in editor
gd::String defaultValue; ///< Used as a default value in editor or if an
///< optional parameter is empty.
/**
* \brief Return true if the type of the parameter is "object", "objectPtr" or
* "objectList". \see gd::ParameterMetadata::GetType
*/
static bool IsObject(const gd::String &type) {
return type == "object" || type == "objectPtr" || type == "objectList" ||
type == "objectListWithoutPicking";
}
};
/**
* \brief Contains user-friendly infos about actions/conditions, and members
* needed to setup an instruction
*
* \ingroup Events
*/
class GD_CORE_API InstructionMetadata {
public:
InstructionMetadata(const gd::String &extensionNamespace,
const gd::String &name,
const gd::String &fullname,
const gd::String &description,
const gd::String &sentence,
const gd::String &group,
const gd::String &icon,
const gd::String &smallIcon);
virtual ~InstructionMetadata(){};
const gd::String &GetFullName() const { return fullname; }
const gd::String &GetDescription() const { return description; }
const gd::String &GetSentence() const { return sentence; }
const gd::String &GetGroup() const { return group; }
const ParameterMetadata &GetParameter(size_t i) const {
return parameters[i];
}
size_t GetParametersCount() const { return parameters.size(); }
#if !defined(GD_NO_WX_GUI)
const wxBitmap &GetBitmapIcon() const { return icon; }
const wxBitmap &GetSmallBitmapIcon() const { return smallicon; }
#endif
#endif // INSTRUCTIONMETADATA_H
const gd::String &GetIconFilename() const { return iconFilename; }
const gd::String &GetSmallIconFilename() const { return smallIconFilename; }
bool CanHaveSubInstructions() const { return canHaveSubInstructions; }
/**
* Get the help page of the instruction.
*/
const gd::String &GetHelpPage() const { return helpPage; }
/**
* Set the help page of the instruction.
*/
InstructionMetadata &SetHelpPage(const gd::String &page) {
helpPage = page;
return *this;
}
/**
* Notify that the instruction can have sub instructions.
*/
InstructionMetadata &SetCanHaveSubInstructions() {
canHaveSubInstructions = true;
return *this;
}
/**
* \brief Set the instruction to be hidden in the IDE.
*
* Used mainly when an instruction is deprecated.
*/
InstructionMetadata &SetHidden() {
hidden = true;
return *this;
}
/**
* \brief Set the group of the instruction in the IDE.
*/
InstructionMetadata &SetGroup(const gd::String &str) {
group = str;
return *this;
}
/**
* \brief Return true if the instruction must be hidden in the IDE.
*/
bool IsHidden() const { return hidden; }
/**
* \brief Add a parameter to the instruction ( condition or action )
* information class. \param type One of the type handled by GDevelop. This
* will also determine the type of the argument used when calling the function
* in the generated code. \see EventsCodeGenerator::GenerateParametersCodes
* \param description Description for parameter
* \param optionalObjectType If type is "object", this parameter will describe
* which objects are allowed. If it is empty, all objects are allowed. \param
* parameterIsOptional true if the parameter must be optional, false
* otherwise.
*/
InstructionMetadata &AddParameter(const gd::String &type,
const gd::String &description,
const gd::String &optionalObjectType = "",
bool parameterIsOptional = false);
/**
* \brief Add a parameter not displayed in editor.
* \param type One of the type handled by GDevelop. This will also determine
* the type of the argument used when calling the function in C++ code. \see
* EventsCodeGenerator::GenerateParametersCodes \param
* supplementaryInformation Can be used if needed. For example, when type ==
* "inlineCode", the content of supplementaryInformation is inserted in the
* generated C++ code.
*/
InstructionMetadata &AddCodeOnlyParameter(
const gd::String &type, const gd::String &supplementaryInformation);
/**
* \brief Set the default value used in editor (or if an optional parameter is
* empty during code generation) for the latest added parameter.
*
* \see AddParameter
*/
InstructionMetadata &SetDefaultValue(gd::String defaultValue_) {
if (!parameters.empty()) parameters.back().defaultValue = defaultValue_;
return *this;
};
/**
* \brief Consider that the instruction is easy for an user to understand.
*/
InstructionMetadata &MarkAsSimple() {
usageComplexity = 2;
return *this;
}
/**
* \brief Consider that the instruction is harder for an user to understand
* than a normal instruction.
*/
InstructionMetadata &MarkAsAdvanced() {
usageComplexity = 7;
return *this;
}
/**
* \brief Consider that the instruction is complex for an user to understand.
*/
InstructionMetadata &MarkAsComplex() {
usageComplexity = 9;
return *this;
}
/**
* \brief Return the usage complexity of this instruction for the user,
* from 0 (simple&easy to use) to 10 (complex to understand).
*/
int GetUsageComplexity() const { return usageComplexity; }
/**
* \brief Defines information about how generate the code for an instruction
*/
class ExtraInformation {
public:
enum AccessType { Reference, MutatorAndOrAccessor, Mutators };
ExtraInformation() : accessType(Reference), hasCustomCodeGenerator(false){};
virtual ~ExtraInformation(){};
/**
* Set the function name which will be used when generating the code.
* \param functionName the name of the function to call
*/
ExtraInformation &SetFunctionName(const gd::String &functionName_) {
functionCallName = functionName_;
return *this;
}
/**
* Declare if the instruction being declared is somewhat manipulating in a
* standard way.
*/
ExtraInformation &SetManipulatedType(const gd::String &type_) {
type = type_;
return *this;
}
/**
* If InstructionMetadata::ExtraInformation::SetManipulatedType was called
* with "number" or "string", this function will tell the code generator the
* name of the getter function used to retrieve the data value.
*
* Usage example:
* \code
* obj.AddAction("String",
* _("Change the string"),
* _("Change the string of a text"),
* _("Do _PARAM1__PARAM2_ to the string of _PARAM0_"),
* _("Text"),
* "CppPlatform/Extensions/text24.png",
* "CppPlatform/Extensions/text.png");
*
* .AddParameter("object", _("Object"), "Text", false)
* .AddParameter("operator", _("Modification operator"))
* .AddParameter("string", _("String"))
* .SetFunctionName("SetString").SetManipulatedType("string").SetGetter("GetString").SetIncludeFile("MyExtension/TextObject.h");
*
* DECLARE_END_OBJECT_ACTION()
* \endcode
*/
ExtraInformation &SetGetter(const gd::String &getter) {
optionalAssociatedInstruction = getter;
accessType = MutatorAndOrAccessor;
return *this;
}
ExtraInformation &SetMutators(
const std::map<gd::String, gd::String> &mutators) {
optionalMutators = mutators;
accessType = Mutators;
return *this;
}
/**
* \brief Erase any existing include file and add the specified include.
*/
ExtraInformation &SetIncludeFile(const gd::String &includeFile) {
includeFiles.clear();
includeFiles.push_back(includeFile);
return *this;
}
/**
* \brief Add a file to the already existing include files.
*/
ExtraInformation &AddIncludeFile(const gd::String &includeFile) {
if (std::find(includeFiles.begin(), includeFiles.end(), includeFile) ==
includeFiles.end())
includeFiles.push_back(includeFile);
return *this;
}
/**
* \brief Get the files that must be included to use the instruction.
*/
const std::vector<gd::String> &GetIncludeFiles() const {
return includeFiles;
};
ExtraInformation &SetCustomCodeGenerator(
std::function<gd::String(Instruction &instruction,
gd::EventsCodeGenerator &codeGenerator,
gd::EventsCodeGenerationContext &context)>
codeGenerator) {
hasCustomCodeGenerator = true;
customCodeGenerator = codeGenerator;
return *this;
}
ExtraInformation &RemoveCustomCodeGenerator() {
hasCustomCodeGenerator = false;
std::function<gd::String(Instruction & instruction,
gd::EventsCodeGenerator & codeGenerator,
gd::EventsCodeGenerationContext & context)>
emptyFunction;
customCodeGenerator = emptyFunction;
return *this;
}
bool HasCustomCodeGenerator() const { return hasCustomCodeGenerator; }
gd::String functionCallName;
gd::String type;
AccessType accessType;
gd::String optionalAssociatedInstruction;
std::map<gd::String, gd::String> optionalMutators;
bool hasCustomCodeGenerator;
std::function<gd::String(Instruction &instruction,
gd::EventsCodeGenerator &codeGenerator,
gd::EventsCodeGenerationContext &context)>
customCodeGenerator;
private:
std::vector<gd::String> includeFiles;
};
ExtraInformation codeExtraInformation; ///< Information about how generate
///< code for the instruction
/**
* \brief Declare if the instruction being declared is somewhat manipulating
* in a standard way. \param type "number" or "string" \note Shortcut for
* `codeExtraInformation.SetManipulatedType(type)`.
*/
ExtraInformation &SetManipulatedType(const gd::String &type_) {
return codeExtraInformation.SetManipulatedType(type_);
}
/**
* \brief Set the function that should be called when generating the source
* code from events.
* \param functionName the name of the function to call
* \note Shortcut for `codeExtraInformation.SetFunctionName`.
*/
ExtraInformation &SetFunctionName(const gd::String &functionName) {
return codeExtraInformation.SetFunctionName(functionName);
}
/** \brief DefaultConstructor.
* \warning Please do not use this constructor. Only here to fulfill std::map
* requirements.
*/
InstructionMetadata();
std::vector<ParameterMetadata> parameters;
private:
gd::String fullname;
gd::String description;
gd::String helpPage;
gd::String sentence;
gd::String group;
#if !defined(GD_NO_WX_GUI)
wxBitmap icon;
wxBitmap smallicon;
#endif
gd::String iconFilename;
gd::String smallIconFilename;
bool canHaveSubInstructions;
gd::String extensionNamespace;
bool hidden;
int usageComplexity; ///< Evaluate the instruction from 0 (simple&easy to
///< use) to 10 (complex to understand)
};
} // namespace gd
#endif
#endif // INSTRUCTIONMETADATA_H

View File

@@ -1,21 +1,20 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "GDCore/Extensions/Metadata/MetadataProvider.h"
#include <algorithm>
#include "GDCore/Extensions/Metadata/BehaviorMetadata.h"
#include "GDCore/Extensions/Metadata/InstructionMetadata.h"
#include "GDCore/Extensions/Metadata/ObjectMetadata.h"
#include "GDCore/Extensions/Platform.h"
#include "GDCore/Extensions/PlatformExtension.h"
#include "GDCore/Extensions/Metadata/InstructionMetadata.h"
#include "GDCore/Extensions/Metadata/BehaviorMetadata.h"
#include "GDCore/Extensions/Metadata/ObjectMetadata.h"
#include <algorithm>
#include "GDCore/String.h"
using namespace std;
namespace gd
{
namespace gd {
gd::BehaviorMetadata MetadataProvider::badBehaviorInfo;
gd::ObjectMetadata MetadataProvider::badObjectInfo;
@@ -23,451 +22,465 @@ gd::InstructionMetadata MetadataProvider::badInstructionMetadata;
gd::ExpressionMetadata MetadataProvider::badExpressionMetadata;
gd::ExpressionMetadata MetadataProvider::badStrExpressionMetadata;
/**
* Get the metadata about a behavior in a platform
*/
const BehaviorMetadata & MetadataProvider::GetBehaviorMetadata(const gd::Platform & platform, gd::String behaviorType)
{
for (std::size_t i = 0;i<platform.GetAllPlatformExtensions().size();++i)
{
std::vector<gd::String> autosTypes = platform.GetAllPlatformExtensions()[i]->GetBehaviorsTypes();
for(std::size_t j = 0;j<autosTypes.size();++j)
{
if ( autosTypes[j] == behaviorType )
return platform.GetAllPlatformExtensions()[i]->GetBehaviorMetadata(behaviorType);
}
}
const BehaviorMetadata& MetadataProvider::GetBehaviorMetadata(
const gd::Platform& platform, gd::String behaviorType) {
for (std::size_t i = 0; i < platform.GetAllPlatformExtensions().size(); ++i) {
std::vector<gd::String> autosTypes =
platform.GetAllPlatformExtensions()[i]->GetBehaviorsTypes();
for (std::size_t j = 0; j < autosTypes.size(); ++j) {
if (autosTypes[j] == behaviorType)
return platform.GetAllPlatformExtensions()[i]->GetBehaviorMetadata(
behaviorType);
}
}
return badBehaviorInfo;
return badBehaviorInfo;
}
/**
* Get the metadata about an object in a platform
*/
const ObjectMetadata & MetadataProvider::GetObjectMetadata(const gd::Platform & platform, gd::String objectType)
{
for (std::size_t i = 0;i<platform.GetAllPlatformExtensions().size();++i)
{
std::vector<gd::String> objectsTypes = platform.GetAllPlatformExtensions()[i]->GetExtensionObjectsTypes();
for(std::size_t j = 0;j<objectsTypes.size();++j)
{
if ( objectsTypes[j] == objectType )
return platform.GetAllPlatformExtensions()[i]->GetObjectMetadata(objectType);
}
}
const ObjectMetadata& MetadataProvider::GetObjectMetadata(
const gd::Platform& platform, gd::String objectType) {
for (std::size_t i = 0; i < platform.GetAllPlatformExtensions().size(); ++i) {
std::vector<gd::String> objectsTypes =
platform.GetAllPlatformExtensions()[i]->GetExtensionObjectsTypes();
for (std::size_t j = 0; j < objectsTypes.size(); ++j) {
if (objectsTypes[j] == objectType)
return platform.GetAllPlatformExtensions()[i]->GetObjectMetadata(
objectType);
}
}
return badObjectInfo;
return badObjectInfo;
}
const gd::InstructionMetadata & MetadataProvider::GetActionMetadata(const gd::Platform & platform, gd::String actionType)
{
std::vector < std::shared_ptr<PlatformExtension> > extensions = platform.GetAllPlatformExtensions();
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::InstructionMetadata> & allActions = extensions[i]->GetAllActions();
if ( allActions.find(actionType) != allActions.end() )
return allActions.find(actionType)->second;
const gd::InstructionMetadata& MetadataProvider::GetActionMetadata(
const gd::Platform& platform, gd::String actionType) {
std::vector<std::shared_ptr<PlatformExtension> > extensions =
platform.GetAllPlatformExtensions();
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::InstructionMetadata>& allActions =
extensions[i]->GetAllActions();
if (allActions.find(actionType) != allActions.end())
return allActions.find(actionType)->second;
const vector < gd::String > & objects = extensions[i]->GetExtensionObjectsTypes();
for (std::size_t j = 0;j<objects.size();++j)
{
const std::map<gd::String, gd::InstructionMetadata> & allObjectsActions = extensions[i]->GetAllActionsForObject(objects[j]);
if ( allObjectsActions.find(actionType) != allObjectsActions.end() )
return allObjectsActions.find(actionType)->second;
}
const vector < gd::String > & autos = extensions[i]->GetBehaviorsTypes();
for (std::size_t j = 0;j<autos.size();++j)
{
const std::map<gd::String, gd::InstructionMetadata> & allAutosActions = extensions[i]->GetAllActionsForBehavior(autos[j]);
if ( allAutosActions.find(actionType) != allAutosActions.end() )
return allAutosActions.find(actionType)->second;
}
const vector<gd::String>& objects =
extensions[i]->GetExtensionObjectsTypes();
for (std::size_t j = 0; j < objects.size(); ++j) {
const std::map<gd::String, gd::InstructionMetadata>& allObjectsActions =
extensions[i]->GetAllActionsForObject(objects[j]);
if (allObjectsActions.find(actionType) != allObjectsActions.end())
return allObjectsActions.find(actionType)->second;
}
return badInstructionMetadata;
const vector<gd::String>& autos = extensions[i]->GetBehaviorsTypes();
for (std::size_t j = 0; j < autos.size(); ++j) {
const std::map<gd::String, gd::InstructionMetadata>& allAutosActions =
extensions[i]->GetAllActionsForBehavior(autos[j]);
if (allAutosActions.find(actionType) != allAutosActions.end())
return allAutosActions.find(actionType)->second;
}
}
return badInstructionMetadata;
}
const gd::InstructionMetadata & MetadataProvider::GetConditionMetadata(const gd::Platform & platform, gd::String conditionType)
{
std::vector < std::shared_ptr<PlatformExtension> > extensions = platform.GetAllPlatformExtensions();
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::InstructionMetadata> & allConditions = extensions[i]->GetAllConditions();
if ( allConditions.find(conditionType) != allConditions.end() )
return allConditions.find(conditionType)->second;
const gd::InstructionMetadata& MetadataProvider::GetConditionMetadata(
const gd::Platform& platform, gd::String conditionType) {
std::vector<std::shared_ptr<PlatformExtension> > extensions =
platform.GetAllPlatformExtensions();
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::InstructionMetadata>& allConditions =
extensions[i]->GetAllConditions();
if (allConditions.find(conditionType) != allConditions.end())
return allConditions.find(conditionType)->second;
const vector < gd::String > & objects = extensions[i]->GetExtensionObjectsTypes();
for (std::size_t j = 0;j<objects.size();++j)
{
const std::map<gd::String, gd::InstructionMetadata> & allObjetsConditions = extensions[i]->GetAllConditionsForObject(objects[j]);
if ( allObjetsConditions.find(conditionType) != allObjetsConditions.end() )
return allObjetsConditions.find(conditionType)->second;
}
const vector < gd::String > & autos = extensions[i]->GetBehaviorsTypes();
for (std::size_t j = 0;j<autos.size();++j)
{
const std::map<gd::String, gd::InstructionMetadata> & allAutosConditions = extensions[i]->GetAllConditionsForBehavior(autos[j]);
if ( allAutosConditions.find(conditionType) != allAutosConditions.end() )
return allAutosConditions.find(conditionType)->second;
}
const vector<gd::String>& objects =
extensions[i]->GetExtensionObjectsTypes();
for (std::size_t j = 0; j < objects.size(); ++j) {
const std::map<gd::String, gd::InstructionMetadata>& allObjetsConditions =
extensions[i]->GetAllConditionsForObject(objects[j]);
if (allObjetsConditions.find(conditionType) != allObjetsConditions.end())
return allObjetsConditions.find(conditionType)->second;
}
return badInstructionMetadata;
const vector<gd::String>& autos = extensions[i]->GetBehaviorsTypes();
for (std::size_t j = 0; j < autos.size(); ++j) {
const std::map<gd::String, gd::InstructionMetadata>& allAutosConditions =
extensions[i]->GetAllConditionsForBehavior(autos[j]);
if (allAutosConditions.find(conditionType) != allAutosConditions.end())
return allAutosConditions.find(conditionType)->second;
}
}
return badInstructionMetadata;
}
const gd::ExpressionMetadata & MetadataProvider::GetObjectExpressionMetadata(const gd::Platform & platform, gd::String objectType, gd::String exprType)
{
std::vector < std::shared_ptr<PlatformExtension> > extensions = platform.GetAllPlatformExtensions();
for (std::size_t i =0;i<extensions.size();++i)
{
const vector < gd::String > & objects = extensions[i]->GetExtensionObjectsTypes();
if ( find(objects.begin(), objects.end(), objectType) != objects.end())
{
const std::map<gd::String, gd::ExpressionMetadata> & allObjectExpressions = extensions[i]->GetAllExpressionsForObject(objectType);
if ( allObjectExpressions.find(exprType) != allObjectExpressions.end() )
return allObjectExpressions.find(exprType)->second;
}
const gd::ExpressionMetadata& MetadataProvider::GetObjectExpressionMetadata(
const gd::Platform& platform, gd::String objectType, gd::String exprType) {
std::vector<std::shared_ptr<PlatformExtension> > extensions =
platform.GetAllPlatformExtensions();
for (std::size_t i = 0; i < extensions.size(); ++i) {
const vector<gd::String>& objects =
extensions[i]->GetExtensionObjectsTypes();
if (find(objects.begin(), objects.end(), objectType) != objects.end()) {
const std::map<gd::String, gd::ExpressionMetadata>& allObjectExpressions =
extensions[i]->GetAllExpressionsForObject(objectType);
if (allObjectExpressions.find(exprType) != allObjectExpressions.end())
return allObjectExpressions.find(exprType)->second;
}
}
//Then check base
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::ExpressionMetadata> & allObjectExpressions = extensions[i]->GetAllExpressionsForObject("");
if ( allObjectExpressions.find(exprType) != allObjectExpressions.end() )
return allObjectExpressions.find(exprType)->second;
}
// Then check base
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::ExpressionMetadata>& allObjectExpressions =
extensions[i]->GetAllExpressionsForObject("");
if (allObjectExpressions.find(exprType) != allObjectExpressions.end())
return allObjectExpressions.find(exprType)->second;
}
return badExpressionMetadata;
return badExpressionMetadata;
}
const gd::ExpressionMetadata & MetadataProvider::GetBehaviorExpressionMetadata(const gd::Platform & platform, gd::String autoType, gd::String exprType)
{
std::vector < std::shared_ptr<PlatformExtension> > extensions = platform.GetAllPlatformExtensions();
for (std::size_t i =0;i<extensions.size();++i)
{
const vector < gd::String > & autos = extensions[i]->GetBehaviorsTypes();
if ( find(autos.begin(), autos.end(), autoType) != autos.end())
{
const std::map<gd::String, gd::ExpressionMetadata> & allAutoExpressions = extensions[i]->GetAllExpressionsForBehavior(autoType);
if ( allAutoExpressions.find(exprType) != allAutoExpressions.end() )
return allAutoExpressions.find(exprType)->second;
}
const gd::ExpressionMetadata& MetadataProvider::GetBehaviorExpressionMetadata(
const gd::Platform& platform, gd::String autoType, gd::String exprType) {
std::vector<std::shared_ptr<PlatformExtension> > extensions =
platform.GetAllPlatformExtensions();
for (std::size_t i = 0; i < extensions.size(); ++i) {
const vector<gd::String>& autos = extensions[i]->GetBehaviorsTypes();
if (find(autos.begin(), autos.end(), autoType) != autos.end()) {
const std::map<gd::String, gd::ExpressionMetadata>& allAutoExpressions =
extensions[i]->GetAllExpressionsForBehavior(autoType);
if (allAutoExpressions.find(exprType) != allAutoExpressions.end())
return allAutoExpressions.find(exprType)->second;
}
}
//Then check base
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::ExpressionMetadata> & allAutoExpressions = extensions[i]->GetAllExpressionsForBehavior("");
if ( allAutoExpressions.find(exprType) != allAutoExpressions.end() )
return allAutoExpressions.find(exprType)->second;
}
// Then check base
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::ExpressionMetadata>& allAutoExpressions =
extensions[i]->GetAllExpressionsForBehavior("");
if (allAutoExpressions.find(exprType) != allAutoExpressions.end())
return allAutoExpressions.find(exprType)->second;
}
return badExpressionMetadata;
return badExpressionMetadata;
}
const gd::ExpressionMetadata & MetadataProvider::GetExpressionMetadata(const gd::Platform & platform, gd::String exprType)
{
std::vector < std::shared_ptr<PlatformExtension> > extensions = platform.GetAllPlatformExtensions();
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::ExpressionMetadata> & allExpr = extensions[i]->GetAllExpressions();
if ( allExpr.find(exprType) != allExpr.end() )
return allExpr.find(exprType)->second;
}
const gd::ExpressionMetadata& MetadataProvider::GetExpressionMetadata(
const gd::Platform& platform, gd::String exprType) {
std::vector<std::shared_ptr<PlatformExtension> > extensions =
platform.GetAllPlatformExtensions();
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::ExpressionMetadata>& allExpr =
extensions[i]->GetAllExpressions();
if (allExpr.find(exprType) != allExpr.end())
return allExpr.find(exprType)->second;
}
return badExpressionMetadata;
return badExpressionMetadata;
}
const gd::ExpressionMetadata & MetadataProvider::GetObjectStrExpressionMetadata(const gd::Platform & platform, gd::String objectType, gd::String exprType)
{
std::vector < std::shared_ptr<PlatformExtension> > extensions = platform.GetAllPlatformExtensions();
for (std::size_t i =0;i<extensions.size();++i)
{
const vector < gd::String > & objects = extensions[i]->GetExtensionObjectsTypes();
if ( find(objects.begin(), objects.end(), objectType) != objects.end())
{
const std::map<gd::String, gd::ExpressionMetadata> & allObjectStrExpressions = extensions[i]->GetAllStrExpressionsForObject(objectType);
if ( allObjectStrExpressions.find(exprType) != allObjectStrExpressions.end() )
return allObjectStrExpressions.find(exprType)->second;
}
const gd::ExpressionMetadata& MetadataProvider::GetObjectStrExpressionMetadata(
const gd::Platform& platform, gd::String objectType, gd::String exprType) {
std::vector<std::shared_ptr<PlatformExtension> > extensions =
platform.GetAllPlatformExtensions();
for (std::size_t i = 0; i < extensions.size(); ++i) {
const vector<gd::String>& objects =
extensions[i]->GetExtensionObjectsTypes();
if (find(objects.begin(), objects.end(), objectType) != objects.end()) {
const std::map<gd::String, gd::ExpressionMetadata>&
allObjectStrExpressions =
extensions[i]->GetAllStrExpressionsForObject(objectType);
if (allObjectStrExpressions.find(exprType) !=
allObjectStrExpressions.end())
return allObjectStrExpressions.find(exprType)->second;
}
}
//Then check in functions of "Base object".
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::ExpressionMetadata> & allObjectStrExpressions = extensions[i]->GetAllStrExpressionsForObject("");
if ( allObjectStrExpressions.find(exprType) != allObjectStrExpressions.end() )
return allObjectStrExpressions.find(exprType)->second;
}
// Then check in functions of "Base object".
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::ExpressionMetadata>&
allObjectStrExpressions =
extensions[i]->GetAllStrExpressionsForObject("");
if (allObjectStrExpressions.find(exprType) != allObjectStrExpressions.end())
return allObjectStrExpressions.find(exprType)->second;
}
return badStrExpressionMetadata;
return badStrExpressionMetadata;
}
const gd::ExpressionMetadata & MetadataProvider::GetBehaviorStrExpressionMetadata(const gd::Platform & platform, gd::String autoType, gd::String exprType)
{
std::vector < std::shared_ptr<PlatformExtension> > extensions = platform.GetAllPlatformExtensions();
for (std::size_t i =0;i<extensions.size();++i)
{
const vector < gd::String > & autos = extensions[i]->GetBehaviorsTypes();
if ( find(autos.begin(), autos.end(), autoType) != autos.end())
{
const std::map<gd::String, gd::ExpressionMetadata> & allBehaviorStrExpressions = extensions[i]->GetAllStrExpressionsForBehavior(autoType);
if ( allBehaviorStrExpressions.find(exprType) != allBehaviorStrExpressions.end() )
return allBehaviorStrExpressions.find(exprType)->second;
}
const gd::ExpressionMetadata&
MetadataProvider::GetBehaviorStrExpressionMetadata(const gd::Platform& platform,
gd::String autoType,
gd::String exprType) {
std::vector<std::shared_ptr<PlatformExtension> > extensions =
platform.GetAllPlatformExtensions();
for (std::size_t i = 0; i < extensions.size(); ++i) {
const vector<gd::String>& autos = extensions[i]->GetBehaviorsTypes();
if (find(autos.begin(), autos.end(), autoType) != autos.end()) {
const std::map<gd::String, gd::ExpressionMetadata>&
allBehaviorStrExpressions =
extensions[i]->GetAllStrExpressionsForBehavior(autoType);
if (allBehaviorStrExpressions.find(exprType) !=
allBehaviorStrExpressions.end())
return allBehaviorStrExpressions.find(exprType)->second;
}
}
//Then check in functions of "Base object".
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::ExpressionMetadata> & allBehaviorStrExpressions = extensions[i]->GetAllStrExpressionsForBehavior("");
if ( allBehaviorStrExpressions.find(exprType) != allBehaviorStrExpressions.end() )
return allBehaviorStrExpressions.find(exprType)->second;
}
// Then check in functions of "Base object".
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::ExpressionMetadata>&
allBehaviorStrExpressions =
extensions[i]->GetAllStrExpressionsForBehavior("");
if (allBehaviorStrExpressions.find(exprType) !=
allBehaviorStrExpressions.end())
return allBehaviorStrExpressions.find(exprType)->second;
}
return badStrExpressionMetadata;
return badStrExpressionMetadata;
}
const gd::ExpressionMetadata & MetadataProvider::GetStrExpressionMetadata(const gd::Platform & platform, gd::String exprType)
{
std::vector < std::shared_ptr<PlatformExtension> > extensions = platform.GetAllPlatformExtensions();
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::ExpressionMetadata> & allExpr = extensions[i]->GetAllStrExpressions();
if ( allExpr.find(exprType) != allExpr.end() )
return allExpr.find(exprType)->second;
}
const gd::ExpressionMetadata& MetadataProvider::GetStrExpressionMetadata(
const gd::Platform& platform, gd::String exprType) {
std::vector<std::shared_ptr<PlatformExtension> > extensions =
platform.GetAllPlatformExtensions();
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::ExpressionMetadata>& allExpr =
extensions[i]->GetAllStrExpressions();
if (allExpr.find(exprType) != allExpr.end())
return allExpr.find(exprType)->second;
}
return badStrExpressionMetadata;
return badStrExpressionMetadata;
}
bool MetadataProvider::HasAction(const gd::Platform & platform, gd::String name)
{
std::vector < std::shared_ptr<PlatformExtension> > extensions = platform.GetAllPlatformExtensions();
bool MetadataProvider::HasAction(const gd::Platform& platform,
gd::String name) {
std::vector<std::shared_ptr<PlatformExtension> > extensions =
platform.GetAllPlatformExtensions();
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::InstructionMetadata > & actions = extensions[i]->GetAllActions();
if ( actions.find(name) != actions.end() )
return true;
}
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::InstructionMetadata>& actions =
extensions[i]->GetAllActions();
if (actions.find(name) != actions.end()) return true;
}
return false;
return false;
}
bool MetadataProvider::HasObjectAction(const gd::Platform & platform, gd::String objectType, gd::String name)
{
std::vector < std::shared_ptr<PlatformExtension> > extensions = platform.GetAllPlatformExtensions();
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::InstructionMetadata > & actions = extensions[i]->GetAllActionsForObject(objectType);
if ( actions.find(name) != actions.end() )
return true;
}
bool MetadataProvider::HasObjectAction(const gd::Platform& platform,
gd::String objectType,
gd::String name) {
std::vector<std::shared_ptr<PlatformExtension> > extensions =
platform.GetAllPlatformExtensions();
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::InstructionMetadata>& actions =
extensions[i]->GetAllActionsForObject(objectType);
if (actions.find(name) != actions.end()) return true;
}
//Then check in functions of "Base object".
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::InstructionMetadata > & actions = extensions[i]->GetAllActionsForObject("");
if ( actions.find(name) != actions.end() )
return true;
}
// Then check in functions of "Base object".
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::InstructionMetadata>& actions =
extensions[i]->GetAllActionsForObject("");
if (actions.find(name) != actions.end()) return true;
}
return false;
return false;
}
bool MetadataProvider::HasBehaviorAction(const gd::Platform & platform, gd::String behaviorType, gd::String name)
{
std::vector < std::shared_ptr<PlatformExtension> > extensions = platform.GetAllPlatformExtensions();
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::InstructionMetadata > & actions = extensions[i]->GetAllActionsForBehavior(behaviorType);
if ( actions.find(name) != actions.end() )
return true;
}
bool MetadataProvider::HasBehaviorAction(const gd::Platform& platform,
gd::String behaviorType,
gd::String name) {
std::vector<std::shared_ptr<PlatformExtension> > extensions =
platform.GetAllPlatformExtensions();
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::InstructionMetadata>& actions =
extensions[i]->GetAllActionsForBehavior(behaviorType);
if (actions.find(name) != actions.end()) return true;
}
//Then check in functions of "Base object".
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::InstructionMetadata > & actions = extensions[i]->GetAllActionsForBehavior("");
if ( actions.find(name) != actions.end() )
return true;
}
// Then check in functions of "Base object".
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::InstructionMetadata>& actions =
extensions[i]->GetAllActionsForBehavior("");
if (actions.find(name) != actions.end()) return true;
}
return false;
return false;
}
bool MetadataProvider::HasCondition(const gd::Platform& platform,
gd::String name) {
std::vector<std::shared_ptr<PlatformExtension> > extensions =
platform.GetAllPlatformExtensions();
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::InstructionMetadata>& conditions =
extensions[i]->GetAllConditions();
if (conditions.find(name) != conditions.end()) return true;
}
bool MetadataProvider::HasCondition(const gd::Platform & platform, gd::String name)
{
std::vector < std::shared_ptr<PlatformExtension> > extensions = platform.GetAllPlatformExtensions();
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::InstructionMetadata > & conditions = extensions[i]->GetAllConditions();
if ( conditions.find(name) != conditions.end() )
return true;
}
return false;
return false;
}
bool MetadataProvider::HasObjectCondition(const gd::Platform & platform, gd::String objectType, gd::String name)
{
std::vector < std::shared_ptr<PlatformExtension> > extensions = platform.GetAllPlatformExtensions();
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::InstructionMetadata > & conditions = extensions[i]->GetAllConditionsForObject(objectType);
if ( conditions.find(name) != conditions.end() )
return true;
}
bool MetadataProvider::HasObjectCondition(const gd::Platform& platform,
gd::String objectType,
gd::String name) {
std::vector<std::shared_ptr<PlatformExtension> > extensions =
platform.GetAllPlatformExtensions();
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::InstructionMetadata>& conditions =
extensions[i]->GetAllConditionsForObject(objectType);
if (conditions.find(name) != conditions.end()) return true;
}
//Then check in functions of "Base object".
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::InstructionMetadata > & conditions = extensions[i]->GetAllConditionsForObject("");
if ( conditions.find(name) != conditions.end() )
return true;
}
// Then check in functions of "Base object".
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::InstructionMetadata>& conditions =
extensions[i]->GetAllConditionsForObject("");
if (conditions.find(name) != conditions.end()) return true;
}
return false;
return false;
}
bool MetadataProvider::HasBehaviorCondition(const gd::Platform & platform, gd::String behaviorType, gd::String name)
{
std::vector < std::shared_ptr<PlatformExtension> > extensions = platform.GetAllPlatformExtensions();
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::InstructionMetadata > & conditions = extensions[i]->GetAllConditionsForBehavior(behaviorType);
if ( conditions.find(name) != conditions.end() )
return true;
}
bool MetadataProvider::HasBehaviorCondition(const gd::Platform& platform,
gd::String behaviorType,
gd::String name) {
std::vector<std::shared_ptr<PlatformExtension> > extensions =
platform.GetAllPlatformExtensions();
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::InstructionMetadata>& conditions =
extensions[i]->GetAllConditionsForBehavior(behaviorType);
if (conditions.find(name) != conditions.end()) return true;
}
//Then check in functions of "Base object".
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::InstructionMetadata > & conditions = extensions[i]->GetAllConditionsForBehavior("");
if ( conditions.find(name) != conditions.end() )
return true;
}
// Then check in functions of "Base object".
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::InstructionMetadata>& conditions =
extensions[i]->GetAllConditionsForBehavior("");
if (conditions.find(name) != conditions.end()) return true;
}
return false;
return false;
}
bool MetadataProvider::HasExpression(const gd::Platform & platform, gd::String name)
{
std::vector < std::shared_ptr<PlatformExtension> > extensions = platform.GetAllPlatformExtensions();
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::ExpressionMetadata > & expressions = extensions[i]->GetAllExpressions();
if ( expressions.find(name) != expressions.end() )
return true;
}
bool MetadataProvider::HasExpression(const gd::Platform& platform,
gd::String name) {
std::vector<std::shared_ptr<PlatformExtension> > extensions =
platform.GetAllPlatformExtensions();
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::ExpressionMetadata>& expressions =
extensions[i]->GetAllExpressions();
if (expressions.find(name) != expressions.end()) return true;
}
return false;
return false;
}
bool MetadataProvider::HasObjectExpression(const gd::Platform & platform, gd::String objectType, gd::String name)
{
std::vector < std::shared_ptr<PlatformExtension> > extensions = platform.GetAllPlatformExtensions();
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::ExpressionMetadata > & expressions = extensions[i]->GetAllExpressionsForObject(objectType);
if ( expressions.find(name) != expressions.end() )
return true;
}
bool MetadataProvider::HasObjectExpression(const gd::Platform& platform,
gd::String objectType,
gd::String name) {
std::vector<std::shared_ptr<PlatformExtension> > extensions =
platform.GetAllPlatformExtensions();
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::ExpressionMetadata>& expressions =
extensions[i]->GetAllExpressionsForObject(objectType);
if (expressions.find(name) != expressions.end()) return true;
}
//Then check in functions of "Base object".
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::ExpressionMetadata > & expressions = extensions[i]->GetAllExpressionsForObject("");
if ( expressions.find(name) != expressions.end() )
return true;
}
// Then check in functions of "Base object".
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::ExpressionMetadata>& expressions =
extensions[i]->GetAllExpressionsForObject("");
if (expressions.find(name) != expressions.end()) return true;
}
return false;
return false;
}
bool MetadataProvider::HasBehaviorExpression(const gd::Platform & platform, gd::String behaviorType, gd::String name)
{
std::vector < std::shared_ptr<PlatformExtension> > extensions = platform.GetAllPlatformExtensions();
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::ExpressionMetadata > & expressions = extensions[i]->GetAllExpressionsForBehavior(behaviorType);
if ( expressions.find(name) != expressions.end() )
return true;
}
bool MetadataProvider::HasBehaviorExpression(const gd::Platform& platform,
gd::String behaviorType,
gd::String name) {
std::vector<std::shared_ptr<PlatformExtension> > extensions =
platform.GetAllPlatformExtensions();
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::ExpressionMetadata>& expressions =
extensions[i]->GetAllExpressionsForBehavior(behaviorType);
if (expressions.find(name) != expressions.end()) return true;
}
//Then check in functions of "Base object".
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::ExpressionMetadata > & expressions = extensions[i]->GetAllExpressionsForBehavior("");
if ( expressions.find(name) != expressions.end() )
return true;
}
// Then check in functions of "Base object".
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::ExpressionMetadata>& expressions =
extensions[i]->GetAllExpressionsForBehavior("");
if (expressions.find(name) != expressions.end()) return true;
}
return false;
return false;
}
bool MetadataProvider::HasStrExpression(const gd::Platform& platform,
gd::String name) {
std::vector<std::shared_ptr<PlatformExtension> > extensions =
platform.GetAllPlatformExtensions();
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::ExpressionMetadata>& expressions =
extensions[i]->GetAllStrExpressions();
if (expressions.find(name) != expressions.end()) return true;
}
bool MetadataProvider::HasStrExpression(const gd::Platform & platform, gd::String name)
{
std::vector < std::shared_ptr<PlatformExtension> > extensions = platform.GetAllPlatformExtensions();
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::ExpressionMetadata > & expressions = extensions[i]->GetAllStrExpressions();
if ( expressions.find(name) != expressions.end() )
return true;
}
return false;
return false;
}
bool MetadataProvider::HasObjectStrExpression(const gd::Platform & platform, gd::String objectType, gd::String name)
{
std::vector < std::shared_ptr<PlatformExtension> > extensions = platform.GetAllPlatformExtensions();
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::ExpressionMetadata > & expressions = extensions[i]->GetAllStrExpressionsForObject(objectType);
if ( expressions.find(name) != expressions.end() )
return true;
}
bool MetadataProvider::HasObjectStrExpression(const gd::Platform& platform,
gd::String objectType,
gd::String name) {
std::vector<std::shared_ptr<PlatformExtension> > extensions =
platform.GetAllPlatformExtensions();
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::ExpressionMetadata>& expressions =
extensions[i]->GetAllStrExpressionsForObject(objectType);
if (expressions.find(name) != expressions.end()) return true;
}
//Then check in functions of "Base object".
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::ExpressionMetadata > & expressions = extensions[i]->GetAllStrExpressionsForObject("");
if ( expressions.find(name) != expressions.end() )
return true;
}
// Then check in functions of "Base object".
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::ExpressionMetadata>& expressions =
extensions[i]->GetAllStrExpressionsForObject("");
if (expressions.find(name) != expressions.end()) return true;
}
return false;
return false;
}
bool MetadataProvider::HasBehaviorStrExpression(const gd::Platform & platform, gd::String behaviorType, gd::String name)
{
std::vector < std::shared_ptr<PlatformExtension> > extensions = platform.GetAllPlatformExtensions();
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::ExpressionMetadata > & expressions = extensions[i]->GetAllStrExpressionsForBehavior(behaviorType);
if ( expressions.find(name) != expressions.end() )
return true;
}
bool MetadataProvider::HasBehaviorStrExpression(const gd::Platform& platform,
gd::String behaviorType,
gd::String name) {
std::vector<std::shared_ptr<PlatformExtension> > extensions =
platform.GetAllPlatformExtensions();
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::ExpressionMetadata>& expressions =
extensions[i]->GetAllStrExpressionsForBehavior(behaviorType);
if (expressions.find(name) != expressions.end()) return true;
}
//Then check in functions of "Base object".
for (std::size_t i =0;i<extensions.size();++i)
{
const std::map<gd::String, gd::ExpressionMetadata > & expressions = extensions[i]->GetAllStrExpressionsForBehavior("");
if ( expressions.find(name) != expressions.end() )
return true;
}
// Then check in functions of "Base object".
for (std::size_t i = 0; i < extensions.size(); ++i) {
const std::map<gd::String, gd::ExpressionMetadata>& expressions =
extensions[i]->GetAllStrExpressionsForBehavior("");
if (expressions.find(name) != expressions.end()) return true;
}
return false;
return false;
}
MetadataProvider::~MetadataProvider() {}
MetadataProvider::MetadataProvider() {}
}
} // namespace gd

View File

@@ -1,173 +1,208 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef METADATAPROVIDER_H
#define METADATAPROVIDER_H
#include "GDCore/String.h"
#include "GDCore/Extensions/Metadata/InstructionMetadata.h"
namespace gd { class BehaviorMetadata; }
namespace gd { class ObjectMetadata; }
namespace gd { class ExpressionMetadata; }
namespace gd { class ExpressionMetadata; }
namespace gd { class Platform; }
#include "GDCore/String.h"
namespace gd {
class BehaviorMetadata;
}
namespace gd {
class ObjectMetadata;
}
namespace gd {
class ExpressionMetadata;
}
namespace gd {
class ExpressionMetadata;
}
namespace gd {
class Platform;
}
namespace gd
{
namespace gd {
/**
* \brief Allow to easily get metadata for instructions (i.e actions and conditions),
* objects and behaviors.
* \brief Allow to easily get metadata for instructions (i.e actions and
* conditions), objects and behaviors.
*
* \ingroup PlatformDefinition
*/
class GD_CORE_API MetadataProvider
{
public:
class GD_CORE_API MetadataProvider {
public:
/**
* Get the metadata about a behavior in a project using a platform
*/
static const BehaviorMetadata& GetBehaviorMetadata(
const gd::Platform& platform, gd::String behaviorType);
/**
* Get the metadata about a behavior in a project using a platform
*/
static const BehaviorMetadata & GetBehaviorMetadata(const gd::Platform & platform, gd::String behaviorType);
/**
* Get the metadata about an object in a project using a platform
*/
static const ObjectMetadata& GetObjectMetadata(const gd::Platform& platform,
gd::String type);
/**
* Get the metadata about an object in a project using a platform
*/
static const ObjectMetadata & GetObjectMetadata(const gd::Platform & platform, gd::String type);
/**
* Get the metadata of an action.
* Must work for object, behaviors and static actions.
*/
static const gd::InstructionMetadata& GetActionMetadata(
const gd::Platform& platform, gd::String actionType);
/**
* Get the metadata of an action.
* Must work for object, behaviors and static actions.
*/
static const gd::InstructionMetadata & GetActionMetadata(const gd::Platform & platform, gd::String actionType);
/**
* Get the metadata of a condition.
* Must Work for object, behaviors and static conditions.
*/
static const gd::InstructionMetadata& GetConditionMetadata(
const gd::Platform& platform, gd::String conditionType);
/**
* Get the metadata of a condition.
* Must Work for object, behaviors and static conditions.
*/
static const gd::InstructionMetadata & GetConditionMetadata(const gd::Platform & platform, gd::String conditionType);
/**
* Get information about an expression from its type
* Works for static expressions.
*/
static const gd::ExpressionMetadata& GetExpressionMetadata(
const gd::Platform& platform, gd::String exprType);
/**
* Get information about an expression from its type
* Works for static expressions.
*/
static const gd::ExpressionMetadata & GetExpressionMetadata(const gd::Platform & platform, gd::String exprType);
/**
* Get information about an expression from its type
* Works for object expressions.
*/
static const gd::ExpressionMetadata& GetObjectExpressionMetadata(
const gd::Platform& platform, gd::String objectType, gd::String exprType);
/**
* Get information about an expression from its type
* Works for object expressions.
*/
static const gd::ExpressionMetadata & GetObjectExpressionMetadata(const gd::Platform & platform, gd::String objectType, gd::String exprType);
/**
* Get information about an expression from its type
* Works for behavior expressions.
*/
static const gd::ExpressionMetadata& GetBehaviorExpressionMetadata(
const gd::Platform& platform, gd::String autoType, gd::String exprType);
/**
* Get information about an expression from its type
* Works for behavior expressions.
*/
static const gd::ExpressionMetadata & GetBehaviorExpressionMetadata(const gd::Platform & platform, gd::String autoType, gd::String exprType);
/**
* Get information about a gd::String expression from its type
* Works for static expressions.
*/
static const gd::ExpressionMetadata& GetStrExpressionMetadata(
const gd::Platform& platform, gd::String exprType);
/**
* Get information about a gd::String expression from its type
* Works for static expressions.
*/
static const gd::ExpressionMetadata & GetStrExpressionMetadata(const gd::Platform & platform, gd::String exprType);
/**
* Get information about a gd::String expression from its type
* Works for object expressions.
*/
static const gd::ExpressionMetadata& GetObjectStrExpressionMetadata(
const gd::Platform& platform, gd::String objectType, gd::String exprType);
/**
* Get information about a gd::String expression from its type
* Works for object expressions.
*/
static const gd::ExpressionMetadata & GetObjectStrExpressionMetadata(const gd::Platform & platform, gd::String objectType, gd::String exprType);
/**
* Get information about a gd::String expression from its type
* Works for behavior expressions.
*/
static const gd::ExpressionMetadata& GetBehaviorStrExpressionMetadata(
const gd::Platform& platform, gd::String autoType, gd::String exprType);
/**
* Get information about a gd::String expression from its type
* Works for behavior expressions.
*/
static const gd::ExpressionMetadata & GetBehaviorStrExpressionMetadata(const gd::Platform & platform, gd::String autoType, gd::String exprType);
/**
* Verifying if a ( static ) condition exists
* @return true if the ( static ) condition exists
*/
static bool HasCondition(const gd::Platform& platform, gd::String name);
/**
* Verifying if a ( static ) condition exists
* @return true if the ( static ) condition exists
*/
static bool HasCondition(const gd::Platform & platform, gd::String name);
/**
* Verifying if a ( static ) action exists
* @return true if the ( static ) action exists
*/
static bool HasAction(const gd::Platform& platform, gd::String name);
/**
* Verifying if a ( static ) action exists
* @return true if the ( static ) action exists
*/
static bool HasAction(const gd::Platform & platform, gd::String name);
/**
* Verifying if a ( object ) action exists
* @return true if the ( object ) action exists
*/
static bool HasObjectAction(const gd::Platform& platform,
gd::String objectType,
gd::String name);
/**
* Verifying if a ( object ) action exists
* @return true if the ( object ) action exists
*/
static bool HasObjectAction(const gd::Platform & platform, gd::String objectType, gd::String name);
/**
* Verifying if a ( object ) condition exists
* @return true if the ( object ) condition exists
*/
static bool HasObjectCondition(const gd::Platform& platform,
gd::String objectType,
gd::String name);
/**
* Verifying if a ( object ) condition exists
* @return true if the ( object ) condition exists
*/
static bool HasObjectCondition(const gd::Platform & platform, gd::String objectType, gd::String name);
/**
* Verifying if a ( Behavior ) action exists
* @return true if the ( Behavior ) action exists
*/
static bool HasBehaviorAction(const gd::Platform& platform,
gd::String behaviorType,
gd::String name);
/**
* Verifying if a ( Behavior ) action exists
* @return true if the ( Behavior ) action exists
*/
static bool HasBehaviorAction(const gd::Platform & platform, gd::String behaviorType, gd::String name);
/**
* Verifying if a ( Behavior ) condition exists
* @return true if the ( Behavior ) condition exists
*/
static bool HasBehaviorCondition(const gd::Platform& platform,
gd::String behaviorType,
gd::String name);
/**
* Verifying if a ( Behavior ) condition exists
* @return true if the ( Behavior ) condition exists
*/
static bool HasBehaviorCondition(const gd::Platform & platform, gd::String behaviorType, gd::String name);
/**
* Verifying if a ( static ) expression exists
* @return true if the ( static ) expression exists
*/
static bool HasExpression(const gd::Platform& platform, gd::String name);
/**
* Verifying if a ( static ) expression exists
* @return true if the ( static ) expression exists
*/
static bool HasExpression(const gd::Platform & platform, gd::String name);
/**
* Verifying if a ( object ) expression exists
* @return true if the ( object ) expression exists
*/
static bool HasObjectExpression(const gd::Platform& platform,
gd::String objectType,
gd::String name);
/**
* Verifying if a ( object ) expression exists
* @return true if the ( object ) expression exists
*/
static bool HasObjectExpression(const gd::Platform & platform, gd::String objectType, gd::String name);
/**
* Verifying if a ( behavior ) expression exists
* @return true if the ( behavior ) expression exists
*/
static bool HasBehaviorExpression(const gd::Platform& platform,
gd::String behaviorType,
gd::String name);
/**
* Verifying if a ( behavior ) expression exists
* @return true if the ( behavior ) expression exists
*/
static bool HasBehaviorExpression(const gd::Platform & platform, gd::String behaviorType, gd::String name);
/**
* Verifying if a ( static ) gd::String expression exists
* @return true if the ( static ) gd::String expression exists
*/
static bool HasStrExpression(const gd::Platform& platform, gd::String name);
/**
* Verifying if a ( static ) gd::String expression exists
* @return true if the ( static ) gd::String expression exists
*/
static bool HasStrExpression(const gd::Platform & platform, gd::String name);
/**
* Verifying if a ( object ) gd::String expression exists
* @return true if the ( object ) gd::String expression exists
*/
static bool HasObjectStrExpression(const gd::Platform& platform,
gd::String objectType,
gd::String name);
/**
* Verifying if a ( object ) gd::String expression exists
* @return true if the ( object ) gd::String expression exists
*/
static bool HasObjectStrExpression(const gd::Platform & platform, gd::String objectType, gd::String name);
/**
* Verifying if a ( object ) gd::String expression exists
* @return true if the ( object ) gd::String expression exists
*/
static bool HasBehaviorStrExpression(const gd::Platform& platform,
gd::String behaviorType,
gd::String name);
/**
* Verifying if a ( object ) gd::String expression exists
* @return true if the ( object ) gd::String expression exists
*/
static bool HasBehaviorStrExpression(const gd::Platform & platform, gd::String behaviorType, gd::String name);
virtual ~MetadataProvider();
virtual ~MetadataProvider();
private:
MetadataProvider();
private:
MetadataProvider();
static BehaviorMetadata badBehaviorInfo;
static ObjectMetadata badObjectInfo;
static gd::InstructionMetadata badInstructionMetadata;
static gd::ExpressionMetadata badExpressionMetadata;
static gd::ExpressionMetadata badStrExpressionMetadata;
int useless; //Useless member to avoid emscripten "must have a positive integer typeid pointer" runtime error.
static BehaviorMetadata badBehaviorInfo;
static ObjectMetadata badObjectInfo;
static gd::InstructionMetadata badInstructionMetadata;
static gd::ExpressionMetadata badExpressionMetadata;
static gd::ExpressionMetadata badStrExpressionMetadata;
int useless; // Useless member to avoid emscripten "must have a positive
// integer typeid pointer" runtime error.
};
}
} // namespace gd
#endif // METADATAPROVIDER_H
#endif // METADATAPROVIDER_H

View File

@@ -1,158 +1,169 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include <iostream>
#include "ObjectMetadata.h"
#include "GDCore/Extensions/Metadata/InstructionMetadata.h"
#include "GDCore/Extensions/Metadata/ExpressionMetadata.h"
#include <algorithm>
#include <iostream>
#include "GDCore/Extensions/Metadata/ExpressionMetadata.h"
#include "GDCore/Extensions/Metadata/InstructionMetadata.h"
#if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
#include "GDCore/IDE/wxTools/SkinHelper.h"
#include <wx/file.h>
#include <wx/bitmap.h>
#include <wx/file.h>
#include "GDCore/IDE/wxTools/SkinHelper.h"
#endif
namespace gd
{
namespace gd {
ObjectMetadata::ObjectMetadata(const gd::String & extensionNamespace_,
const gd::String & name_,
const gd::String & fullname_,
const gd::String & informations_,
const gd::String & icon24x24,
CreateFunPtr createFunPtrP) :
extensionNamespace(extensionNamespace_)
{
name = name_;
ObjectMetadata::ObjectMetadata(const gd::String& extensionNamespace_,
const gd::String& name_,
const gd::String& fullname_,
const gd::String& informations_,
const gd::String& icon24x24,
CreateFunPtr createFunPtrP)
: extensionNamespace(extensionNamespace_) {
name = name_;
#if defined(GD_IDE_ONLY)
SetFullName(gd::String(fullname_));
SetDescription(gd::String(informations_));
iconFilename = icon24x24;
SetFullName(gd::String(fullname_));
SetDescription(gd::String(informations_));
iconFilename = icon24x24;
#if !defined(GD_NO_WX_GUI)
if (!iconFilename.empty())
{
if ( gd::SkinHelper::IconExists(icon24x24, 24) )
SetBitmapIcon(gd::SkinHelper::GetIcon(icon24x24, 24));
else if ( wxFile::Exists(icon24x24) )
SetBitmapIcon(wxBitmap(icon24x24, wxBITMAP_TYPE_ANY));
else {
std::cout << "Warning: The icon file for object \"" << name_
if (!iconFilename.empty()) {
if (gd::SkinHelper::IconExists(icon24x24, 24))
SetBitmapIcon(gd::SkinHelper::GetIcon(icon24x24, 24));
else if (wxFile::Exists(icon24x24))
SetBitmapIcon(wxBitmap(icon24x24, wxBITMAP_TYPE_ANY));
else {
std::cout << "Warning: The icon file for object \"" << name_
<< " was not found in the current skin icons"
<< " and the specified name is not an existing filename.";
SetBitmapIcon(wxBitmap(24,24));
}
SetBitmapIcon(wxBitmap(24, 24));
}
}
#endif
#endif
createFunPtr = createFunPtrP;
createFunPtr = createFunPtrP;
}
gd::InstructionMetadata & ObjectMetadata::AddCondition(const gd::String & name,
const gd::String & fullname,
const gd::String & description,
const gd::String & sentence,
const gd::String & group,
const gd::String & icon,
const gd::String & smallicon)
{
gd::InstructionMetadata& ObjectMetadata::AddCondition(
const gd::String& name,
const gd::String& fullname,
const gd::String& description,
const gd::String& sentence,
const gd::String& group,
const gd::String& icon,
const gd::String& smallicon) {
#if defined(GD_IDE_ONLY)
gd::String nameWithNamespace = extensionNamespace.empty() ? name : extensionNamespace+name;
conditionsInfos[nameWithNamespace] = InstructionMetadata(extensionNamespace, nameWithNamespace, fullname, description, sentence, group, icon, smallicon);
return conditionsInfos[nameWithNamespace];
gd::String nameWithNamespace =
extensionNamespace.empty() ? name : extensionNamespace + name;
conditionsInfos[nameWithNamespace] = InstructionMetadata(extensionNamespace,
nameWithNamespace,
fullname,
description,
sentence,
group,
icon,
smallicon);
return conditionsInfos[nameWithNamespace];
#endif
}
gd::InstructionMetadata & ObjectMetadata::AddAction(const gd::String & name,
const gd::String & fullname,
const gd::String & description,
const gd::String & sentence,
const gd::String & group,
const gd::String & icon,
const gd::String & smallicon)
{
gd::InstructionMetadata& ObjectMetadata::AddAction(
const gd::String& name,
const gd::String& fullname,
const gd::String& description,
const gd::String& sentence,
const gd::String& group,
const gd::String& icon,
const gd::String& smallicon) {
#if defined(GD_IDE_ONLY)
gd::String nameWithNamespace = extensionNamespace.empty() ? name : extensionNamespace+name;
actionsInfos[nameWithNamespace] = InstructionMetadata(extensionNamespace, nameWithNamespace, fullname, description, sentence, group, icon, smallicon);
return actionsInfos[nameWithNamespace];
gd::String nameWithNamespace =
extensionNamespace.empty() ? name : extensionNamespace + name;
actionsInfos[nameWithNamespace] = InstructionMetadata(extensionNamespace,
nameWithNamespace,
fullname,
description,
sentence,
group,
icon,
smallicon);
return actionsInfos[nameWithNamespace];
#endif
}
gd::ExpressionMetadata & ObjectMetadata::AddExpression(const gd::String & name,
const gd::String & fullname,
const gd::String & description,
const gd::String & group,
const gd::String & smallicon)
{
gd::ExpressionMetadata& ObjectMetadata::AddExpression(
const gd::String& name,
const gd::String& fullname,
const gd::String& description,
const gd::String& group,
const gd::String& smallicon) {
#if defined(GD_IDE_ONLY)
//Be careful, objects expression do not have namespace ( not necessary as objects inherits from only one derived object )
expressionsInfos[name] = ExpressionMetadata(extensionNamespace, name, fullname, description, group, smallicon);
return expressionsInfos[name];
// Be careful, objects expression do not have namespace ( not necessary as
// objects inherits from only one derived object )
expressionsInfos[name] = ExpressionMetadata(
extensionNamespace, name, fullname, description, group, smallicon);
return expressionsInfos[name];
#endif
}
gd::ExpressionMetadata & ObjectMetadata::AddStrExpression(const gd::String & name,
const gd::String & fullname,
const gd::String & description,
const gd::String & group,
const gd::String & smallicon)
{
gd::ExpressionMetadata& ObjectMetadata::AddStrExpression(
const gd::String& name,
const gd::String& fullname,
const gd::String& description,
const gd::String& group,
const gd::String& smallicon) {
#if defined(GD_IDE_ONLY)
//Be careful, objects expression do not have namespace ( not necessary as objects inherits from only one derived object )
strExpressionsInfos[name] = ExpressionMetadata(extensionNamespace, name, fullname, description, group, smallicon);
return strExpressionsInfos[name];
// Be careful, objects expression do not have namespace ( not necessary as
// objects inherits from only one derived object )
strExpressionsInfos[name] = ExpressionMetadata(
extensionNamespace, name, fullname, description, group, smallicon);
return strExpressionsInfos[name];
#endif
}
ObjectMetadata & ObjectMetadata::SetFullName(const gd::String & fullname_)
{
ObjectMetadata& ObjectMetadata::SetFullName(const gd::String& fullname_) {
#if defined(GD_IDE_ONLY)
fullname = fullname_;
fullname = fullname_;
#endif
return *this;
return *this;
}
ObjectMetadata & ObjectMetadata::SetHelpUrl(const gd::String & helpUrl_)
{
ObjectMetadata& ObjectMetadata::SetHelpUrl(const gd::String& helpUrl_) {
#if defined(GD_IDE_ONLY)
helpUrl = helpUrl_;
helpUrl = helpUrl_;
#endif
return *this;
return *this;
}
ObjectMetadata & ObjectMetadata::SetDescription(const gd::String & description_)
{
ObjectMetadata& ObjectMetadata::SetDescription(const gd::String& description_) {
#if defined(GD_IDE_ONLY)
description = description_;
description = description_;
#endif
return *this;
return *this;
}
ObjectMetadata & ObjectMetadata::SetBitmapIcon(const wxBitmap & bitmap_)
{
ObjectMetadata& ObjectMetadata::SetBitmapIcon(const wxBitmap& bitmap_) {
#if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
icon = bitmap_;
icon = bitmap_;
#endif
return *this;
return *this;
}
ObjectMetadata & ObjectMetadata::SetIncludeFile(const gd::String & includeFile)
{
ObjectMetadata& ObjectMetadata::SetIncludeFile(const gd::String& includeFile) {
#if defined(GD_IDE_ONLY)
includeFiles.clear();
includeFiles.clear();
includeFiles.push_back(includeFile);
#endif
return *this;
}
ObjectMetadata& ObjectMetadata::AddIncludeFile(const gd::String& includeFile) {
#if defined(GD_IDE_ONLY)
if (std::find(includeFiles.begin(), includeFiles.end(), includeFile) ==
includeFiles.end())
includeFiles.push_back(includeFile);
#endif
return *this;
}
ObjectMetadata & ObjectMetadata::AddIncludeFile(const gd::String & includeFile)
{
#if defined(GD_IDE_ONLY)
if ( std::find(includeFiles.begin(), includeFiles.end(), includeFile) == includeFiles.end())
includeFiles.push_back(includeFile);
#endif
return *this;
return *this;
}
}
} // namespace gd

View File

@@ -1,28 +1,32 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef OBJECTMETADATA_H
#define OBJECTMETADATA_H
#include "GDCore/String.h"
#include <map>
#include <memory>
#include "GDCore/Extensions/Metadata/InstructionMetadata.h"
#include "GDCore/Extensions/Metadata/ExpressionMetadata.h"
#include "GDCore/Extensions/Metadata/InstructionMetadata.h"
#include "GDCore/String.h"
#if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
#include <wx/bitmap.h>
#endif
namespace gd { class Object; }
namespace gd { class InstructionMetadata; }
namespace gd { class ExpressionMetadata; }
namespace gd {
class Object;
}
namespace gd {
class InstructionMetadata;
}
namespace gd {
class ExpressionMetadata;
}
class wxBitmap;
typedef std::unique_ptr<gd::Object> (*CreateFunPtr)(gd::String name);
namespace gd
{
namespace gd {
/**
* \brief Contains user-friendly information about an object type, and a
@@ -30,132 +34,130 @@ namespace gd
*
* \ingroup Events
*/
class GD_CORE_API ObjectMetadata
{
public:
ObjectMetadata(const gd::String & extensionNamespace_,
const gd::String & name_,
const gd::String & fullname_,
const gd::String & informations_,
const gd::String & icon24x24_,
CreateFunPtr createFunPtrP);
ObjectMetadata() : createFunPtr(NULL) {}
virtual ~ObjectMetadata() {};
class GD_CORE_API ObjectMetadata {
public:
ObjectMetadata(const gd::String& extensionNamespace_,
const gd::String& name_,
const gd::String& fullname_,
const gd::String& informations_,
const gd::String& icon24x24_,
CreateFunPtr createFunPtrP);
ObjectMetadata() : createFunPtr(NULL) {}
virtual ~ObjectMetadata(){};
/**
* \brief Declare a new condition as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
*/
gd::InstructionMetadata & AddCondition(const gd::String & name_,
const gd::String & fullname_,
const gd::String & description_,
const gd::String & sentence_,
const gd::String & group_,
const gd::String & icon_,
const gd::String & smallicon_);
/**
* \brief Declare a new condition as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
*/
gd::InstructionMetadata& AddCondition(const gd::String& name_,
const gd::String& fullname_,
const gd::String& description_,
const gd::String& sentence_,
const gd::String& group_,
const gd::String& icon_,
const gd::String& smallicon_);
/**
* \brief Declare a new action as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
*/
gd::InstructionMetadata & AddAction(const gd::String & name_,
const gd::String & fullname_,
const gd::String & description_,
const gd::String & sentence_,
const gd::String & group_,
const gd::String & icon_,
const gd::String & smallicon_);
/**
* \brief Declare a new expression as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
*/
gd::ExpressionMetadata & AddExpression(const gd::String & name_,
const gd::String & fullname_,
const gd::String & description_,
const gd::String & group_,
const gd::String & smallicon_);
/**
* \brief Declare a new string expression as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
*/
gd::ExpressionMetadata & AddStrExpression(const gd::String & name_,
const gd::String & fullname_,
const gd::String & description_,
const gd::String & group_,
const gd::String & smallicon_);
/**
* \brief Declare a new action as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
*/
gd::InstructionMetadata& AddAction(const gd::String& name_,
const gd::String& fullname_,
const gd::String& description_,
const gd::String& sentence_,
const gd::String& group_,
const gd::String& icon_,
const gd::String& smallicon_);
/**
* \brief Declare a new expression as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
*/
gd::ExpressionMetadata& AddExpression(const gd::String& name_,
const gd::String& fullname_,
const gd::String& description_,
const gd::String& group_,
const gd::String& smallicon_);
/**
* \brief Declare a new string expression as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
*/
gd::ExpressionMetadata& AddStrExpression(const gd::String& name_,
const gd::String& fullname_,
const gd::String& description_,
const gd::String& group_,
const gd::String& smallicon_);
/**
* \brief Set the name shown to the user.
* \note This method does nothing when used for GD C++ runtime.
*/
ObjectMetadata & SetFullName(const gd::String & fullname_);
/**
* \brief Set the name shown to the user.
* \note This method does nothing when used for GD C++ runtime.
*/
ObjectMetadata& SetFullName(const gd::String& fullname_);
/**
* \brief Set the description shown to the user.
* \note This method does nothing when used for GD C++ runtime.
*/
ObjectMetadata & SetDescription(const gd::String & description_);
/**
* \brief Set the description shown to the user.
* \note This method does nothing when used for GD C++ runtime.
*/
ObjectMetadata& SetDescription(const gd::String& description_);
/**
* Set the bitmap icon shown to the user.
* \note This method does nothing when used for GD C++ runtime.
*/
ObjectMetadata & SetBitmapIcon(const wxBitmap & bitmap_);
/**
* Set the bitmap icon shown to the user.
* \note This method does nothing when used for GD C++ runtime.
*/
ObjectMetadata& SetBitmapIcon(const wxBitmap& bitmap_);
const gd::String & GetName() const { return name; }
const gd::String& GetName() const { return name; }
#if defined(GD_IDE_ONLY)
const gd::String & GetFullName() const { return fullname; }
const gd::String & GetHelpUrl() const { return helpUrl; }
const gd::String & GetDescription() const { return description; }
const gd::String & GetIconFilename() const { return iconFilename; }
const gd::String& GetFullName() const { return fullname; }
const gd::String& GetHelpUrl() const { return helpUrl; }
const gd::String& GetDescription() const { return description; }
const gd::String& GetIconFilename() const { return iconFilename; }
#if !defined(GD_NO_WX_GUI)
const wxBitmap & GetBitmapIcon() const { return icon; }
const wxBitmap& GetBitmapIcon() const { return icon; }
#endif
#endif
/**
* \brief Set the URL pointing to the help page about this object
* \note The path to the page must be relative to the wiki url.
*/
ObjectMetadata & SetHelpUrl(const gd::String & url);
/**
* \brief Set the URL pointing to the help page about this object
* \note The path to the page must be relative to the wiki url.
*/
ObjectMetadata& SetHelpUrl(const gd::String& url);
/**
* \brief Erase any existing include file and add the specified include.
* \note The requirement may vary depending on the platform: Most of the time, the include
* file contains the declaration of the object.
*/
ObjectMetadata & SetIncludeFile(const gd::String & includeFile);
/**
* \brief Erase any existing include file and add the specified include.
* \note The requirement may vary depending on the platform: Most of the time,
* the include file contains the declaration of the object.
*/
ObjectMetadata& SetIncludeFile(const gd::String& includeFile);
/**
* \brief Add a file to the already existing include files.
*/
ObjectMetadata & AddIncludeFile(const gd::String & includeFile);
/**
* \brief Add a file to the already existing include files.
*/
ObjectMetadata& AddIncludeFile(const gd::String& includeFile);
#if defined(GD_IDE_ONLY)
std::map<gd::String, gd::InstructionMetadata > conditionsInfos;
std::map<gd::String, gd::InstructionMetadata > actionsInfos;
std::map<gd::String, gd::ExpressionMetadata > expressionsInfos;
std::map<gd::String, gd::ExpressionMetadata > strExpressionsInfos;
std::map<gd::String, gd::InstructionMetadata> conditionsInfos;
std::map<gd::String, gd::InstructionMetadata> actionsInfos;
std::map<gd::String, gd::ExpressionMetadata> expressionsInfos;
std::map<gd::String, gd::ExpressionMetadata> strExpressionsInfos;
std::vector<gd::String> includeFiles;
gd::String className;
std::vector<gd::String> includeFiles;
gd::String className;
#endif
CreateFunPtr createFunPtr;
CreateFunPtr createFunPtr;
private:
gd::String extensionNamespace;
gd::String name;
private:
gd::String extensionNamespace;
gd::String name;
#if defined(GD_IDE_ONLY)
gd::String helpUrl;
gd::String fullname;
gd::String description;
gd::String iconFilename;
gd::String helpUrl;
gd::String fullname;
gd::String description;
gd::String iconFilename;
#if !defined(GD_NO_WX_GUI)
wxBitmap icon;
wxBitmap icon;
#endif
#endif
};
}
#endif // OBJECTMETADATA_H
} // namespace gd
#endif // OBJECTMETADATA_H

View File

@@ -1,12 +1,12 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "Platform.h"
#include "GDCore/Extensions/PlatformExtension.h"
#include "GDCore/Project/ChangesNotifier.h"
#include "GDCore/IDE/ProjectExporter.h"
#include "GDCore/Project/ChangesNotifier.h"
#include "GDCore/Project/Object.h"
#include "GDCore/String.h"
@@ -14,136 +14,126 @@ using namespace std;
#undef CreateEvent
namespace gd
{
namespace gd {
#if defined(GD_IDE_ONLY)
gd::ChangesNotifier Platform::defaultEmptyChangesNotifier;
#endif
Platform::Platform()
{
//ctor
Platform::Platform() {
// ctor
}
Platform::~Platform()
{
//dtor
Platform::~Platform() {
// dtor
}
bool Platform::AddExtension(std::shared_ptr<gd::PlatformExtension> extension)
{
std::cout << extension->GetName();
for (std::size_t i =0;i<extensionsLoaded.size();++i)
{
if ( extensionsLoaded[i]->GetName() == extension->GetName() ) {
std::cout << "(Already loaded!)" << std::endl;
return false;
}
bool Platform::AddExtension(std::shared_ptr<gd::PlatformExtension> extension) {
std::cout << extension->GetName();
for (std::size_t i = 0; i < extensionsLoaded.size(); ++i) {
if (extensionsLoaded[i]->GetName() == extension->GetName()) {
std::cout << "(Already loaded!)" << std::endl;
return false;
}
}
//Load all creation/destruction functions for objects provided by the extension
vector < gd::String > objectsTypes = extension->GetExtensionObjectsTypes();
for ( std::size_t i = 0; i < objectsTypes.size();++i)
{
creationFunctionTable[objectsTypes[i]] = extension->GetObjectCreationFunctionPtr(objectsTypes[i]);
}
// Load all creation/destruction functions for objects provided by the
// extension
vector<gd::String> objectsTypes = extension->GetExtensionObjectsTypes();
for (std::size_t i = 0; i < objectsTypes.size(); ++i) {
creationFunctionTable[objectsTypes[i]] =
extension->GetObjectCreationFunctionPtr(objectsTypes[i]);
}
extensionsLoaded.push_back(extension);
std::cout << ", ";
return true;
extensionsLoaded.push_back(extension);
std::cout << ", ";
return true;
}
bool Platform::IsExtensionLoaded(const gd::String & name) const
{
for (std::size_t i =0;i<extensionsLoaded.size();++i)
{
if ( extensionsLoaded[i]->GetName() == name )
return true;
}
bool Platform::IsExtensionLoaded(const gd::String& name) const {
for (std::size_t i = 0; i < extensionsLoaded.size(); ++i) {
if (extensionsLoaded[i]->GetName() == name) return true;
}
return false;
return false;
}
std::shared_ptr<gd::PlatformExtension> Platform::GetExtension(const gd::String & name) const
{
for (std::size_t i =0;i<extensionsLoaded.size();++i)
{
if ( extensionsLoaded[i]->GetName() == name )
return extensionsLoaded[i];
}
std::shared_ptr<gd::PlatformExtension> Platform::GetExtension(
const gd::String& name) const {
for (std::size_t i = 0; i < extensionsLoaded.size(); ++i) {
if (extensionsLoaded[i]->GetName() == name) return extensionsLoaded[i];
}
return std::shared_ptr<gd::PlatformExtension> ();
return std::shared_ptr<gd::PlatformExtension>();
}
std::unique_ptr<gd::Object> Platform::CreateObject(gd::String type, const gd::String & name) const
{
if ( creationFunctionTable.find(type) == creationFunctionTable.end() )
{
std::cout << "Tried to create an object with an unknown type: " << type << " for platform " << GetName() << "!" << std::endl;
type = "";
if ( creationFunctionTable.find("") == creationFunctionTable.end() ) {
std::cout << "Unable to create a Base object!" << std::endl;
return nullptr;
}
std::unique_ptr<gd::Object> Platform::CreateObject(
gd::String type, const gd::String& name) const {
if (creationFunctionTable.find(type) == creationFunctionTable.end()) {
std::cout << "Tried to create an object with an unknown type: " << type
<< " for platform " << GetName() << "!" << std::endl;
type = "";
if (creationFunctionTable.find("") == creationFunctionTable.end()) {
std::cout << "Unable to create a Base object!" << std::endl;
return nullptr;
}
}
//Create a new object with the type we want.
std::unique_ptr<gd::Object> object = (creationFunctionTable.find(type)->second)(name);
object->SetType(type);
// Create a new object with the type we want.
std::unique_ptr<gd::Object> object =
(creationFunctionTable.find(type)->second)(name);
object->SetType(type);
return std::unique_ptr<gd::Object>(std::move(object));
return std::unique_ptr<gd::Object>(std::move(object));
}
std::unique_ptr<gd::Behavior> Platform::CreateBehavior(const gd::String & behaviorType) const
{
for (std::size_t i =0;i<extensionsLoaded.size();++i)
{
std::unique_ptr<gd::Behavior> behavior = extensionsLoaded[i]->CreateBehavior(behaviorType);
if ( behavior )
return behavior;
}
std::unique_ptr<gd::Behavior> Platform::CreateBehavior(
const gd::String& behaviorType) const {
for (std::size_t i = 0; i < extensionsLoaded.size(); ++i) {
std::unique_ptr<gd::Behavior> behavior =
extensionsLoaded[i]->CreateBehavior(behaviorType);
if (behavior) return behavior;
}
return nullptr;
return nullptr;
}
std::shared_ptr<gd::BehaviorsSharedData> Platform::CreateBehaviorSharedDatas(const gd::String & behaviorType) const
{
for (std::size_t i =0;i<extensionsLoaded.size();++i)
{
std::shared_ptr<gd::BehaviorsSharedData> behavior = extensionsLoaded[i]->CreateBehaviorSharedDatas(behaviorType);
if ( behavior != std::shared_ptr<gd::BehaviorsSharedData>() )
return behavior;
}
std::shared_ptr<gd::BehaviorsSharedData> Platform::CreateBehaviorSharedDatas(
const gd::String& behaviorType) const {
for (std::size_t i = 0; i < extensionsLoaded.size(); ++i) {
std::shared_ptr<gd::BehaviorsSharedData> behavior =
extensionsLoaded[i]->CreateBehaviorSharedDatas(behaviorType);
if (behavior != std::shared_ptr<gd::BehaviorsSharedData>()) return behavior;
}
return std::shared_ptr<gd::BehaviorsSharedData>();
return std::shared_ptr<gd::BehaviorsSharedData>();
}
#if defined(GD_IDE_ONLY)
std::shared_ptr<gd::BaseEvent> Platform::CreateEvent(const gd::String & eventType) const
{
for (std::size_t i =0;i<extensionsLoaded.size();++i)
{
std::shared_ptr<gd::BaseEvent> event = extensionsLoaded[i]->CreateEvent(eventType);
if ( event != std::shared_ptr<gd::BaseEvent>() )
return event;
}
std::shared_ptr<gd::BaseEvent> Platform::CreateEvent(
const gd::String& eventType) const {
for (std::size_t i = 0; i < extensionsLoaded.size(); ++i) {
std::shared_ptr<gd::BaseEvent> event =
extensionsLoaded[i]->CreateEvent(eventType);
if (event != std::shared_ptr<gd::BaseEvent>()) return event;
}
return std::shared_ptr<gd::BaseEvent>();
return std::shared_ptr<gd::BaseEvent>();
}
#if !defined(GD_NO_WX_GUI)
std::shared_ptr<gd::LayoutEditorPreviewer> Platform::GetLayoutPreviewer(gd::LayoutEditorCanvas & editor) const
{
return std::make_shared<gd::LayoutEditorPreviewer>();
std::shared_ptr<gd::LayoutEditorPreviewer> Platform::GetLayoutPreviewer(
gd::LayoutEditorCanvas& editor) const {
return std::make_shared<gd::LayoutEditorPreviewer>();
}
std::vector<std::shared_ptr<gd::ProjectExporter>> Platform::GetProjectExporters() const
{
return std::vector<std::shared_ptr<gd::ProjectExporter>>{std::make_shared<gd::ProjectExporter>()};
std::vector<std::shared_ptr<gd::ProjectExporter>>
Platform::GetProjectExporters() const {
return std::vector<std::shared_ptr<gd::ProjectExporter>>{
std::make_shared<gd::ProjectExporter>()};
}
#endif
#endif
}
} // namespace gd

View File

@@ -1,7 +1,7 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_PLATFORM_H
@@ -9,197 +9,232 @@
#include <map>
#include <memory>
#include <vector>
#include "GDCore/String.h"
#include "GDCore/Project/ChangesNotifier.h"
#include "GDCore/Project/LayoutEditorPreviewer.h"
#include "GDCore/String.h"
namespace gd { class InstructionsMetadataHolder; }
namespace gd { class Project; }
namespace gd { class Object; }
namespace gd { class Behavior; }
namespace gd { class BehaviorMetadata; }
namespace gd { class ObjectMetadata; }
namespace gd { class BaseEvent; }
namespace gd { class BehaviorsSharedData; }
namespace gd { class PlatformExtension; }
namespace gd { class LayoutEditorCanvas; }
namespace gd { class ProjectExporter; }
namespace gd {
class InstructionsMetadataHolder;
}
namespace gd {
class Project;
}
namespace gd {
class Object;
}
namespace gd {
class Behavior;
}
namespace gd {
class BehaviorMetadata;
}
namespace gd {
class ObjectMetadata;
}
namespace gd {
class BaseEvent;
}
namespace gd {
class BehaviorsSharedData;
}
namespace gd {
class PlatformExtension;
}
namespace gd {
class LayoutEditorCanvas;
}
namespace gd {
class ProjectExporter;
}
typedef std::unique_ptr<gd::Object> (*CreateFunPtr)(gd::String name);
#undef CreateEvent
namespace gd
{
namespace gd {
/**
* \brief Base class for implementing a platform
*
* \ingroup PlatformDefinition
*/
class GD_CORE_API Platform
{
public:
Platform();
virtual ~Platform();
class GD_CORE_API Platform {
public:
Platform();
virtual ~Platform();
/**
* \brief Must return the platform name
*/
virtual gd::String GetName() const { return "Unnamed platform"; }
/**
* \brief Must return the platform name
*/
virtual gd::String GetName() const { return "Unnamed platform"; }
/**
* \brief Must return the platform full name, displayed to users.
*/
virtual gd::String GetFullName() const { return "Unnamed platform"; }
/**
* \brief Must return the platform full name, displayed to users.
*/
virtual gd::String GetFullName() const { return "Unnamed platform"; }
#if defined(GD_IDE_ONLY)
/**
* \brief Must return a text describing the platform in a few words.
*/
virtual gd::String GetSubtitle() const { return ""; }
#if defined(GD_IDE_ONLY)
/**
* \brief Must return a text describing the platform in a few words.
*/
virtual gd::String GetSubtitle() const { return ""; }
/**
* \brief Must return a text describing the platform, displayed to users.
*/
virtual gd::String GetDescription() const { return ""; }
/**
* \brief Must return a text describing the platform, displayed to users.
*/
virtual gd::String GetDescription() const { return ""; }
/**
* \brief Must return a filename to a 32*32 image file for the platform.
*/
virtual gd::String GetIcon() const { return ""; }
#endif
/**
* \brief Must return a filename to a 32*32 image file for the platform.
*/
virtual gd::String GetIcon() const { return ""; }
#endif
/** \name Extensions management
* Member functions used to manage the extensions
*/
///@{
/** \name Extensions management
* Member functions used to manage the extensions
*/
///@{
/**
* \brief Must return the name of the function that is used to create an
* extension for this platform.
*
* For example, GD C++ Platform uses "CreateGDExtension" and GD JS Platform
* "CreateGDJSExtension". \see gd::ExtensionsLoader
*/
virtual gd::String GetExtensionCreateFunctionName() { return ""; }
/**
* \brief Must return the name of the function that is used to create an extension for this platform.
*
* For example, GD C++ Platform uses "CreateGDExtension" and GD JS Platform "CreateGDJSExtension".
* \see gd::ExtensionsLoader
*/
virtual gd::String GetExtensionCreateFunctionName() { return ""; }
/**
* \brief Add an extension to the manager.
* \note This method is virtual and can be redefined by platforms if they want
* to do special work when an extension is loaded. \see gd::ExtensionsLoader
*/
virtual bool AddExtension(std::shared_ptr<PlatformExtension> extension);
/**
* \brief Add an extension to the manager.
* \note This method is virtual and can be redefined by platforms if they want to do special work when an extension is loaded.
* \see gd::ExtensionsLoader
*/
virtual bool AddExtension(std::shared_ptr<PlatformExtension> extension);
/**
* \brief Return true if an extension with the specified name is loaded
*/
bool IsExtensionLoaded(const gd::String& name) const;
/**
* \brief Return true if an extension with the specified name is loaded
*/
bool IsExtensionLoaded(const gd::String & name) const;
/**
* \brief Get an extension of the platform
* @return Shared pointer to the extension
*/
std::shared_ptr<PlatformExtension> GetExtension(const gd::String& name) const;
/**
* \brief Get an extension of the platform
* @return Shared pointer to the extension
*/
std::shared_ptr<PlatformExtension> GetExtension(const gd::String & name) const;
/**
* \brief Get all extensions loaded for the platform.
* @return Vector of Shared pointer containing all extensions
*/
const std::vector<std::shared_ptr<gd::PlatformExtension>>&
GetAllPlatformExtensions() const {
return extensionsLoaded;
};
/**
* \brief Get all extensions loaded for the platform.
* @return Vector of Shared pointer containing all extensions
*/
const std::vector < std::shared_ptr<gd::PlatformExtension> > & GetAllPlatformExtensions() const { return extensionsLoaded; };
///@}
///@}
/** \name Factory method
* Member functions used to create the platforms objects
*/
///@{
/** \name Factory method
* Member functions used to create the platforms objects
*/
///@{
/**
* \brief Create an object of given type with the specified name.
*/
std::unique_ptr<gd::Object> CreateObject(gd::String type,
const gd::String& name) const;
/**
* \brief Create an object of given type with the specified name.
*/
std::unique_ptr<gd::Object> CreateObject(gd::String type, const gd::String & name) const;
/**
* \brief Create a behavior
*/
std::unique_ptr<gd::Behavior> CreateBehavior(const gd::String& type) const;
/**
* \brief Create a behavior
*/
std::unique_ptr<gd::Behavior> CreateBehavior(const gd::String & type) const;
/**
* \brief Create a behavior shared data object.
*/
std::shared_ptr<gd::BehaviorsSharedData> CreateBehaviorSharedDatas(
const gd::String& type) const;
/**
* \brief Create a behavior shared data object.
*/
std::shared_ptr<gd::BehaviorsSharedData> CreateBehaviorSharedDatas(const gd::String & type) const;
#if defined(GD_IDE_ONLY)
/**
* \brief Create an event of given type
*/
std::shared_ptr<gd::BaseEvent> CreateEvent(const gd::String& type) const;
#if defined(GD_IDE_ONLY)
/**
* \brief Create an event of given type
*/
std::shared_ptr<gd::BaseEvent> CreateEvent(const gd::String & type) const;
///@}
///@}
/** \name Notification of changes
* The platform can do extra work when a change occurs by providing a special
* gd::ChangesNotifier
*/
///@{
/** \name Notification of changes
* The platform can do extra work when a change occurs by providing a special gd::ChangesNotifier
*/
///@{
/**
* \brief Must provide a ChangesNotifier object that will be called by the IDE if needed.
* The IDE is not supposed to store the returned object.
*
* The default implementation simply return a ChangesNotifier object doing nothing.
*/
virtual ChangesNotifier & GetChangesNotifier() const { return defaultEmptyChangesNotifier; };
/**
* \brief Must provide a ChangesNotifier object that will be called by the IDE
* if needed. The IDE is not supposed to store the returned object.
*
* The default implementation simply return a ChangesNotifier object doing
* nothing.
*/
virtual ChangesNotifier& GetChangesNotifier() const {
return defaultEmptyChangesNotifier;
};
///@}
/** \name Preview and compilation
* The platform should provides specialized classes used for previewing layouts or
* exporting the project.
* The platform should provides specialized classes used for previewing
* layouts or exporting the project.
*/
///@{
#if !defined(GD_NO_WX_GUI)
/**
* \brief Must provide a gd::LayoutEditorPreviewer object that will be stored and used
* by LayoutEditorCanvas to display/run a preview of the layout of a project.
*
* The default implementation simply return a gd::LayoutEditorPreviewer object doing nothing.
*/
virtual std::shared_ptr<gd::LayoutEditorPreviewer> GetLayoutPreviewer(gd::LayoutEditorCanvas & editor) const;
#if !defined(GD_NO_WX_GUI)
/**
* \brief Must provide a gd::LayoutEditorPreviewer object that will be stored
* and used by LayoutEditorCanvas to display/run a preview of the layout of a
* project.
*
* The default implementation simply return a gd::LayoutEditorPreviewer object
* doing nothing.
*/
virtual std::shared_ptr<gd::LayoutEditorPreviewer> GetLayoutPreviewer(
gd::LayoutEditorCanvas& editor) const;
/**
* \brief Must provide at least one gd::ProjectExporter object that will be used
* by the IDE to export the project so as to be used without the IDE.
*
* The default implementation simply return a vector containing a gd::ProjectExporter object doing nothing.
*/
virtual std::vector<std::shared_ptr<gd::ProjectExporter>> GetProjectExporters() const;
#endif
///@}
/**
* \brief Must provide at least one gd::ProjectExporter object that will be
* used by the IDE to export the project so as to be used without the IDE.
*
* The default implementation simply return a vector containing a
* gd::ProjectExporter object doing nothing.
*/
virtual std::vector<std::shared_ptr<gd::ProjectExporter>>
GetProjectExporters() const;
#endif
///@}
/**
* \brief Called when the IDE is about to shut down: Take this opportunity for erasing
* for example any temporary file.
*/
virtual void OnIDEClosed() {};
/**
* \brief Called when the IDE is about to shut down: Take this opportunity for
* erasing for example any temporary file.
*/
virtual void OnIDEClosed(){};
/**
* \brief Called when the IDE is initialized and ready to be used.
*/
virtual void OnIDEInitialized() {};
/**
* \brief Called when the IDE is initialized and ready to be used.
*/
virtual void OnIDEInitialized(){};
#endif
#endif
private:
std::vector < std::shared_ptr<PlatformExtension> > extensionsLoaded; ///< Extensions of the platform
std::map < gd::String, CreateFunPtr > creationFunctionTable; ///< Creation functions for objects
private:
std::vector<std::shared_ptr<PlatformExtension>>
extensionsLoaded; ///< Extensions of the platform
std::map<gd::String, CreateFunPtr>
creationFunctionTable; ///< Creation functions for objects
#if defined(GD_IDE_ONLY)
static ChangesNotifier defaultEmptyChangesNotifier;
#endif
#if defined(GD_IDE_ONLY)
static ChangesNotifier defaultEmptyChangesNotifier;
#endif
};
}
} // namespace gd
#endif // GDCORE_PLATFORM_H
#endif // GDCORE_PLATFORM_H

File diff suppressed because it is too large Load Diff

View File

@@ -1,462 +1,531 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* Copyright 2016 Victor Levasseur (victorlevasseur52@gmail.com)
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. Copyright 2016 Victor Levasseur (victorlevasseur52@gmail.com) This
* project is released under the MIT License.
*/
#ifndef GDCORE_PLATFORMEXTENSION_H
#define GDCORE_PLATFORMEXTENSION_H
#include <map>
#include <vector>
#include <memory>
#include "GDCore/Extensions/Metadata/ObjectMetadata.h"
#include <vector>
#include "GDCore/CommonTools.h"
#include "GDCore/Extensions/Metadata/BehaviorMetadata.h"
#include "GDCore/Extensions/Metadata/EventMetadata.h"
#include "GDCore/CommonTools.h"
#include "GDCore/Extensions/Metadata/ObjectMetadata.h"
#include "GDCore/String.h"
#include "GDCore/Tools/VersionPriv.h"
namespace gd { class Instruction; }
namespace gd { class InstructionMetadata; }
namespace gd { class ExpressionMetadata; }
namespace gd { class ObjectMetadata; }
namespace gd { class BehaviorMetadata; }
namespace gd { class BaseEvent; }
namespace gd { class EventMetadata; }
namespace gd { class EventCodeGenerator; }
namespace gd { class ArbitraryResourceWorker; }
namespace gd { class BehaviorsSharedData; }
namespace gd { class Behavior; }
namespace gd { class Object; }
namespace gd {
class Instruction;
}
namespace gd {
class InstructionMetadata;
}
namespace gd {
class ExpressionMetadata;
}
namespace gd {
class ObjectMetadata;
}
namespace gd {
class BehaviorMetadata;
}
namespace gd {
class BaseEvent;
}
namespace gd {
class EventMetadata;
}
namespace gd {
class EventCodeGenerator;
}
namespace gd {
class ArbitraryResourceWorker;
}
namespace gd {
class BehaviorsSharedData;
}
namespace gd {
class Behavior;
}
namespace gd {
class Object;
}
typedef std::unique_ptr<gd::Object> (*CreateFunPtr)(gd::String name);
namespace gd
{
namespace gd {
/**
* \brief Class used by gd::PlatformExtension to ensure that an extension is compiled against the right versions of libraries.
* \brief Class used by gd::PlatformExtension to ensure that an extension is
* compiled against the right versions of libraries.
*/
class GD_CORE_API CompilationInfo
{
public :
CompilationInfo() : informationCompleted(false) {};
virtual ~CompilationInfo() {};
class GD_CORE_API CompilationInfo {
public:
CompilationInfo() : informationCompleted(false){};
virtual ~CompilationInfo(){};
bool informationCompleted;
bool informationCompleted;
bool runtimeOnly; ///< True if the extension was compiled for a runtime use only
bool runtimeOnly; ///< True if the extension was compiled for a runtime use
///< only
#if defined(__GNUC__)
int gccMajorVersion;
int gccMinorVersion;
int gccPatchLevel;
#endif
#if defined(__GNUC__)
int gccMajorVersion;
int gccMinorVersion;
int gccPatchLevel;
#endif
int sfmlMajorVersion;
int sfmlMinorVersion;
int sfmlMajorVersion;
int sfmlMinorVersion;
#if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
int wxWidgetsMajorVersion;
int wxWidgetsMinorVersion;
int wxWidgetsReleaseNumber;
int wxWidgetsSubReleaseNumber;
#endif
#if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
int wxWidgetsMajorVersion;
int wxWidgetsMinorVersion;
int wxWidgetsReleaseNumber;
int wxWidgetsSubReleaseNumber;
#endif
gd::String gdCoreVersion;
int sizeOfpInt;
gd::String gdCoreVersion;
int sizeOfpInt;
};
/**
* \brief Base class for implementing platform's extensions.
*
* \ingroup PlatformDefinition
*/
class GD_CORE_API PlatformExtension
{
public:
CompilationInfo compilationInfo;
class GD_CORE_API PlatformExtension {
public:
CompilationInfo compilationInfo;
PlatformExtension();
virtual ~PlatformExtension();
PlatformExtension();
virtual ~PlatformExtension();
/**
* \brief Must be called to declare the main information about the extension.
*/
void SetExtensionInformation(const gd::String & name_,
const gd::String & fullname_,
const gd::String & description_,
const gd::String & author_,
const gd::String & license_);
/**
* \brief Must be called to declare the main information about the extension.
*/
void SetExtensionInformation(const gd::String& name_,
const gd::String& fullname_,
const gd::String& description_,
const gd::String& author_,
const gd::String& license_);
/**
* \brief Mark this extension as deprecated: the IDE will hide it from the user.
*/
void MarkAsDeprecated() { deprecated = true; }
/**
* \brief Mark this extension as deprecated: the IDE will hide it from the
* user.
*/
void MarkAsDeprecated() { deprecated = true; }
/**
* \brief Declare a new condition as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
*/
gd::InstructionMetadata & AddCondition(const gd::String & name_,
const gd::String & fullname_,
const gd::String & description_,
const gd::String & sentence_,
const gd::String & group_,
const gd::String & icon_,
const gd::String & smallicon_);
/**
* \brief Declare a new condition as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
*/
gd::InstructionMetadata& AddCondition(const gd::String& name_,
const gd::String& fullname_,
const gd::String& description_,
const gd::String& sentence_,
const gd::String& group_,
const gd::String& icon_,
const gd::String& smallicon_);
/**
* \brief Declare a new action as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
*/
gd::InstructionMetadata & AddAction(const gd::String & name_,
const gd::String & fullname_,
const gd::String & description_,
const gd::String & sentence_,
const gd::String & group_,
const gd::String & icon_,
const gd::String & smallicon_);
/**
* \brief Declare a new expression as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
*/
gd::ExpressionMetadata & AddExpression(const gd::String & name_,
const gd::String & fullname_,
const gd::String & description_,
const gd::String & group_,
const gd::String & smallicon_);
/**
* \brief Declare a new String expression as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
*/
gd::ExpressionMetadata & AddStrExpression(const gd::String & name_,
const gd::String & fullname_,
const gd::String & description_,
const gd::String & group_,
const gd::String & smallicon_);
/**
* \brief Declare a new action as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
*/
gd::InstructionMetadata& AddAction(const gd::String& name_,
const gd::String& fullname_,
const gd::String& description_,
const gd::String& sentence_,
const gd::String& group_,
const gd::String& icon_,
const gd::String& smallicon_);
/**
* \brief Declare a new expression as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
*/
gd::ExpressionMetadata& AddExpression(const gd::String& name_,
const gd::String& fullname_,
const gd::String& description_,
const gd::String& group_,
const gd::String& smallicon_);
/**
* \brief Declare a new String expression as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
*/
gd::ExpressionMetadata& AddStrExpression(const gd::String& name_,
const gd::String& fullname_,
const gd::String& description_,
const gd::String& group_,
const gd::String& smallicon_);
/**
* \brief Declare a new object as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
* \tparam T the declared class inherited from *gd::Object*
* \param name The name of the object
* \param fullname The user friendly name of the object
* \param description The user friendly description of the object
* \param icon The 24x24 icon of the object: res/icons_[SkinName]/[iconName]24.png will be first tried,
* and then if it does not exists, the full entered name will be tried.
\endcode
*/
template<class T>
gd::ObjectMetadata & AddObject(const gd::String & name_,
const gd::String & fullname_,
const gd::String & description_,
const gd::String & icon24x24_);
/**
* \brief Declare a new object as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
* \tparam T the declared class inherited from *gd::Object*
* \param name The name of the object
* \param fullname The user friendly name of the object
* \param description The user friendly description of the object
* \param icon The 24x24 icon of the object:
res/icons_[SkinName]/[iconName]24.png will be first tried,
* and then if it does not exists, the full entered name will be tried.
\endcode
*/
template <class T>
gd::ObjectMetadata& AddObject(const gd::String& name_,
const gd::String& fullname_,
const gd::String& description_,
const gd::String& icon24x24_);
/**
* \brief Declare a new behavior as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
*
* \param name The name of the behavior
* \param fullname The user friendly name of the behavior
* \param description The user friendly description of the behavior
* \param icon The 24x24 icon of the behavior: res/icons_[SkinName]/[iconName]24.png will be first tried,
* and then if it does not exists, it is assumed that the icon name is the filename that must be used to open the icon.
* \param instance An instance of the behavior that will be used to create the behavior
* \param sharedDatasInstance Optional instance of the data shared by the behaviors having the same name.
*/
gd::BehaviorMetadata & AddBehavior(const gd::String & name_,
const gd::String & fullname_,
const gd::String & defaultName_,
const gd::String & description_,
const gd::String & group_,
const gd::String & icon24x24_,
const gd::String & className_,
std::shared_ptr<gd::Behavior> instance,
std::shared_ptr<gd::BehaviorsSharedData> sharedDatasInstance);
/**
* \brief Declare a new behavior as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
*
* \param name The name of the behavior
* \param fullname The user friendly name of the behavior
* \param description The user friendly description of the behavior
* \param icon The 24x24 icon of the behavior:
* res/icons_[SkinName]/[iconName]24.png will be first tried, and then if it
* does not exists, it is assumed that the icon name is the filename that must
* be used to open the icon. \param instance An instance of the behavior that
* will be used to create the behavior \param sharedDatasInstance Optional
* instance of the data shared by the behaviors having the same name.
*/
gd::BehaviorMetadata& AddBehavior(
const gd::String& name_,
const gd::String& fullname_,
const gd::String& defaultName_,
const gd::String& description_,
const gd::String& group_,
const gd::String& icon24x24_,
const gd::String& className_,
std::shared_ptr<gd::Behavior> instance,
std::shared_ptr<gd::BehaviorsSharedData> sharedDatasInstance);
/**
* \brief Declare a new event as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
*/
gd::EventMetadata & AddEvent(const gd::String & name_,
const gd::String & fullname_,
const gd::String & description_,
const gd::String & group_,
const gd::String & smallicon_,
std::shared_ptr<gd::BaseEvent> instance);
/**
* \brief Declare a new event as being part of the extension.
* \note This method does nothing when used for GD C++ runtime.
*/
gd::EventMetadata& AddEvent(const gd::String& name_,
const gd::String& fullname_,
const gd::String& description_,
const gd::String& group_,
const gd::String& smallicon_,
std::shared_ptr<gd::BaseEvent> instance);
/**
* \brief Return the name extension user friendly name.
*/
const gd::String & GetFullName() const { return fullname; }
/**
* \brief Return the name extension user friendly name.
*/
const gd::String& GetFullName() const { return fullname; }
/**
* \brief Return the name of the extension
*/
const gd::String & GetName() const { return name; }
/**
* \brief Return the name of the extension
*/
const gd::String& GetName() const { return name; }
/**
* \brief Return a description of the extension
*/
const gd::String & GetDescription() const { return informations; }
/**
* \brief Return a description of the extension
*/
const gd::String& GetDescription() const { return informations; }
/**
* \brief Return the name of the extension developer
*/
const gd::String & GetAuthor() const { return author; }
/**
* \brief Return the name of the extension developer
*/
const gd::String& GetAuthor() const { return author; }
/**
* \brief Return the name of extension license
*/
const gd::String & GetLicense() const { return license; }
/**
* \brief Return the name of extension license
*/
const gd::String& GetLicense() const { return license; }
/**
* \brief Check if the extension is flagged as being deprecated.
*/
bool IsDeprecated() const { return deprecated; }
/**
* \brief Check if the extension is flagged as being deprecated.
*/
bool IsDeprecated() const { return deprecated; }
/**
* \brief Return true if the extension is a standard extension that cannot be deactivated
*/
bool IsBuiltin() const;
/**
* \brief Return true if the extension is a standard extension that cannot be
* deactivated
*/
bool IsBuiltin() const;
/**
* \brief Get the namespace of the extension.
* \note The namespace is simply the name of the extension concatenated with "::" at the end.
*/
const gd::String & GetNameSpace() { return nameSpace; };
/**
* \brief Get the namespace of the extension.
* \note The namespace is simply the name of the extension concatenated with
* "::" at the end.
*/
const gd::String& GetNameSpace() { return nameSpace; };
/**
* \brief Return a vector containing all the object types provided by the extension
*/
std::vector < gd::String > GetExtensionObjectsTypes() const;
/**
* \brief Return a vector containing all the object types provided by the
* extension
*/
std::vector<gd::String> GetExtensionObjectsTypes() const;
/**
* \brief Return a vector containing all the behavior types provided by the extension
*/
std::vector < gd::String > GetBehaviorsTypes() const;
/**
* \brief Return a vector containing all the behavior types provided by the
* extension
*/
std::vector<gd::String> GetBehaviorsTypes() const;
/**
* \brief Return a function to create the object if the type is handled by the extension
*/
CreateFunPtr GetObjectCreationFunctionPtr(gd::String objectType) const;
/**
* \brief Return a function to create the object if the type is handled by the
* extension
*/
CreateFunPtr GetObjectCreationFunctionPtr(gd::String objectType) const;
/**
* \brief Create a custom event.
*
* Return an empty pointer if \a eventType is not provided by the extension.
*/
std::shared_ptr<gd::BaseEvent> CreateEvent(gd::String eventType) const;
/**
* \brief Create a behavior
*
* Return NULL if \a behaviorType is not provided by the extension.
*/
std::unique_ptr<gd::Behavior> CreateBehavior(gd::String behaviorType) const;
/**
* \brief Create a custom event.
*
* Return an empty pointer if \a eventType is not provided by the extension.
*/
std::shared_ptr<gd::BaseEvent> CreateEvent(gd::String eventType) const;
/**
* \brief Create a behavior
*
* Return NULL if \a behaviorType is not provided by the extension.
*/
std::unique_ptr<gd::Behavior> CreateBehavior(gd::String behaviorType) const;
/**
* \brief Create shared data for a behavior
*
* Return NULL if \a behaviorType is not provided by the extension.
*/
std::shared_ptr<gd::BehaviorsSharedData> CreateBehaviorSharedDatas(gd::String behaviorType) const;
/**
* \brief Create shared data for a behavior
*
* Return NULL if \a behaviorType is not provided by the extension.
*/
std::shared_ptr<gd::BehaviorsSharedData> CreateBehaviorSharedDatas(
gd::String behaviorType) const;
/**
* \brief Return a reference to the ObjectMetadata object associated to \a objectType
*/
ObjectMetadata & GetObjectMetadata(const gd::String & objectType);
/**
* \brief Return a reference to the ObjectMetadata object associated to \a
* objectType
*/
ObjectMetadata& GetObjectMetadata(const gd::String& objectType);
/**
* \brief Return a reference to the BehaviorMetadata object associated to \a behaviorType
*/
BehaviorMetadata & GetBehaviorMetadata(const gd::String & behaviorType);
/**
* \brief Return a reference to the BehaviorMetadata object associated to \a
* behaviorType
*/
BehaviorMetadata& GetBehaviorMetadata(const gd::String& behaviorType);
/**
* \brief Return a map containing all the events provided by the extension
*/
std::map<gd::String, gd::EventMetadata > & GetAllEvents();
/**
* \brief Return a map containing all the events provided by the extension
*/
std::map<gd::String, gd::EventMetadata>& GetAllEvents();
#if defined(GD_IDE_ONLY)
/**
* \brief Return a reference to a map containing the names of the actions (in the first members) and the metadata associated with (in the second members).
*/
std::map<gd::String, gd::InstructionMetadata > & GetAllActions();
#if defined(GD_IDE_ONLY)
/**
* \brief Return a reference to a map containing the names of the actions (in
* the first members) and the metadata associated with (in the second
* members).
*/
std::map<gd::String, gd::InstructionMetadata>& GetAllActions();
/**
* \see gd::PlatformExtension::GetAllActions
*/
std::map<gd::String, gd::InstructionMetadata > & GetAllConditions();
/**
* \see gd::PlatformExtension::GetAllActions
*/
std::map<gd::String, gd::InstructionMetadata>& GetAllConditions();
/**
* \see gd::PlatformExtension::GetAllActions
*/
std::map<gd::String, gd::ExpressionMetadata > & GetAllExpressions();
/**
* \see gd::PlatformExtension::GetAllActions
*/
std::map<gd::String, gd::ExpressionMetadata>& GetAllExpressions();
/**
* \see gd::PlatformExtension::GetAllActions
*/
std::map<gd::String, gd::ExpressionMetadata > & GetAllStrExpressions();
/**
* \see gd::PlatformExtension::GetAllActions
*/
std::map<gd::String, gd::ExpressionMetadata>& GetAllStrExpressions();
/**
* \brief Return a reference to a map containing the names of the actions, related to the object type, and the metadata associated with.
*/
std::map<gd::String, gd::InstructionMetadata > & GetAllActionsForObject(gd::String objectType);
/**
* \brief Return a reference to a map containing the names of the actions,
* related to the object type, and the metadata associated with.
*/
std::map<gd::String, gd::InstructionMetadata>& GetAllActionsForObject(
gd::String objectType);
/**
* \see gd::PlatformExtension::GetAllActionsForObject
*/
std::map<gd::String, gd::InstructionMetadata > & GetAllConditionsForObject(gd::String objectType);
/**
* \see gd::PlatformExtension::GetAllActionsForObject
*/
std::map<gd::String, gd::InstructionMetadata>& GetAllConditionsForObject(
gd::String objectType);
/**
* \see gd::PlatformExtension::GetAllActionsForObject
*/
std::map<gd::String, gd::ExpressionMetadata > & GetAllExpressionsForObject(gd::String objectType);
/**
* \see gd::PlatformExtension::GetAllActionsForObject
*/
std::map<gd::String, gd::ExpressionMetadata>& GetAllExpressionsForObject(
gd::String objectType);
/**
* \see gd::PlatformExtension::GetAllActionsForObject
*/
std::map<gd::String, gd::ExpressionMetadata > & GetAllStrExpressionsForObject(gd::String objectType);
/**
* \see gd::PlatformExtension::GetAllActionsForObject
*/
std::map<gd::String, gd::ExpressionMetadata>& GetAllStrExpressionsForObject(
gd::String objectType);
/**
* \see gd::PlatformExtension::GetAllActionsForObject
*/
std::map<gd::String, gd::InstructionMetadata > & GetAllActionsForBehavior(gd::String autoType);
/**
* \see gd::PlatformExtension::GetAllActionsForObject
*/
std::map<gd::String, gd::InstructionMetadata>& GetAllActionsForBehavior(
gd::String autoType);
/**
* \see gd::PlatformExtension::GetAllActionsForObject
*/
std::map<gd::String, gd::InstructionMetadata > & GetAllConditionsForBehavior(gd::String autoType);
/**
* \see gd::PlatformExtension::GetAllActionsForObject
*/
std::map<gd::String, gd::InstructionMetadata>& GetAllConditionsForBehavior(
gd::String autoType);
/**
* \see gd::PlatformExtension::GetAllActionsForObject
*/
std::map<gd::String, gd::ExpressionMetadata > & GetAllExpressionsForBehavior(gd::String autoType);
/**
* \see gd::PlatformExtension::GetAllActionsForObject
*/
std::map<gd::String, gd::ExpressionMetadata>& GetAllExpressionsForBehavior(
gd::String autoType);
/**
* \see gd::PlatformExtension::GetAllActionsForObject
*/
std::map<gd::String, gd::ExpressionMetadata > & GetAllStrExpressionsForBehavior(gd::String autoType);
/**
* \see gd::PlatformExtension::GetAllActionsForObject
*/
std::map<gd::String, gd::ExpressionMetadata>& GetAllStrExpressionsForBehavior(
gd::String autoType);
/**
* Called ( e.g. during compilation ) so as to inventory resources used by conditions and update their filename
*
* \see gd::PlatformExtension::ExposeActionsResources
*/
virtual void ExposeConditionsResources(Instruction & condition, gd::ArbitraryResourceWorker & worker) {};
/**
* Called ( e.g. during compilation ) so as to inventory resources used by
* conditions and update their filename
*
* \see gd::PlatformExtension::ExposeActionsResources
*/
virtual void ExposeConditionsResources(Instruction& condition,
gd::ArbitraryResourceWorker& worker){};
/**
* Called ( e.g. during compilation ) so as to inventory resources used by actions and update their filename
*
* \see ArbitraryResourceWorker
*/
virtual void ExposeActionsResources(Instruction & action, gd::ArbitraryResourceWorker & worker) {};
/**
* Called ( e.g. during compilation ) so as to inventory resources used by
* actions and update their filename
*
* \see ArbitraryResourceWorker
*/
virtual void ExposeActionsResources(Instruction& action,
gd::ArbitraryResourceWorker& worker){};
/**
* \brief Clone the extension of another platform.
*
* This can be used when you want a platform to conform to another.<br>
* It is still possible to make some changes after the cloning by using getter methods.<br>
* See also gd::PlatformExtension::StripUnimplementedInstructionsAndExpressions.
*
* \param platformName The name of the platform in which the source extension must be searched for.
* \param extensionName The name of the source extension to be copied.
* \param stripFunctionsNameAndCodeGeneration If set to true, all functions names and code generator of all instructions/expression/events
* will be removed.
*/
void CloneExtension(const gd::String & platformName, const gd::String & extensionName, bool stripFunctionsNameAndCodeGeneration = true);
/**
* \brief Clone the extension of another platform.
*
* This can be used when you want a platform to conform to another.<br>
* It is still possible to make some changes after the cloning by using getter
* methods.<br> See also
* gd::PlatformExtension::StripUnimplementedInstructionsAndExpressions.
*
* \param platformName The name of the platform in which the source extension
* must be searched for. \param extensionName The name of the source extension
* to be copied. \param stripFunctionsNameAndCodeGeneration If set to true,
* all functions names and code generator of all
* instructions/expression/events will be removed.
*/
void CloneExtension(const gd::String& platformName,
const gd::String& extensionName,
bool stripFunctionsNameAndCodeGeneration = true);
/**
* \brief Delete all instructions having no functions name or custom code generator.
*/
void StripUnimplementedInstructionsAndExpressions();
#endif
/**
* \brief Delete all instructions having no functions name or custom code
* generator.
*/
void StripUnimplementedInstructionsAndExpressions();
#endif
/**
* \brief Return the name of all the extensions which are considered provided by platforms.
*/
static std::vector<gd::String> GetBuiltinExtensionsNames();
/**
* \brief Return the name of all the extensions which are considered provided
* by platforms.
*/
static std::vector<gd::String> GetBuiltinExtensionsNames();
private:
private:
/**
* Set the namespace ( the String each actions/conditions/expressions start
* with )
*/
void SetNameSpace(gd::String nameSpace_);
/**
* Set the namespace ( the String each actions/conditions/expressions start with )
*/
void SetNameSpace(gd::String nameSpace_);
gd::String name; ///< Name identifying the extension
gd::String
nameSpace; ///< Automatically set from the name of the extension, and
///< added to every
///< actions/conditions/expressions/objects/behavior/event.
gd::String fullname; ///< Name displayed to users at edittime
gd::String informations; ///< Description displayed to users at edittime
gd::String author; ///< Author displayed to users at edittime
gd::String license; ///< License name displayed to users at edittime
bool deprecated;
gd::String name; ///<Name identifying the extension
gd::String nameSpace; ///<Automatically set from the name of the extension, and added to every actions/conditions/expressions/objects/behavior/event.
gd::String fullname; ///<Name displayed to users at edittime
gd::String informations; ///<Description displayed to users at edittime
gd::String author; ///<Author displayed to users at edittime
gd::String license; ///<License name displayed to users at edittime
bool deprecated;
std::map<gd::String, gd::ObjectMetadata> objectsInfos;
std::map<gd::String, gd::BehaviorMetadata> behaviorsInfo;
#if defined(GD_IDE_ONLY)
std::map<gd::String, gd::InstructionMetadata> conditionsInfos;
std::map<gd::String, gd::InstructionMetadata> actionsInfos;
std::map<gd::String, gd::ExpressionMetadata> expressionsInfos;
std::map<gd::String, gd::ExpressionMetadata> strExpressionsInfos;
std::map<gd::String, gd::EventMetadata> eventsInfos;
#endif
std::map<gd::String, gd::ObjectMetadata > objectsInfos;
std::map<gd::String, gd::BehaviorMetadata > behaviorsInfo;
#if defined(GD_IDE_ONLY)
std::map<gd::String, gd::InstructionMetadata > conditionsInfos;
std::map<gd::String, gd::InstructionMetadata > actionsInfos;
std::map<gd::String, gd::ExpressionMetadata > expressionsInfos;
std::map<gd::String, gd::ExpressionMetadata > strExpressionsInfos;
std::map<gd::String, gd::EventMetadata > eventsInfos;
#endif
ObjectMetadata badObjectMetadata;
BehaviorMetadata badBehaviorMetadata;
#if defined(GD_IDE_ONLY)
static std::map<gd::String, gd::InstructionMetadata > badConditionsMetadata; ///< Used when a condition is not found in the extension
static std::map<gd::String, gd::InstructionMetadata > badActionsMetadata; ///< Used when an action is not found in the extension
static std::map<gd::String, gd::ExpressionMetadata > badExpressionsMetadata; ///< Used when an expression is not found in the extension
static std::map<gd::String, gd::ExpressionMetadata > badStrExpressionsMetadata;///< Used when an expression is not found in the extension
#endif
ObjectMetadata badObjectMetadata;
BehaviorMetadata badBehaviorMetadata;
#if defined(GD_IDE_ONLY)
static std::map<gd::String, gd::InstructionMetadata>
badConditionsMetadata; ///< Used when a condition is not found in the
///< extension
static std::map<gd::String, gd::InstructionMetadata>
badActionsMetadata; ///< Used when an action is not found in the
///< extension
static std::map<gd::String, gd::ExpressionMetadata>
badExpressionsMetadata; ///< Used when an expression is not found in the
///< extension
static std::map<gd::String, gd::ExpressionMetadata>
badStrExpressionsMetadata; ///< Used when an expression is not found in
///< the extension
#endif
};
}
} // namespace gd
#if defined(GD_IDE_ONLY)
#if !defined(GD_NO_WX_GUI)
#define GD_COMPLETE_WX_COMPILATION_INFORMATION() compilationInfo.wxWidgetsMajorVersion = wxMAJOR_VERSION; \
compilationInfo.wxWidgetsMinorVersion = wxMINOR_VERSION; \
compilationInfo.wxWidgetsReleaseNumber = wxRELEASE_NUMBER; \
compilationInfo.wxWidgetsSubReleaseNumber = wxSUBRELEASE_NUMBER;
#define GD_COMPLETE_WX_COMPILATION_INFORMATION() \
compilationInfo.wxWidgetsMajorVersion = wxMAJOR_VERSION; \
compilationInfo.wxWidgetsMinorVersion = wxMINOR_VERSION; \
compilationInfo.wxWidgetsReleaseNumber = wxRELEASE_NUMBER; \
compilationInfo.wxWidgetsSubReleaseNumber = wxSUBRELEASE_NUMBER;
#else
#define GD_COMPLETE_WX_COMPILATION_INFORMATION() ;
#define GD_COMPLETE_WX_COMPILATION_INFORMATION() ;
#endif
/** \brief Macro used by extensions in their constructor to declare how they have been compiled.
* \see gd::CompilationInfo
/** \brief Macro used by extensions in their constructor to declare how they
* have been compiled. \see gd::CompilationInfo
*/
#define GD_COMPLETE_EXTENSION_COMPILATION_INFORMATION() compilationInfo.runtimeOnly = false; \
compilationInfo.sfmlMajorVersion = 2; \
compilationInfo.sfmlMinorVersion = 0; \
compilationInfo.gdCoreVersion = GD_VERSION_STRING; \
compilationInfo.sizeOfpInt = sizeof(int*); \
GD_COMPLETE_WX_COMPILATION_INFORMATION() \
compilationInfo.gccMajorVersion = __GNUC__; \
compilationInfo.gccMinorVersion = __GNUC_MINOR__; \
compilationInfo.gccPatchLevel = __GNUC_PATCHLEVEL__; \
compilationInfo.informationCompleted = true;
#define GD_COMPLETE_EXTENSION_COMPILATION_INFORMATION() \
compilationInfo.runtimeOnly = false; \
compilationInfo.sfmlMajorVersion = 2; \
compilationInfo.sfmlMinorVersion = 0; \
compilationInfo.gdCoreVersion = GD_VERSION_STRING; \
compilationInfo.sizeOfpInt = sizeof(int*); \
GD_COMPLETE_WX_COMPILATION_INFORMATION() \
compilationInfo.gccMajorVersion = __GNUC__; \
compilationInfo.gccMinorVersion = __GNUC_MINOR__; \
compilationInfo.gccPatchLevel = __GNUC_PATCHLEVEL__; \
compilationInfo.informationCompleted = true;
#else
/** \brief Macro used by extensions in their constructor to declare how they have been compiled.
* \see gd::CompilationInfo
/** \brief Macro used by extensions in their constructor to declare how they
* have been compiled. \see gd::CompilationInfo
*/
#define GD_COMPLETE_EXTENSION_COMPILATION_INFORMATION() compilationInfo.runtimeOnly = true;\
compilationInfo.sfmlMajorVersion = 2; \
compilationInfo.sfmlMinorVersion = 0; \
compilationInfo.gdCoreVersion = GD_VERSION_STRING; \
compilationInfo.sizeOfpInt = sizeof(int*); \
compilationInfo.gccMajorVersion = __GNUC__; \
compilationInfo.gccMinorVersion = __GNUC_MINOR__; \
compilationInfo.gccPatchLevel = __GNUC_PATCHLEVEL__; \
compilationInfo.informationCompleted = true;
#define GD_COMPLETE_EXTENSION_COMPILATION_INFORMATION() \
compilationInfo.runtimeOnly = true; \
compilationInfo.sfmlMajorVersion = 2; \
compilationInfo.sfmlMinorVersion = 0; \
compilationInfo.gdCoreVersion = GD_VERSION_STRING; \
compilationInfo.sizeOfpInt = sizeof(int*); \
compilationInfo.gccMajorVersion = __GNUC__; \
compilationInfo.gccMinorVersion = __GNUC_MINOR__; \
compilationInfo.gccPatchLevel = __GNUC_PATCHLEVEL__; \
compilationInfo.informationCompleted = true;
#endif
#include "GDCore/Extensions/PlatformExtension.inl"
#endif // GDCORE_PLATFORMEXTENSION_H
#endif // GDCORE_PLATFORMEXTENSION_H

View File

@@ -1,8 +1,8 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* Copyright 2016 Victor Levasseur (victorlevasseur52@gmail.com)
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. Copyright 2016 Victor Levasseur (victorlevasseur52@gmail.com) This
* project is released under the MIT License.
*/
#ifndef GDCORE_PLATFORMEXTENSION_INL
@@ -10,27 +10,28 @@
#include "GDCore/Tools/MakeUnique.h"
namespace gd
{
namespace gd {
template<class T>
gd::ObjectMetadata & PlatformExtension::AddObject(const gd::String & name,
const gd::String & fullname, const gd::String & description,
const gd::String & icon24x24)
{
gd::String nameWithNamespace = GetNameSpace().empty() ? name : GetNameSpace()+name;
objectsInfos[nameWithNamespace] = ObjectMetadata(
GetNameSpace(),
nameWithNamespace,
fullname,
description,
icon24x24,
[](gd::String name) -> std::unique_ptr<gd::Object> { return gd::make_unique<T>(name); }
);
template <class T>
gd::ObjectMetadata& PlatformExtension::AddObject(const gd::String& name,
const gd::String& fullname,
const gd::String& description,
const gd::String& icon24x24) {
gd::String nameWithNamespace =
GetNameSpace().empty() ? name : GetNameSpace() + name;
objectsInfos[nameWithNamespace] =
ObjectMetadata(GetNameSpace(),
nameWithNamespace,
fullname,
description,
icon24x24,
[](gd::String name) -> std::unique_ptr<gd::Object> {
return gd::make_unique<T>(name);
});
return objectsInfos[nameWithNamespace];
return objectsInfos[nameWithNamespace];
}
}
} // namespace gd
#endif

View File

@@ -1,214 +1,191 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "GDCore/String.h"
#include "GDCore/Tools/FileStream.h"
#include <algorithm>
#include "AbstractFileSystem.h"
#include <algorithm>
#include "GDCore/CommonTools.h"
#include "GDCore/IDE/wxTools/RecursiveMkDir.h"
#include "GDCore/String.h"
#include "GDCore/Tools/FileStream.h"
#if !defined(GD_NO_WX_GUI)
#include <fstream>
#include <wx/filename.h>
#include <iostream>
#include <wx/log.h>
#include <wx/filefn.h>
#include <wx/dir.h>
#include <wx/filefn.h>
#include <wx/filename.h>
#include <wx/log.h>
#include <fstream>
#include <iostream>
#endif
#undef CopyFile //Remove a Windows macro
#undef CopyFile // Remove a Windows macro
namespace gd
{
namespace gd {
AbstractFileSystem::~AbstractFileSystem()
{
}
AbstractFileSystem::~AbstractFileSystem() {}
gd::String gd::AbstractFileSystem::NormalizeSeparator(gd::String filename)
{
//Convert all backslash to slashs.
return filename.FindAndReplace("\\", "/");
gd::String gd::AbstractFileSystem::NormalizeSeparator(gd::String filename) {
// Convert all backslash to slashs.
return filename.FindAndReplace("\\", "/");
}
#if !defined(GD_NO_WX_GUI)
NativeFileSystem *NativeFileSystem::singleton = NULL;
gd::String NativeFileSystem::FileNameFrom(const gd::String & file)
{
wxFileName filename = wxFileName::FileName( file );
return filename.GetFullName();
gd::String NativeFileSystem::FileNameFrom(const gd::String &file) {
wxFileName filename = wxFileName::FileName(file);
return filename.GetFullName();
}
gd::String NativeFileSystem::DirNameFrom(const gd::String & file)
{
wxFileName filename = wxFileName::FileName( file );
return filename.GetPath();
gd::String NativeFileSystem::DirNameFrom(const gd::String &file) {
wxFileName filename = wxFileName::FileName(file);
return filename.GetPath();
}
bool NativeFileSystem::IsAbsolute(const gd::String & filename)
{
return wxFileName::FileName(filename).IsAbsolute();
bool NativeFileSystem::IsAbsolute(const gd::String &filename) {
return wxFileName::FileName(filename).IsAbsolute();
}
bool NativeFileSystem::MakeAbsolute(gd::String & fn, const gd::String & baseDirectory)
{
wxFileName filename = wxFileName::FileName(fn);
bool success = filename.MakeAbsolute(baseDirectory);
fn = filename.GetFullPath();
return success;
bool NativeFileSystem::MakeAbsolute(gd::String &fn,
const gd::String &baseDirectory) {
wxFileName filename = wxFileName::FileName(fn);
bool success = filename.MakeAbsolute(baseDirectory);
fn = filename.GetFullPath();
return success;
}
bool NativeFileSystem::MakeRelative(gd::String & fn, const gd::String & baseDirectory)
{
wxFileName filename = wxFileName::FileName(fn);
bool success = filename.MakeRelativeTo(baseDirectory);
if (success)
{
fn = filename.GetFullPath(wxPATH_UNIX);
return true;
}
return false;
}
bool NativeFileSystem::DirExists(const gd::String & path)
{
return wxDirExists(path);
}
bool NativeFileSystem::FileExists(const gd::String & path)
{
return wxFileExists(path);
}
void NativeFileSystem::MkDir(const gd::String & directory)
{
RecursiveMkDir::MkDir(directory);
}
bool NativeFileSystem::ClearDir(const gd::String & directory)
{
wxString file = wxFindFirstFile( directory + "/*" );
while ( !file.empty() )
{
wxRemoveFile( file );
file = wxFindNextFile();
}
bool NativeFileSystem::MakeRelative(gd::String &fn,
const gd::String &baseDirectory) {
wxFileName filename = wxFileName::FileName(fn);
bool success = filename.MakeRelativeTo(baseDirectory);
if (success) {
fn = filename.GetFullPath(wxPATH_UNIX);
return true;
}
return false;
}
gd::String NativeFileSystem::GetTempDir()
{
return wxFileName::GetTempDir();
bool NativeFileSystem::DirExists(const gd::String &path) {
return wxDirExists(path);
}
bool NativeFileSystem::WriteToFile(const gd::String & filename, const gd::String & content)
{
gd::FileStream file( filename, std::ios_base::out );
if ( file.is_open() ) {
file << content.ToUTF8();
file.close();
return true;
}
return false;
bool NativeFileSystem::FileExists(const gd::String &path) {
return wxFileExists(path);
}
gd::String NativeFileSystem::ReadFile(const gd::String & file)
{
gd::FileStream t( file, std::ios_base::in );
std::stringstream buffer;
buffer << t.rdbuf();
return gd::String::FromUTF8(buffer.str());
void NativeFileSystem::MkDir(const gd::String &directory) {
RecursiveMkDir::MkDir(directory);
}
bool NativeFileSystem::ClearDir(const gd::String &directory) {
wxString file = wxFindFirstFile(directory + "/*");
while (!file.empty()) {
wxRemoveFile(file);
file = wxFindNextFile();
}
std::vector<gd::String> NativeFileSystem::ReadDir(const gd::String & path, const gd::String & extension)
{
std::vector<gd::String> results;
wxString upperExt = wxString(extension).Upper();
wxString file = wxFindFirstFile( path + "/*" );
while ( !file.empty() )
{
if ( upperExt.empty() || file.Upper().EndsWith(upperExt) )
results.push_back(file);
file = wxFindNextFile();
}
return results;
return true;
}
bool NativeFileSystem::CopyFile(const gd::String & file, const gd::String & destination)
{
if (file == destination) return true; //No copy needed
gd::String NativeFileSystem::GetTempDir() { return wxFileName::GetTempDir(); }
wxLogNull noLogPlease;
return wxCopyFile( file, destination, true );
}
bool NativeFileSystem::CopyDir(const gd::String & source, const gd::String & destination)
{
wxString sFrom = source.ToWxString();
wxString sTo = destination.ToWxString();
//As seen on https://forums.wxwidgets.org/viewtopic.php?t=2080
if (sFrom[sFrom.Len() - 1] != '\\' && sFrom[sFrom.Len() - 1] != '/') sFrom += wxFILE_SEP_PATH;
if (sTo[sTo.Len() - 1] != '\\' && sTo[sTo.Len() - 1] != '/') sTo += wxFILE_SEP_PATH;
if (!::wxDirExists(sFrom)) {
return false;
}
if (!wxDirExists(sTo)) {
if (!wxFileName::Mkdir(sTo, 0777, wxPATH_MKDIR_FULL)) {
return false;
}
}
wxDir fDir(sFrom);
wxString sNext = wxEmptyString;
bool bIsFile = fDir.GetFirst(&sNext);
while (bIsFile) {
const wxString sFileFrom = sFrom + sNext;
const wxString sFileTo = sTo + sNext;
if (::wxDirExists(sFileFrom)) {
CopyDir(sFileFrom, sFileTo);
}
else {
if (!::wxFileExists(sFileTo)) {
if (!::wxCopyFile(sFileFrom, sFileTo)) {
return false;
}
}
}
bIsFile = fDir.GetNext(&sNext);
}
bool NativeFileSystem::WriteToFile(const gd::String &filename,
const gd::String &content) {
gd::FileStream file(filename, std::ios_base::out);
if (file.is_open()) {
file << content.ToUTF8();
file.close();
return true;
}
return false;
}
NativeFileSystem & NativeFileSystem::Get()
{
if ( !singleton ) singleton = new NativeFileSystem;
return *singleton;
gd::String NativeFileSystem::ReadFile(const gd::String &file) {
gd::FileStream t(file, std::ios_base::in);
std::stringstream buffer;
buffer << t.rdbuf();
return gd::String::FromUTF8(buffer.str());
}
void NativeFileSystem::DestroySingleton()
{
if ( singleton )
{
delete singleton;
singleton = NULL;
std::vector<gd::String> NativeFileSystem::ReadDir(const gd::String &path,
const gd::String &extension) {
std::vector<gd::String> results;
wxString upperExt = wxString(extension).Upper();
wxString file = wxFindFirstFile(path + "/*");
while (!file.empty()) {
if (upperExt.empty() || file.Upper().EndsWith(upperExt))
results.push_back(file);
file = wxFindNextFile();
}
return results;
}
bool NativeFileSystem::CopyFile(const gd::String &file,
const gd::String &destination) {
if (file == destination) return true; // No copy needed
wxLogNull noLogPlease;
return wxCopyFile(file, destination, true);
}
bool NativeFileSystem::CopyDir(const gd::String &source,
const gd::String &destination) {
wxString sFrom = source.ToWxString();
wxString sTo = destination.ToWxString();
// As seen on https://forums.wxwidgets.org/viewtopic.php?t=2080
if (sFrom[sFrom.Len() - 1] != '\\' && sFrom[sFrom.Len() - 1] != '/')
sFrom += wxFILE_SEP_PATH;
if (sTo[sTo.Len() - 1] != '\\' && sTo[sTo.Len() - 1] != '/')
sTo += wxFILE_SEP_PATH;
if (!::wxDirExists(sFrom)) {
return false;
}
if (!wxDirExists(sTo)) {
if (!wxFileName::Mkdir(sTo, 0777, wxPATH_MKDIR_FULL)) {
return false;
}
}
wxDir fDir(sFrom);
wxString sNext = wxEmptyString;
bool bIsFile = fDir.GetFirst(&sNext);
while (bIsFile) {
const wxString sFileFrom = sFrom + sNext;
const wxString sFileTo = sTo + sNext;
if (::wxDirExists(sFileFrom)) {
CopyDir(sFileFrom, sFileTo);
} else {
if (!::wxFileExists(sFileTo)) {
if (!::wxCopyFile(sFileFrom, sFileTo)) {
return false;
}
}
}
bIsFile = fDir.GetNext(&sNext);
}
return true;
}
NativeFileSystem::~NativeFileSystem()
{
NativeFileSystem &NativeFileSystem::Get() {
if (!singleton) singleton = new NativeFileSystem;
return *singleton;
}
void NativeFileSystem::DestroySingleton() {
if (singleton) {
delete singleton;
singleton = NULL;
}
}
NativeFileSystem::~NativeFileSystem() {}
#endif
}
} // namespace gd

View File

@@ -1,7 +1,7 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_ABSTRACTFILESYSTEM
@@ -9,10 +9,9 @@
#include <vector>
#include "GDCore/String.h"
#undef CopyFile //Remove a Windows macro
#undef CopyFile // Remove a Windows macro
namespace gd
{
namespace gd {
/**
* \brief AbstractFileSystem is used to do classical file manipulation
@@ -21,113 +20,117 @@ namespace gd
* \see gd::NativeFileSystem
* \ingroup IDE
*/
class GD_CORE_API AbstractFileSystem
{
public:
class GD_CORE_API AbstractFileSystem {
public:
virtual ~AbstractFileSystem();
virtual ~AbstractFileSystem();
/**
* \brief Make sure that only slash are used as a path separator:
* all backslashs are converted to forward slashs.
*
* Use this method when you get a filename from a file dialog for example:
* it ensures that filenames will be usable from Windows to Linux (as long
* as the filename is not an absolute path).
*
* @param filename The filename to normalize
* @return The normalized filename.
*/
static gd::String NormalizeSeparator(gd::String filename);
/**
* \brief Make sure that only slash are used as a path separator:
* all backslashs are converted to forward slashs.
*
* Use this method when you get a filename from a file dialog for example:
* it ensures that filenames will be usable from Windows to Linux (as long
* as the filename is not an absolute path).
*
* @param filename The filename to normalize
* @return The normalized filename.
*/
static gd::String NormalizeSeparator(gd::String filename);
/**
* \brief Create the specified directory.
* \param path The directory to create.
*/
virtual void MkDir(const gd::String& path) = 0;
/**
* \brief Create the specified directory.
* \param path The directory to create.
*/
virtual void MkDir(const gd::String & path) = 0;
/**
* \brief Return true if the specified directory exists
*/
virtual bool DirExists(const gd::String& path) = 0;
/**
* \brief Return true if the specified directory exists
*/
virtual bool DirExists(const gd::String & path) = 0;
/**
* \brief Return true if the specified file exists
*/
virtual bool FileExists(const gd::String& path) = 0;
/**
* \brief Return true if the specified file exists
*/
virtual bool FileExists(const gd::String & path) = 0;
/**
* \brief Clear the directory given as parameter, removing all the files.
*/
virtual bool ClearDir(const gd::String& directory) = 0;
/**
* \brief Clear the directory given as parameter, removing all the files.
*/
virtual bool ClearDir(const gd::String & directory) = 0;
/**
* \brief Get a directory suitable for temporary files.
*/
virtual gd::String GetTempDir() = 0;
/**
* \brief Get a directory suitable for temporary files.
*/
virtual gd::String GetTempDir() = 0;
/**
* \brief Extract the name of the file (with its extension) from a path.
*/
virtual gd::String FileNameFrom(const gd::String& file) = 0;
/**
* \brief Extract the name of the file (with its extension) from a path.
*/
virtual gd::String FileNameFrom(const gd::String & file) = 0;
/**
* \brief Extract the path without the filename.
*/
virtual gd::String DirNameFrom(const gd::String& file) = 0;
/**
* \brief Extract the path without the filename.
*/
virtual gd::String DirNameFrom(const gd::String & file) = 0;
/**
* \brief Change the filename so that it is absolute, using the base directory
* passed as parameter. \return true if the operation succeeded.
*/
virtual bool MakeAbsolute(gd::String& filename,
const gd::String& baseDirectory) = 0;
/**
* \brief Change the filename so that it is absolute, using the base directory passed as parameter.
* \return true if the operation succeeded.
*/
virtual bool MakeAbsolute(gd::String & filename, const gd::String & baseDirectory) = 0;
/**
* \brief Return true if the filename is absolute
*/
virtual bool IsAbsolute(const gd::String& filename) = 0;
/**
* \brief Return true if the filename is absolute
*/
virtual bool IsAbsolute(const gd::String & filename) = 0;
/**
* \brief Change the filename so that it is relative to the base directory
* passed as parameter. \return true if the operation succeeded.
*/
virtual bool MakeRelative(gd::String& filename,
const gd::String& baseDirectory) = 0;
/**
* \brief Change the filename so that it is relative to the base directory passed as parameter.
* \return true if the operation succeeded.
*/
virtual bool MakeRelative(gd::String & filename, const gd::String & baseDirectory) = 0;
/**
* \brief Copy a file
* \return true if the operation succeeded.
*/
virtual bool CopyFile(const gd::String& file,
const gd::String& destination) = 0;
/**
* \brief Copy a file
* \return true if the operation succeeded.
*/
virtual bool CopyFile(const gd::String & file, const gd::String & destination) = 0;
/**
* \brief Copy a whole directory
* \return true if the operation succeeded.
*/
virtual bool CopyDir(const gd::String & source, const gd::String & destination) = 0;
/**
* \brief Copy a whole directory
* \return true if the operation succeeded.
*/
virtual bool CopyDir(const gd::String& source,
const gd::String& destination) = 0;
/**
* \brief Write the content of a string to a file.
* \return true if the operation succeeded.
*/
virtual bool WriteToFile(const gd::String & file, const gd::String & content) = 0;
/**
* \brief Write the content of a string to a file.
* \return true if the operation succeeded.
*/
virtual bool WriteToFile(const gd::String& file,
const gd::String& content) = 0;
/**
* \brief Read the content of a file.
* \return The content of the file.
*/
virtual gd::String ReadFile(const gd::String & file) = 0;
/**
* \brief Read the content of a file.
* \return The content of the file.
*/
virtual gd::String ReadFile(const gd::String& file) = 0;
/**
* \brief Return a vector containing the files in the specified path
*
* \param path The path to read
* \param extension If specified, only file finishing with this extension will be returned
* \return A vector with all the matched files
*/
virtual std::vector<gd::String> ReadDir(const gd::String & path, const gd::String & extension = "") = 0;
/**
* \brief Return a vector containing the files in the specified path
*
* \param path The path to read
* \param extension If specified, only file finishing with this extension will
* be returned \return A vector with all the matched files
*/
virtual std::vector<gd::String> ReadDir(const gd::String& path,
const gd::String& extension = "") = 0;
protected:
AbstractFileSystem() {};
protected:
AbstractFileSystem(){};
};
#if !defined(GD_NO_WX_GUI)
@@ -137,44 +140,46 @@ protected:
*
* \ingroup IDE
*/
class GD_CORE_API NativeFileSystem : public AbstractFileSystem
{
public:
/**
* \brief Get the NativeFileSystem instance.
*/
static NativeFileSystem & Get();
class GD_CORE_API NativeFileSystem : public AbstractFileSystem {
public:
/**
* \brief Get the NativeFileSystem instance.
*/
static NativeFileSystem& Get();
virtual void MkDir(const gd::String & path);
virtual bool DirExists(const gd::String & path);
virtual bool FileExists(const gd::String & path);
virtual gd::String FileNameFrom(const gd::String & file);
virtual gd::String DirNameFrom(const gd::String & file);
virtual bool MakeAbsolute(gd::String & filename, const gd::String & baseDirectory);
virtual bool MakeRelative(gd::String & filename, const gd::String & baseDirectory);
virtual bool IsAbsolute(const gd::String & filename);
virtual bool CopyFile(const gd::String & file, const gd::String & destination);
virtual bool CopyDir(const gd::String & source, const gd::String & destination);
virtual bool ClearDir(const gd::String & directory);
virtual bool WriteToFile(const gd::String & file, const gd::String & content);
virtual gd::String ReadFile(const gd::String & file);
virtual gd::String GetTempDir();
virtual std::vector<gd::String> ReadDir(const gd::String & path, const gd::String & extension = "");
virtual void MkDir(const gd::String& path);
virtual bool DirExists(const gd::String& path);
virtual bool FileExists(const gd::String& path);
virtual gd::String FileNameFrom(const gd::String& file);
virtual gd::String DirNameFrom(const gd::String& file);
virtual bool MakeAbsolute(gd::String& filename,
const gd::String& baseDirectory);
virtual bool MakeRelative(gd::String& filename,
const gd::String& baseDirectory);
virtual bool IsAbsolute(const gd::String& filename);
virtual bool CopyFile(const gd::String& file, const gd::String& destination);
virtual bool CopyDir(const gd::String& source, const gd::String& destination);
virtual bool ClearDir(const gd::String& directory);
virtual bool WriteToFile(const gd::String& file, const gd::String& content);
virtual gd::String ReadFile(const gd::String& file);
virtual gd::String GetTempDir();
virtual std::vector<gd::String> ReadDir(const gd::String& path,
const gd::String& extension = "");
/**
* \brief Destroy the singleton.
* \note You do not need usually to call this method.
**/
static void DestroySingleton();
/**
* \brief Destroy the singleton.
* \note You do not need usually to call this method.
**/
static void DestroySingleton();
private:
NativeFileSystem() {};
virtual ~NativeFileSystem();
private:
NativeFileSystem(){};
virtual ~NativeFileSystem();
static NativeFileSystem * singleton;
static NativeFileSystem* singleton;
};
#endif
}
} // namespace gd
#endif // GDCORE_ABSTRACTFILESYSTEM
#endif // GDCORE_ABSTRACTFILESYSTEM

View File

@@ -1,21 +1,21 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "GDCore/CommonTools.h"
#include "GDCore/Tools/VersionWrapper.h"
#include "GDCore/Tools/Locale/LocaleManager.h"
#include "AnalyticsSender.h"
#include <SFML/Network.hpp>
#include <iostream>
#include "GDCore/CommonTools.h"
#include "GDCore/Serialization/Serializer.h"
#include "GDCore/Serialization/SerializerElement.h"
#include <SFML/Network.hpp>
#include "GDCore/String.h"
#include <iostream>
#include "GDCore/Tools/Locale/LocaleManager.h"
#include "GDCore/Tools/VersionWrapper.h"
#if !defined(GD_NO_WX_GUI)
#include <wx/config.h>
#include <wx/filename.h>
#include <wx/filefn.h>
#include <wx/filename.h>
#include <wx/utils.h>
#endif
@@ -23,80 +23,80 @@ namespace gd {
AnalyticsSender *AnalyticsSender::_singleton = NULL;
void AnalyticsSender::SendProgramOpening()
{
#if !defined(GD_NO_WX_GUI)
SerializerElement data;
SendData("program_opening", data);
#endif
void AnalyticsSender::SendProgramOpening() {
#if !defined(GD_NO_WX_GUI)
SerializerElement data;
SendData("program_opening", data);
#endif
}
void AnalyticsSender::SendNewGameCreated(gd::String platformName, gd::String templateName)
{
#if !defined(GD_NO_WX_GUI)
wxFileName templateFile = wxFileName::FileName(templateName);
templateFile.MakeRelativeTo();
void AnalyticsSender::SendNewGameCreated(gd::String platformName,
gd::String templateName) {
#if !defined(GD_NO_WX_GUI)
wxFileName templateFile = wxFileName::FileName(templateName);
templateFile.MakeRelativeTo();
SerializerElement data;
data.SetAttribute("platform", platformName);
data.SetAttribute("templateName", gd::String(templateFile.GetFullPath(wxPATH_UNIX)));
SendData("new_game_creation", data);
#endif
SerializerElement data;
data.SetAttribute("platform", platformName);
data.SetAttribute("templateName",
gd::String(templateFile.GetFullPath(wxPATH_UNIX)));
SendData("new_game_creation", data);
#endif
}
void AnalyticsSender::SendData(gd::String collection, SerializerElement & data)
{
#if !defined(GD_NO_WX_GUI)
//Check if we are allowed to send these data.
bool sendInfo;
wxConfigBase::Get()->Read("/Startup/SendInfo", &sendInfo, true);
if (!sendInfo) return;
void AnalyticsSender::SendData(gd::String collection, SerializerElement &data) {
#if !defined(GD_NO_WX_GUI)
// Check if we are allowed to send these data.
bool sendInfo;
wxConfigBase::Get()->Read("/Startup/SendInfo", &sendInfo, true);
if (!sendInfo) return;
data.SetAttribute("gdVersion", VersionWrapper::FullString());
data.SetAttribute("os", gd::String(wxGetOsDescription()));
data.SetAttribute("lang",
gd::String(wxLocale::GetLanguageCanonicalName(LocaleManager::Get()->GetLanguage())));
if (wxConfig::Get())
data.SetAttribute("openingCount", wxConfig::Get()->ReadDouble("Startup/OpeningCount", 0));
data.SetAttribute("gdVersion", VersionWrapper::FullString());
data.SetAttribute("os", gd::String(wxGetOsDescription()));
data.SetAttribute("lang",
gd::String(wxLocale::GetLanguageCanonicalName(
LocaleManager::Get()->GetLanguage())));
if (wxConfig::Get())
data.SetAttribute("openingCount",
wxConfig::Get()->ReadDouble("Startup/OpeningCount", 0));
// Create request
std::cout << "Sending analytics data..."; std::cout.flush();
sf::Http Http;
Http.setHost("http://api.keen.io");
sf::Http::Request request;
request.setMethod(sf::Http::Request::Post);
request.setField("Content-Type", "application/json");
request.setUri("/3.0/projects/"+projectId.ToLocale()+"/events/"+collection.ToLocale()+"?api_key="+writeKey.ToLocale());
request.setBody(Serializer::ToJSON(data).ToSfString());
// Create request
std::cout << "Sending analytics data...";
std::cout.flush();
sf::Http Http;
Http.setHost("http://api.keen.io");
sf::Http::Request request;
request.setMethod(sf::Http::Request::Post);
request.setField("Content-Type", "application/json");
request.setUri("/3.0/projects/" + projectId.ToLocale() + "/events/" +
collection.ToLocale() + "?api_key=" + writeKey.ToLocale());
request.setBody(Serializer::ToJSON(data).ToSfString());
// Send the request
sf::Http::Response response = Http.sendRequest(request, sf::seconds(2));
std::cout << "done (" << response.getStatus() << ")" << std::endl;
#endif
// Send the request
sf::Http::Response response = Http.sendRequest(request, sf::seconds(2));
std::cout << "done (" << response.getStatus() << ")" << std::endl;
#endif
}
AnalyticsSender::AnalyticsSender() :
projectId("54722730709a3932d94d0d5c"),
writeKey("fad7129dd241c361e4d4a0390b0dcf6be6eb914ba73e395283115095c9648f912ba84fcc292cc91759cf1970ccac0bc7c29f8207b34b738dbb8a9bde4a8211df20a6f49d3b2a48b598fb02fd33e1d64c0102088ebf093079714ed1cfe8335760c63c6c18a3be9d16ce904f83cec25d4f")
{
AnalyticsSender::AnalyticsSender()
: projectId("54722730709a3932d94d0d5c"),
writeKey(
"fad7129dd241c361e4d4a0390b0dcf6be6eb914ba73e395283115095c9648f912ba8"
"4fcc292cc91759cf1970ccac0bc7c29f8207b34b738dbb8a9bde4a8211df20a6f49d"
"3b2a48b598fb02fd33e1d64c0102088ebf093079714ed1cfe8335760c63c6c18a3be"
"9d16ce904f83cec25d4f") {}
AnalyticsSender *AnalyticsSender::Get() {
if (NULL == _singleton) _singleton = new AnalyticsSender;
return (static_cast<AnalyticsSender *>(_singleton));
}
AnalyticsSender * AnalyticsSender::Get()
{
if ( NULL == _singleton )
_singleton = new AnalyticsSender;
return ( static_cast<AnalyticsSender*>( _singleton ) );
void AnalyticsSender::DestroySingleton() {
if (NULL != _singleton) {
delete _singleton;
_singleton = NULL;
}
}
void AnalyticsSender::DestroySingleton()
{
if ( NULL != _singleton )
{
delete _singleton;
_singleton = NULL;
}
}
}
} // namespace gd

View File

@@ -1,35 +1,35 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "GDCore/String.h"
namespace gd { class SerializerElement; }
namespace gd {
class SerializerElement;
}
namespace gd
{
namespace gd {
/**
* \brief Used to send anonymous usage data to do
* analytics on how is used GDevelop.
*/
class GD_CORE_API AnalyticsSender
{
public:
void SendProgramOpening();
void SendNewGameCreated(gd::String platformName, gd::String templateName);
class GD_CORE_API AnalyticsSender {
public:
void SendProgramOpening();
void SendNewGameCreated(gd::String platformName, gd::String templateName);
static AnalyticsSender *Get();
static void DestroySingleton();
static AnalyticsSender *Get();
static void DestroySingleton();
private:
AnalyticsSender();
virtual ~AnalyticsSender() {};
void SendData(gd::String collection, gd::SerializerElement & data);
private:
AnalyticsSender();
virtual ~AnalyticsSender(){};
void SendData(gd::String collection, gd::SerializerElement &data);
const gd::String projectId;
const gd::String writeKey;
static AnalyticsSender *_singleton;
const gd::String projectId;
const gd::String writeKey;
static AnalyticsSender *_singleton;
};
}
} // namespace gd

View File

@@ -1,157 +1,132 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include <memory>
#include "GDCore/IDE/Clipboard.h"
#include "GDCore/Project/Layout.h"
#include "GDCore/Project/ExternalEvents.h"
#include "GDCore/Project/ExternalLayout.h"
#include "GDCore/Project/Object.h"
#include "GDCore/Project/InitialInstance.h"
#include <memory>
#include "GDCore/Events/Event.h"
#include "GDCore/Events/Instruction.h"
#include "GDCore/Project/ExternalEvents.h"
#include "GDCore/Project/ExternalLayout.h"
#include "GDCore/Project/InitialInstance.h"
#include "GDCore/Project/Layout.h"
#include "GDCore/Project/Object.h"
//Undefining an annoying macro changing GetObject in GetObjectA
// Undefining an annoying macro changing GetObject in GetObjectA
#undef GetObject
namespace gd
{
namespace gd {
Clipboard::Clipboard() :
objectCopied(nullptr),
hasObject(false),
hasEvents(false),
hasInstructions(false),
instructionsAreConditions(true),
externalEventsCopied(nullptr),
hasExternalEvents(false),
externalLayoutCopied(nullptr),
hasExternalLayout(false),
layoutCopied(nullptr),
hasLayout(false),
hasObjectGroup(false),
hasInstances(false)
{
//ctor
Clipboard::Clipboard()
: objectCopied(nullptr),
hasObject(false),
hasEvents(false),
hasInstructions(false),
instructionsAreConditions(true),
externalEventsCopied(nullptr),
hasExternalEvents(false),
externalLayoutCopied(nullptr),
hasExternalLayout(false),
layoutCopied(nullptr),
hasLayout(false),
hasObjectGroup(false),
hasInstances(false) {
// ctor
}
Clipboard::~Clipboard()
{
if ( layoutCopied != NULL ) delete layoutCopied;
Clipboard::~Clipboard() {
if (layoutCopied != NULL) delete layoutCopied;
}
Clipboard * Clipboard::Get()
{
if ( NULL == singleton )
singleton = new Clipboard;
Clipboard* Clipboard::Get() {
if (NULL == singleton) singleton = new Clipboard;
return singleton;
return singleton;
}
void Clipboard::DestroySingleton()
{
if ( NULL != singleton )
{
delete singleton;
singleton = NULL;
}
void Clipboard::DestroySingleton() {
if (NULL != singleton) {
delete singleton;
singleton = NULL;
}
}
void Clipboard::SetObject( const gd::Object& object )
{
objectCopied = object.Clone();
void Clipboard::SetObject(const gd::Object& object) {
objectCopied = object.Clone();
hasObject = true;
hasObject = true;
}
std::unique_ptr<gd::Object> Clipboard::GetObject()
{
return objectCopied->Clone();
std::unique_ptr<gd::Object> Clipboard::GetObject() {
return objectCopied->Clone();
}
void Clipboard::SetEvents( const gd::EventsList & events )
{
eventsCopied = events;
hasEvents = true;
void Clipboard::SetEvents(const gd::EventsList& events) {
eventsCopied = events;
hasEvents = true;
}
gd::EventsList Clipboard::GetEvents()
{
return eventsCopied;
gd::EventsList Clipboard::GetEvents() { return eventsCopied; }
void Clipboard::SetLayout(const gd::Layout* layout) {
if (layout == NULL) return;
layoutCopied = layout->Clone();
hasLayout = true;
}
void Clipboard::SetLayout( const gd::Layout * layout )
{
if ( layout == NULL ) return;
layoutCopied = layout->Clone();
hasLayout = true;
gd::Layout* Clipboard::GetLayout() {
if (layoutCopied == NULL) return NULL;
return layoutCopied->Clone();
}
gd::Layout * Clipboard::GetLayout()
{
if ( layoutCopied == NULL ) return NULL;
return layoutCopied->Clone();
void Clipboard::SetExternalEvents(const gd::ExternalEvents& events) {
if (externalEventsCopied) delete externalEventsCopied;
externalEventsCopied = new gd::ExternalEvents(events);
hasExternalEvents = true;
}
void Clipboard::SetExternalEvents( const gd::ExternalEvents & events )
{
if (externalEventsCopied) delete externalEventsCopied;
externalEventsCopied = new gd::ExternalEvents(events);
hasExternalEvents = true;
gd::ExternalEvents Clipboard::GetExternalEvents() {
return *externalEventsCopied;
}
gd::ExternalEvents Clipboard::GetExternalEvents()
{
return *externalEventsCopied;
void Clipboard::SetExternalLayout(const gd::ExternalLayout& layout) {
if (externalLayoutCopied) delete externalLayoutCopied;
externalLayoutCopied = new gd::ExternalLayout(layout);
hasExternalLayout = true;
}
void Clipboard::SetExternalLayout( const gd::ExternalLayout & layout )
{
if (externalLayoutCopied) delete externalLayoutCopied;
externalLayoutCopied = new gd::ExternalLayout(layout);
hasExternalLayout = true;
gd::ExternalLayout Clipboard::GetExternalLayout() {
return *externalLayoutCopied;
}
gd::ExternalLayout Clipboard::GetExternalLayout()
{
return *externalLayoutCopied;
void Clipboard::SetConditions(const gd::InstructionsList& conditions) {
hasInstructions = true;
instructionsAreConditions = true;
instructionsCopied = conditions;
}
void Clipboard::SetConditions( const gd::InstructionsList & conditions )
{
hasInstructions = true;
instructionsAreConditions = true;
instructionsCopied = conditions;
void Clipboard::SetActions(const gd::InstructionsList& actions) {
hasInstructions = true;
instructionsAreConditions = false;
instructionsCopied = actions;
}
void Clipboard::SetActions( const gd::InstructionsList & actions )
{
hasInstructions = true;
instructionsAreConditions = false;
instructionsCopied = actions;
void Clipboard::SetObjectGroup(const gd::ObjectGroup& group) {
objectGroupCopied = group;
hasObjectGroup = true;
}
void Clipboard::SetObjectGroup( const gd::ObjectGroup & group )
{
objectGroupCopied = group;
hasObjectGroup = true;
gd::ObjectGroup Clipboard::GetObjectGroup() { return objectGroupCopied; }
void Clipboard::SetInstances(
std::vector<std::shared_ptr<gd::InitialInstance> > instances) {
instancesCopied = instances;
hasInstances = true;
}
gd::ObjectGroup Clipboard::GetObjectGroup()
{
return objectGroupCopied;
}
Clipboard* Clipboard::singleton = NULL;
void Clipboard::SetInstances( std::vector < std::shared_ptr<gd::InitialInstance> > instances )
{
instancesCopied = instances;
hasInstances = true;
}
Clipboard * Clipboard::singleton = NULL;
}
} // namespace gd

View File

@@ -1,115 +1,129 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef CLIPBOARD_H
#define CLIPBOARD_H
namespace gd { class Layout; }
namespace gd { class ExternalEvents; }
namespace gd { class ExternalLayout; }
namespace gd {
class Layout;
}
namespace gd {
class ExternalEvents;
}
namespace gd {
class ExternalLayout;
}
#include "GDCore/Events/Event.h"
#include "GDCore/Events/EventsList.h"
#include "GDCore/Events/Instruction.h"
#include "GDCore/Project/ObjectGroup.h"
#include "GDCore/Project/Object.h"
#include "GDCore/Project/InitialInstance.h"
#undef GetObject //Undefining an annoying macro changing GetObject in GetObjectA or GetObjectW
#include "GDCore/Project/Object.h"
#include "GDCore/Project/ObjectGroup.h"
#undef GetObject // Undefining an annoying macro changing GetObject in
// GetObjectA or GetObjectW
namespace gd
{
namespace gd {
/**
* \brief Singleton class which can be used by the IDE and the editors to access to a (fake) clipboard.
* \brief Singleton class which can be used by the IDE and the editors to access
* to a (fake) clipboard.
*
* All objects stored in this clipboard are stored by copy. Getter returns a copy of the stored objects,
* and can only be called if "Has" method returns true (otherwise, behavior is undefined).
* All objects stored in this clipboard are stored by copy. Getter returns a
* copy of the stored objects, and can only be called if "Has" method returns
* true (otherwise, behavior is undefined).
*/
class GD_CORE_API Clipboard
{
public:
/**
* \brief Return the unique clipboard instance.
*/
static Clipboard * Get();
class GD_CORE_API Clipboard {
public:
/**
* \brief Return the unique clipboard instance.
*/
static Clipboard* Get();
/**
* @brief Destroy the unique clipboard instance.
*
* No need to call this method except at the end of the application.
*/
static void DestroySingleton();
/**
* @brief Destroy the unique clipboard instance.
*
* No need to call this method except at the end of the application.
*/
static void DestroySingleton();
void SetObject( const gd::Object& object );
std::unique_ptr<gd::Object> GetObject();
bool HasObject() { return hasObject; };
void ForgetObject() { hasObject = false; };
void SetObject(const gd::Object& object);
std::unique_ptr<gd::Object> GetObject();
bool HasObject() { return hasObject; };
void ForgetObject() { hasObject = false; };
void SetEvents( const gd::EventsList & event );
gd::EventsList GetEvents();
bool HasEvents() { return hasEvents; };
void SetEvents(const gd::EventsList& event);
gd::EventsList GetEvents();
bool HasEvents() { return hasEvents; };
void SetLayout( const gd::Layout * layout );
gd::Layout * GetLayout();
bool HasLayout() { return hasLayout; };
void SetLayout(const gd::Layout* layout);
gd::Layout* GetLayout();
bool HasLayout() { return hasLayout; };
void SetExternalEvents( const gd::ExternalEvents & events );
gd::ExternalEvents GetExternalEvents();
bool HasExternalEvents() { return hasExternalEvents; };
void SetExternalEvents(const gd::ExternalEvents& events);
gd::ExternalEvents GetExternalEvents();
bool HasExternalEvents() { return hasExternalEvents; };
void SetExternalLayout( const gd::ExternalLayout & layout );
gd::ExternalLayout GetExternalLayout();
bool HasExternalLayout() { return hasExternalLayout; };
void SetExternalLayout(const gd::ExternalLayout& layout);
gd::ExternalLayout GetExternalLayout();
bool HasExternalLayout() { return hasExternalLayout; };
void SetConditions( const gd::InstructionsList & conditions );
void SetActions( const gd::InstructionsList & actions );
void SetConditions(const gd::InstructionsList& conditions);
void SetActions(const gd::InstructionsList& actions);
bool HasCondition() { return hasInstructions && instructionsAreConditions; };
bool HasAction() { return hasInstructions && !instructionsAreConditions; };
gd::InstructionsList GetInstructions() const { return instructionsCopied; };
bool HasCondition() { return hasInstructions && instructionsAreConditions; };
bool HasAction() { return hasInstructions && !instructionsAreConditions; };
gd::InstructionsList GetInstructions() const { return instructionsCopied; };
void SetObjectGroup( const gd::ObjectGroup & group );
gd::ObjectGroup GetObjectGroup();
bool HasObjectGroup() { return hasObjectGroup; };
void ForgetObjectGroup() { hasObjectGroup = false; };
void SetObjectGroup(const gd::ObjectGroup& group);
gd::ObjectGroup GetObjectGroup();
bool HasObjectGroup() { return hasObjectGroup; };
void ForgetObjectGroup() { hasObjectGroup = false; };
void SetInstances( std::vector < std::shared_ptr<InitialInstance> > instances );
std::vector < std::shared_ptr<InitialInstance> > Gets() { return instancesCopied; };
bool HasInstances() { return hasInstances; };
void SetInstances(std::vector<std::shared_ptr<InitialInstance> > instances);
std::vector<std::shared_ptr<InitialInstance> > Gets() {
return instancesCopied;
};
bool HasInstances() { return hasInstances; };
private:
Clipboard();
virtual ~Clipboard();
private:
Clipboard();
virtual ~Clipboard();
std::unique_ptr<gd::Object> objectCopied;
bool hasObject;
std::unique_ptr<gd::Object> objectCopied;
bool hasObject;
gd::EventsList eventsCopied;
bool hasEvents;
gd::EventsList eventsCopied;
bool hasEvents;
gd::InstructionsList instructionsCopied;
bool hasInstructions;
bool instructionsAreConditions;
gd::InstructionsList instructionsCopied;
bool hasInstructions;
bool instructionsAreConditions;
gd::ExternalEvents * externalEventsCopied; ///< Stored using a pointer to avoid including the full header file.
bool hasExternalEvents;
gd::ExternalEvents*
externalEventsCopied; ///< Stored using a pointer to avoid including the
///< full header file.
bool hasExternalEvents;
gd::ExternalLayout * externalLayoutCopied; ///< Stored using a pointer to avoid including the full header file.
bool hasExternalLayout;
gd::ExternalLayout*
externalLayoutCopied; ///< Stored using a pointer to avoid including the
///< full header file.
bool hasExternalLayout;
gd::Layout * layoutCopied; ///< Stored using a pointer to avoid including the full header file.
bool hasLayout;
gd::Layout* layoutCopied; ///< Stored using a pointer to avoid including the
///< full header file.
bool hasLayout;
gd::ObjectGroup objectGroupCopied;
bool hasObjectGroup;
gd::ObjectGroup objectGroupCopied;
bool hasObjectGroup;
std::vector < std::shared_ptr<gd::InitialInstance> > instancesCopied;
bool hasInstances;
std::vector<std::shared_ptr<gd::InitialInstance> > instancesCopied;
bool hasInstances;
static Clipboard *singleton;
static Clipboard* singleton;
};
}
} // namespace gd
#endif // CLIPBOARD_H
#endif // CLIPBOARD_H

View File

@@ -1,154 +1,163 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#if defined(GD_IDE_ONLY)
#include "DependenciesAnalyzer.h"
#include <algorithm>
#include "GDCore/Events/EventsList.h"
#include "GDCore/Events/Builtin/LinkEvent.h"
#include "GDCore/Events/Event.h"
#include "GDCore/Events/EventsList.h"
#include "GDCore/Project/ExternalEvents.h"
#include "GDCore/Project/Layout.h"
#include "GDCore/Project/Project.h"
#include "GDCore/Project/SourceFile.h"
#include "GDCore/Events/Builtin/LinkEvent.h"
#include "DependenciesAnalyzer.h"
DependenciesAnalyzer::DependenciesAnalyzer(gd::Project & project_, gd::Layout & layout_) :
project(project_),
layout(&layout_),
externalEvents(NULL)
{
parentScenes.push_back(layout->GetName());
DependenciesAnalyzer::DependenciesAnalyzer(gd::Project& project_,
gd::Layout& layout_)
: project(project_), layout(&layout_), externalEvents(NULL) {
parentScenes.push_back(layout->GetName());
}
DependenciesAnalyzer::DependenciesAnalyzer(gd::Project & project_, gd::ExternalEvents & externalEvents_) :
project(project_),
layout(NULL),
externalEvents(&externalEvents_)
{
parentExternalEvents.push_back(externalEvents->GetName());
DependenciesAnalyzer::DependenciesAnalyzer(gd::Project& project_,
gd::ExternalEvents& externalEvents_)
: project(project_), layout(NULL), externalEvents(&externalEvents_) {
parentExternalEvents.push_back(externalEvents->GetName());
}
DependenciesAnalyzer::DependenciesAnalyzer(const DependenciesAnalyzer & parent) :
parentScenes(parent.parentScenes),
parentExternalEvents(parent.parentExternalEvents),
project(parent.project),
layout(NULL),
externalEvents(NULL)
{
DependenciesAnalyzer::DependenciesAnalyzer(const DependenciesAnalyzer& parent)
: parentScenes(parent.parentScenes),
parentExternalEvents(parent.parentExternalEvents),
project(parent.project),
layout(NULL),
externalEvents(NULL) {}
bool DependenciesAnalyzer::Analyze() {
if (layout)
return Analyze(layout->GetEvents(), true);
else if (externalEvents)
return Analyze(externalEvents->GetEvents(), true);
std::cout << "ERROR: DependenciesAnalyzer called without any layout or "
"external events.";
return false;
}
bool DependenciesAnalyzer::Analyze()
{
if (layout)
return Analyze(layout->GetEvents(), true);
else if (externalEvents)
return Analyze(externalEvents->GetEvents(), true);
DependenciesAnalyzer::~DependenciesAnalyzer() {}
std::cout << "ERROR: DependenciesAnalyzer called without any layout or external events.";
return false;
}
bool DependenciesAnalyzer::Analyze(gd::EventsList& events, bool isOnTopLevel) {
for (unsigned int i = 0; i < events.size(); ++i) {
gd::LinkEvent* linkEvent = dynamic_cast<gd::LinkEvent*>(&events[i]);
if (linkEvent) {
DependenciesAnalyzer analyzer(*this);
DependenciesAnalyzer::~DependenciesAnalyzer()
{
}
gd::String linked = linkEvent->GetTarget();
if (project.HasExternalEventsNamed(linked)) {
if (std::find(parentExternalEvents.begin(),
parentExternalEvents.end(),
linked) != parentExternalEvents.end())
return false; // Circular dependency!
bool DependenciesAnalyzer::Analyze(gd::EventsList & events, bool isOnTopLevel)
{
for (unsigned int i = 0;i<events.size();++i)
{
gd::LinkEvent* linkEvent = dynamic_cast<gd::LinkEvent*>(&events[i]);
if (linkEvent)
{
DependenciesAnalyzer analyzer(*this);
externalEventsDependencies.insert(
linked); // There is a direct dependency
if (!isOnTopLevel) notTopLevelExternalEventsDependencies.insert(linked);
analyzer.AddParentExternalEvents(linked);
if (!analyzer.Analyze(project.GetExternalEvents(linked).GetEvents(),
isOnTopLevel))
return false;
gd::String linked = linkEvent->GetTarget();
if ( project.HasExternalEventsNamed(linked) )
{
if ( std::find(parentExternalEvents.begin(), parentExternalEvents.end(), linked) != parentExternalEvents.end() )
return false; //Circular dependency!
} else if (project.HasLayoutNamed(linked)) {
if (std::find(parentScenes.begin(), parentScenes.end(), linked) !=
parentScenes.end())
return false; // Circular dependency!
externalEventsDependencies.insert(linked); //There is a direct dependency
if ( !isOnTopLevel ) notTopLevelExternalEventsDependencies.insert(linked);
analyzer.AddParentExternalEvents(linked);
if ( !analyzer.Analyze(project.GetExternalEvents(linked).GetEvents(), isOnTopLevel) )
return false;
scenesDependencies.insert(linked); // There is a direct dependency
if (!isOnTopLevel) notTopLevelScenesDependencies.insert(linked);
analyzer.AddParentScene(linked);
if (!analyzer.Analyze(project.GetLayout(linked).GetEvents(),
isOnTopLevel))
return false;
}
}
else if ( project.HasLayoutNamed(linked) )
{
if ( std::find(parentScenes.begin(), parentScenes.end(), linked) != parentScenes.end() )
return false; //Circular dependency!
// Update with indirect dependencies.
scenesDependencies.insert(analyzer.GetScenesDependencies().begin(),
analyzer.GetScenesDependencies().end());
externalEventsDependencies.insert(
analyzer.GetExternalEventsDependencies().begin(),
analyzer.GetExternalEventsDependencies().end());
sourceFilesDependencies.insert(
analyzer.GetSourceFilesDependencies().begin(),
analyzer.GetSourceFilesDependencies().end());
notTopLevelScenesDependencies.insert(
analyzer.GetNotTopLevelScenesDependencies().begin(),
analyzer.GetNotTopLevelScenesDependencies().end());
notTopLevelExternalEventsDependencies.insert(
analyzer.GetNotTopLevelExternalEventsDependencies().begin(),
analyzer.GetNotTopLevelExternalEventsDependencies().end());
scenesDependencies.insert(linked); //There is a direct dependency
if ( !isOnTopLevel ) notTopLevelScenesDependencies.insert(linked);
analyzer.AddParentScene(linked);
if ( !analyzer.Analyze(project.GetLayout(linked).GetEvents(), isOnTopLevel) )
return false;
}
//Update with indirect dependencies.
scenesDependencies.insert(analyzer.GetScenesDependencies().begin(), analyzer.GetScenesDependencies().end());
externalEventsDependencies.insert(analyzer.GetExternalEventsDependencies().begin(), analyzer.GetExternalEventsDependencies().end());
sourceFilesDependencies.insert(analyzer.GetSourceFilesDependencies().begin(), analyzer.GetSourceFilesDependencies().end());
notTopLevelScenesDependencies.insert(analyzer.GetNotTopLevelScenesDependencies().begin(), analyzer.GetNotTopLevelScenesDependencies().end());
notTopLevelExternalEventsDependencies.insert(analyzer.GetNotTopLevelExternalEventsDependencies().begin(), analyzer.GetNotTopLevelExternalEventsDependencies().end());
if ( !isOnTopLevel )
{
notTopLevelScenesDependencies.insert(analyzer.GetScenesDependencies().begin(), analyzer.GetScenesDependencies().end());
notTopLevelExternalEventsDependencies.insert(analyzer.GetExternalEventsDependencies().begin(), analyzer.GetExternalEventsDependencies().end());
}
}
// Search for source files dependencies
std::vector<gd::String> dependencies = events[i].GetSourceFileDependencies();
sourceFilesDependencies.insert(dependencies.begin(), dependencies.end());
const gd::String & associatedSourceFile = events[i].GetAssociatedGDManagedSourceFile(project);
if (!associatedSourceFile.empty()) sourceFilesDependencies.insert(associatedSourceFile);
// Analyze sub events dependencies
if ( events[i].CanHaveSubEvents() )
{
if ( !Analyze(events[i].GetSubEvents(), false) )
return false;
}
if (!isOnTopLevel) {
notTopLevelScenesDependencies.insert(
analyzer.GetScenesDependencies().begin(),
analyzer.GetScenesDependencies().end());
notTopLevelExternalEventsDependencies.insert(
analyzer.GetExternalEventsDependencies().begin(),
analyzer.GetExternalEventsDependencies().end());
}
}
return true;
// Search for source files dependencies
std::vector<gd::String> dependencies =
events[i].GetSourceFileDependencies();
sourceFilesDependencies.insert(dependencies.begin(), dependencies.end());
const gd::String& associatedSourceFile =
events[i].GetAssociatedGDManagedSourceFile(project);
if (!associatedSourceFile.empty())
sourceFilesDependencies.insert(associatedSourceFile);
// Analyze sub events dependencies
if (events[i].CanHaveSubEvents()) {
if (!Analyze(events[i].GetSubEvents(), false)) return false;
}
}
return true;
}
gd::String DependenciesAnalyzer::ExternalEventsCanBeCompiledForAScene()
{
if ( !externalEvents )
{
std::cout << "ERROR: ExternalEventsCanBeCompiledForAScene called without external events set!" << std::endl;
return "";
gd::String DependenciesAnalyzer::ExternalEventsCanBeCompiledForAScene() {
if (!externalEvents) {
std::cout << "ERROR: ExternalEventsCanBeCompiledForAScene called without "
"external events set!"
<< std::endl;
return "";
}
gd::String sceneName;
for (unsigned int i = 0; i < project.GetLayoutsCount(); ++i) {
// For each layout, compute the dependencies and the dependencies which are
// not coming from a top level event.
DependenciesAnalyzer analyzer(project, project.GetLayout(i));
if (!analyzer.Analyze()) continue; // Analyze failed -> Cyclic dependencies
const std::set<gd::String>& dependencies =
analyzer.GetExternalEventsDependencies();
const std::set<gd::String>& notTopLevelDependencies =
analyzer.GetNotTopLevelExternalEventsDependencies();
// Check if the external events is a dependency, and that is is only present
// as a link on the top level.
if (dependencies.find(externalEvents->GetName()) != dependencies.end() &&
notTopLevelDependencies.find(externalEvents->GetName()) ==
notTopLevelDependencies.end()) {
if (!sceneName.empty())
return ""; // External events can be compiled only if one scene is
// including them.
else
sceneName = project.GetLayout(i).GetName();
}
}
gd::String sceneName;
for (unsigned int i = 0;i<project.GetLayoutsCount();++i)
{
//For each layout, compute the dependencies and the dependencies which are not coming from a top level event.
DependenciesAnalyzer analyzer(project, project.GetLayout(i));
if ( !analyzer.Analyze() ) continue; //Analyze failed -> Cyclic dependencies
const std::set <gd::String > & dependencies = analyzer.GetExternalEventsDependencies();
const std::set <gd::String > & notTopLevelDependencies = analyzer.GetNotTopLevelExternalEventsDependencies();
//Check if the external events is a dependency, and that is is only present as a link on the top level.
if ( dependencies.find(externalEvents->GetName()) != dependencies.end() &&
notTopLevelDependencies.find(externalEvents->GetName()) == notTopLevelDependencies.end() )
{
if (!sceneName.empty())
return ""; //External events can be compiled only if one scene is including them.
else
sceneName = project.GetLayout(i).GetName();
}
}
return sceneName; //External events can be compiled and used for the scene.
return sceneName; // External events can be compiled and used for the scene.
}
#endif

Some files were not shown because too many files have changed in this diff Show More