Skip to content

Commit

Permalink
Merge pull request #38131 from akien-mga/3.2-cherrypicks
Browse files Browse the repository at this point in the history
Cherry-picks for the 3.2 branch (future 3.2.2) - 3rd batch
  • Loading branch information
akien-mga authored Apr 23, 2020
2 parents 3b44f34 + dfdb7bd commit ed27b7e
Show file tree
Hide file tree
Showing 24 changed files with 259 additions and 102 deletions.
3 changes: 1 addition & 2 deletions editor/plugins/spatial_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -828,12 +828,11 @@ class EditorSpatialGizmoPlugin : public Resource {
static const int HIDDEN = 1;
static const int ON_TOP = 2;

private:
protected:
int current_state;
List<EditorSpatialGizmo *> current_gizmos;
HashMap<String, Vector<Ref<SpatialMaterial> > > materials;

protected:
static void _bind_methods();
virtual bool has_gizmo(Spatial *p_spatial);
virtual Ref<EditorSpatialGizmo> create_gizmo(Spatial *p_spatial);
Expand Down
11 changes: 6 additions & 5 deletions editor/plugins/tile_map_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,18 @@ void TileMapEditor::_notification(int p_what) {

} break;

case NOTIFICATION_ENTER_TREE: {

get_tree()->connect("node_removed", this, "_node_removed");
FALLTHROUGH;
}

case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {

if (is_visible_in_tree()) {
_update_palette();
}
FALLTHROUGH;
}

case NOTIFICATION_ENTER_TREE: {

get_tree()->connect("node_removed", this, "_node_removed");
paint_button->set_icon(get_icon("Edit", "EditorIcons"));
bucket_fill_button->set_icon(get_icon("Bucket", "EditorIcons"));
picker_button->set_icon(get_icon("ColorPick", "EditorIcons"));
Expand Down
19 changes: 19 additions & 0 deletions editor/spatial_editor_gizmos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4075,6 +4075,25 @@ JointSpatialGizmoPlugin::JointSpatialGizmoPlugin() {
create_material("joint_material", EDITOR_DEF("editors/3d_gizmos/gizmo_colors/joint", Color(0.5, 0.8, 1)));
create_material("joint_body_a_material", EDITOR_DEF("editors/3d_gizmos/gizmo_colors/joint_body_a", Color(0.6, 0.8, 1)));
create_material("joint_body_b_material", EDITOR_DEF("editors/3d_gizmos/gizmo_colors/joint_body_b", Color(0.6, 0.9, 1)));

update_timer = memnew(Timer);
update_timer->set_name("JointGizmoUpdateTimer");
update_timer->set_wait_time(1.0 / 120.0);
update_timer->connect("timeout", this, "incremental_update_gizmos");
update_timer->set_autostart(true);
EditorNode::get_singleton()->call_deferred("add_child", update_timer);
}

void JointSpatialGizmoPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("incremental_update_gizmos"), &JointSpatialGizmoPlugin::incremental_update_gizmos);
}

void JointSpatialGizmoPlugin::incremental_update_gizmos() {
if (!current_gizmos.empty()) {
update_idx++;
update_idx = update_idx % current_gizmos.size();
redraw(current_gizmos[update_idx]);
}
}

bool JointSpatialGizmoPlugin::has_gizmo(Spatial *p_spatial) {
Expand Down
8 changes: 8 additions & 0 deletions editor/spatial_editor_gizmos.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,14 @@ class JointSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {

GDCLASS(JointSpatialGizmoPlugin, EditorSpatialGizmoPlugin);

Timer *update_timer;
uint64_t update_idx = 0;

void incremental_update_gizmos();

protected:
static void _bind_methods();

public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
Expand Down
8 changes: 8 additions & 0 deletions modules/gdscript/gdscript_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2683,6 +2683,7 @@ void GDScriptParser::_transform_match_statment(MatchNode *p_match_statement) {
LocalVarNode *local_var = branch->body->variables[e->key()];
local_var->assign = e->value();
local_var->set_datatype(local_var->assign->get_datatype());
local_var->assignments++;

IdentifierNode *id2 = alloc_node<IdentifierNode>();
id2->name = local_var->name;
Expand Down Expand Up @@ -3673,6 +3674,12 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
_set_error("A constant named \"" + String(name) + "\" already exists in the outer class scope (at line" + itos(outer_class->constant_expressions[name].expression->line) + ").");
return;
}
for (int i = 0; i < outer_class->variables.size(); i++) {
if (outer_class->variables[i].identifier == name) {
_set_error("A variable named \"" + String(name) + "\" already exists in the outer class scope (at line " + itos(outer_class->variables[i].line) + ").");
return;
}
}

outer_class = outer_class->owner;
}
Expand Down Expand Up @@ -6568,6 +6575,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
node_type = _reduce_identifier_type(&base_type, member_id->name, op->line, true);
#ifdef DEBUG_ENABLED
if (!node_type.has_type) {
_mark_line_as_unsafe(op->line);
_add_warning(GDScriptWarning::UNSAFE_PROPERTY_ACCESS, op->line, member_id->name.operator String(), base_type.to_string());
}
#endif // DEBUG_ENABLED
Expand Down
27 changes: 27 additions & 0 deletions modules/mono/editor/GodotTools/GodotTools.Core/FileUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.IO;

namespace GodotTools.Core
{
public static class FileUtils
{
public static void SaveBackupCopy(string filePath)
{
string backupPathBase = filePath + ".old";
string backupPath = backupPathBase;

const int maxAttempts = 5;
int attempt = 1;

while (File.Exists(backupPath) && attempt <= maxAttempts)
{
backupPath = backupPathBase + "." + (attempt);
attempt++;
}

if (attempt > maxAttempts + 1)
return;

File.Copy(filePath, backupPath, overwrite: true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="FileUtils.cs" />
<Compile Include="ProcessExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StringExtensions.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ public static void MigrateFromOldConfigNames(string slnPath)
var result = regex.Replace(input,m => dict[m.Value]);

if (result != input)
{
// Save a copy of the solution before replacing it
FileUtils.SaveBackupCopy(slnPath);

File.WriteAllText(slnPath, result);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,28 @@

namespace GodotTools.ProjectEditor
{
public sealed class MSBuildProject
{
public ProjectRootElement Root { get; }

public bool HasUnsavedChanges => Root.HasUnsavedChanges;

public void Save() => Root.Save();

public MSBuildProject(ProjectRootElement root)
{
Root = root;
}
}

public static class ProjectUtils
{
public static MSBuildProject Open(string path)
{
var root = ProjectRootElement.Open(path);
return root != null ? new MSBuildProject(root) : null;
}

public static void AddItemToProjectChecked(string projectPath, string itemType, string include)
{
var dir = Directory.GetParent(projectPath).FullName;
Expand Down Expand Up @@ -43,7 +63,6 @@ public static void RenameItemInProjectChecked(string projectPath, string itemTyp

public static void RemoveItemFromProjectChecked(string projectPath, string itemType, string include)
{
var dir = Directory.GetParent(projectPath).FullName;
var root = ProjectRootElement.Open(projectPath);
Debug.Assert(root != null);

Expand All @@ -59,8 +78,6 @@ public static void RenameItemsToNewFolderInProjectChecked(string projectPath, st
var root = ProjectRootElement.Open(projectPath);
Debug.Assert(root != null);

bool dirty = false;

var oldFolderNormalized = oldFolder.NormalizePath();
var newFolderNormalized = newFolder.NormalizePath();
string absOldFolderNormalized = Path.GetFullPath(oldFolderNormalized).NormalizePath();
Expand All @@ -71,10 +88,9 @@ public static void RenameItemsToNewFolderInProjectChecked(string projectPath, st
string absPathNormalized = Path.GetFullPath(item.Include).NormalizePath();
string absNewIncludeNormalized = absNewFolderNormalized + absPathNormalized.Substring(absOldFolderNormalized.Length);
item.Include = absNewIncludeNormalized.RelativeToPath(dir).Replace("/", "\\");
dirty = true;
}

if (dirty)
if (root.HasUnsavedChanges)
root.Save();
}

Expand Down Expand Up @@ -150,12 +166,9 @@ public static string[] GetIncludeFiles(string projectPath, string itemType)
}

/// Simple function to make sure the Api assembly references are configured correctly
public static void FixApiHintPath(string projectPath)
public static void FixApiHintPath(MSBuildProject project)
{
var root = ProjectRootElement.Open(projectPath);
Debug.Assert(root != null);

bool dirty = false;
var root = project.Root;

void AddPropertyIfNotPresent(string name, string condition, string value)
{
Expand All @@ -170,7 +183,6 @@ void AddPropertyIfNotPresent(string name, string condition, string value)
}

root.AddProperty(name, value).Condition = " " + condition + " ";
dirty = true;
}

AddPropertyIfNotPresent(name: "ApiConfiguration",
Expand Down Expand Up @@ -212,7 +224,6 @@ void SetReferenceHintPath(string referenceName, string condition, string hintPat
}

referenceWithHintPath.AddMetadata("HintPath", hintPath);
dirty = true;
return;
}

Expand All @@ -221,14 +232,12 @@ void SetReferenceHintPath(string referenceName, string condition, string hintPat
{
// Found a Reference item without a HintPath
referenceWithoutHintPath.AddMetadata("HintPath", hintPath);
dirty = true;
return;
}
}

// Found no Reference item at all. Add it.
root.AddItem("Reference", referenceName).Condition = " " + condition + " ";
dirty = true;
}

const string coreProjectName = "GodotSharp";
Expand All @@ -242,17 +251,11 @@ void SetReferenceHintPath(string referenceName, string condition, string hintPat

SetReferenceHintPath(coreProjectName, coreCondition, coreHintPath);
SetReferenceHintPath(editorProjectName, editorCondition, editorHintPath);

if (dirty)
root.Save();
}

public static void MigrateFromOldConfigNames(string projectPath)
public static void MigrateFromOldConfigNames(MSBuildProject project)
{
var root = ProjectRootElement.Open(projectPath);
Debug.Assert(root != null);

bool dirty = false;
var root = project.Root;

bool hasGodotProjectGeneratorVersion = false;
bool foundOldConfiguration = false;
Expand All @@ -267,15 +270,13 @@ public static void MigrateFromOldConfigNames(string projectPath)
{
configItem.Value = "Debug";
foundOldConfiguration = true;
dirty = true;
}
}

if (!hasGodotProjectGeneratorVersion)
{
root.PropertyGroups.First(g => g.Condition == string.Empty)?
.AddProperty("GodotProjectGeneratorVersion", Assembly.GetExecutingAssembly().GetName().Version.ToString());
dirty = true;
}

if (!foundOldConfiguration)
Expand All @@ -299,33 +300,21 @@ void MigrateConfigurationConditions(string oldConfiguration, string newConfigura
void MigrateConditions(string oldCondition, string newCondition)
{
foreach (var propertyGroup in root.PropertyGroups.Where(g => g.Condition.Trim() == oldCondition))
{
propertyGroup.Condition = " " + newCondition + " ";
dirty = true;
}

foreach (var propertyGroup in root.PropertyGroups)
{
foreach (var prop in propertyGroup.Properties.Where(p => p.Condition.Trim() == oldCondition))
{
prop.Condition = " " + newCondition + " ";
dirty = true;
}
}

foreach (var itemGroup in root.ItemGroups.Where(g => g.Condition.Trim() == oldCondition))
{
itemGroup.Condition = " " + newCondition + " ";
dirty = true;
}

foreach (var itemGroup in root.ItemGroups)
{
foreach (var item in itemGroup.Items.Where(item => item.Condition.Trim() == oldCondition))
{
item.Condition = " " + newCondition + " ";
dirty = true;
}
}
}

Expand All @@ -340,10 +329,6 @@ void MigrateConditions(string oldCondition, string newCondition)
MigrateConfigurationConditions("Release", "ExportRelease");
MigrateConfigurationConditions("Tools", "Debug"); // Must be last
}


if (dirty)
root.Save();
}
}
}
Loading

0 comments on commit ed27b7e

Please sign in to comment.