-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPropitizeAction.cs
More file actions
100 lines (89 loc) · 3.57 KB
/
PropitizeAction.cs
File metadata and controls
100 lines (89 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Reflection;
using System.Collections.Generic;
using ColossalFramework;
using UnityEngine;
using MoveIt;
using HarmonyLib;
namespace Propitize
{
public enum ToolAction
{
None,
Do,
Undo,
Redo
}
public class PropitizeAction : MoveIt.Action
{
public HashSet<InstanceState> m_states = new HashSet<InstanceState>();
public bool replaceInstances = true;
internal HashSet<Instance> m_clones; // the resulting Instances
internal HashSet<Instance> m_oldSelection; // The selection before cloning
public PropitizeAction(bool defaultConstructor) : base()
{
if (!defaultConstructor) return; // Ugly hack to control when this constructor is called by derived classes
m_oldSelection = selection;
HashSet<Instance> newSelection = new HashSet<Instance>(selection);
foreach(Instance instance in newSelection)
{
if(instance.id.Type == InstanceType.Tree && instance.isValid)
{
m_states.Add(instance.SaveToState());
}
}
StartConversion();
}
private void StartConversion()
{
m_clones = new HashSet<Instance>();
foreach (InstanceState state in m_states)
{
if (state is TreeState)
{
lock(state.instance.data)
{
TreeInfo treeInfo = state.instance.Info.Prefab as TreeInfo;
PropInfo propInfo = null;
Instance instanceProp = null;
if (!PropitizeMod.PropitizedTreeMap.ContainsKey(treeInfo))
{
propInfo = PropitizeTool.PropitizeTree(treeInfo, true);
PropitizeTool.PropFinalTouch(ref propInfo, ref treeInfo);
PropitizeTool.InitializeAndBindPrefab(propInfo);
}
else
{
propInfo = PropitizeMod.PropitizedTreeMap.GetValueSafe<TreeInfo, PropInfo>(treeInfo);
}
PropitizeTool.PropitizeTreeSizeRandomizer(ref propInfo);
if (Singleton<PropManager>.instance.CreateProp(out ushort clone, ref SimulationManager.instance.m_randomizer, propInfo, state.position, state.angle, true))
{
InstanceID cloneID = default;
cloneID.Prop = clone;
instanceProp = new MoveableProp(cloneID);
}
m_clones.Add(instanceProp);
selection.Add(instanceProp);
selection.Remove(state.instance);
state.instance.Delete();
// save tree name to file for later propitizing
PropitizeTool.SavePropitizedTree(treeInfo);
}
}
}
}
public override void Do()
{
throw new NotImplementedException();
}
public override void Undo()
{
throw new NotImplementedException();
}
public override void ReplaceInstances(Dictionary<Instance, Instance> toReplace)
{
throw new NotImplementedException();
}
}
}