Skip to content

Commit 35bb084

Browse files
committed
Remove obsolete input/field IDs
1 parent 6b5cc48 commit 35bb084

File tree

16 files changed

+0
-297
lines changed

16 files changed

+0
-297
lines changed

include/scratchcpp/block.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ class LIBSCRATCHCPP_EXPORT Block
2323
, public std::enable_shared_from_this<Block>
2424
{
2525
public:
26-
friend class Engine;
27-
2826
Block(const std::string &id, const std::string &opcode, bool isMonitorBlock = false);
2927
Block(const Block &) = delete;
3028

@@ -46,13 +44,11 @@ class LIBSCRATCHCPP_EXPORT Block
4644
int addInput(std::shared_ptr<Input> input);
4745
std::shared_ptr<Input> inputAt(int index) const;
4846
int findInput(const std::string &inputName) const;
49-
Input *findInputById(int id) const;
5047

5148
const std::vector<std::shared_ptr<Field>> &fields() const;
5249
int addField(std::shared_ptr<Field> field);
5350
std::shared_ptr<Field> fieldAt(int index) const;
5451
int findField(const std::string &fieldName) const;
55-
Field *findFieldById(int id) const;
5652

5753
bool shadow() const;
5854
void setShadow(bool newShadow);
@@ -95,9 +91,6 @@ class LIBSCRATCHCPP_EXPORT Block
9591
bool isMonitorBlock() const;
9692

9793
private:
98-
void updateInputMap();
99-
void updateFieldMap();
100-
10194
spimpl::unique_impl_ptr<BlockPrivate> impl;
10295
};
10396

include/scratchcpp/field.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,13 @@ class LIBSCRATCHCPP_EXPORT Field
2626

2727
const std::string &name() const;
2828

29-
int fieldId() const;
30-
void setFieldId(int newFieldId);
31-
3229
const Value &value() const;
3330

3431
std::shared_ptr<Entity> valuePtr() const;
3532
void setValuePtr(const std::shared_ptr<Entity> &newValuePtr);
3633

3734
const std::string &valueId() const;
3835

39-
int specialValueId() const;
40-
void setSpecialValueId(int newSpecialValueId);
41-
4236
private:
4337
spimpl::unique_impl_ptr<FieldPrivate> impl;
4438
};

include/scratchcpp/iengine.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -249,24 +249,6 @@ class LIBSCRATCHCPP_EXPORT IEngine
249249
*/
250250
virtual void addHatBlock(IExtension *extension, const std::string &opcode) = 0;
251251

252-
/*!
253-
* Call this from IExtension#registerBlocks() to add an input to a block section.
254-
* \see <a href="extensions.html">Extensions</a>
255-
*/
256-
virtual void addInput(IExtension *extension, const std::string &name, int id) = 0;
257-
258-
/*!
259-
* Call this from IExtension#registerBlocks() to add a field to a block section.
260-
* \see <a href="extensions.html">Extensions</a>
261-
*/
262-
virtual void addField(IExtension *extension, const std::string &name, int id) = 0;
263-
264-
/*!
265-
* Call this from IExtension#registerBlocks() to add a field value to a block section.
266-
* \see <a href="extensions.html">Extensions</a>
267-
*/
268-
virtual void addFieldValue(IExtension *extension, const std::string &value, int id) = 0;
269-
270252
/*! Returns the list of broadcasts. */
271253
virtual const std::vector<std::shared_ptr<Broadcast>> &broadcasts() const = 0;
272254

include/scratchcpp/input.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ class LIBSCRATCHCPP_EXPORT Input
2929

3030
const std::string &name() const;
3131

32-
int inputId() const;
33-
void setInputId(int newInputId);
34-
3532
Type type() const;
3633

3734
InputValue *primaryValue();

src/engine/internal/engine.cpp

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ void Engine::resolveIds()
118118
for (const auto &input : inputs) {
119119
input->setValueBlock(getBlock(input->valueBlockId(), target.get()).get());
120120

121-
if (ext)
122-
input->setInputId(resolveInput(ext, input->name()));
123-
124121
InputValue *value = input->primaryValue();
125122
std::string id = value->valueId(); // no reference!
126123
value->setValuePtr(getEntity(id, target.get()));
@@ -150,13 +147,6 @@ void Engine::resolveIds()
150147
std::string id = field->valueId(); // no reference!
151148
field->setValuePtr(getEntity(id, target.get()));
152149

153-
if (ext) {
154-
field->setFieldId(resolveField(ext, field->name()));
155-
156-
if (!field->valuePtr())
157-
field->setSpecialValueId(resolveFieldValue(ext, field->value().toString()));
158-
}
159-
160150
// TODO: Move field information out of Engine
161151
if (!field->valuePtr()) {
162152
if (field->name() == "VARIABLE") {
@@ -175,9 +165,6 @@ void Engine::resolveIds()
175165
}
176166
}
177167

178-
block->updateInputMap();
179-
block->updateFieldMap();
180-
181168
auto comment = getComment(block->commentId(), target.get());
182169
block->setComment(comment);
183170

@@ -210,13 +197,6 @@ void Engine::resolveIds()
210197
for (auto field : fields) {
211198
field->setValuePtr(getEntity(field->valueId(), target));
212199

213-
if (ext) {
214-
field->setFieldId(resolveField(ext, field->name()));
215-
216-
if (!field->valuePtr())
217-
field->setSpecialValueId(resolveFieldValue(ext, field->value().toString()));
218-
}
219-
220200
// TODO: Move field information out of Engine
221201
if (field->name() == "VARIABLE") {
222202
std::string name = field->value().toString();
@@ -248,9 +228,6 @@ void Engine::resolveIds()
248228
list->setMonitor(monitor.get());
249229
}
250230
}
251-
252-
block->updateInputMap();
253-
block->updateFieldMap();
254231
}
255232
}
256233

@@ -971,30 +948,6 @@ void Engine::addHatBlock(IExtension *extension, const std::string &opcode)
971948
m_compileFunctions[extension][opcode] = [](Compiler *compiler) -> CompilerValue * { return nullptr; };
972949
}
973950

974-
void Engine::addInput(IExtension *extension, const std::string &name, int id)
975-
{
976-
if (m_inputs.find(extension) == m_inputs.cend())
977-
m_inputs[extension] = {};
978-
979-
m_inputs[extension][name] = id;
980-
}
981-
982-
void Engine::addField(IExtension *extension, const std::string &name, int id)
983-
{
984-
if (m_fields.find(extension) == m_fields.cend())
985-
m_fields[extension] = {};
986-
987-
m_fields[extension][name] = id;
988-
}
989-
990-
void Engine::addFieldValue(IExtension *extension, const std::string &value, int id)
991-
{
992-
if (m_fieldValues.find(extension) == m_fieldValues.cend())
993-
m_fieldValues[extension] = {};
994-
995-
m_fieldValues[extension][value] = id;
996-
}
997-
998951
const std::vector<std::shared_ptr<Broadcast>> &Engine::broadcasts() const
999952
{
1000953
return m_broadcasts;
@@ -1733,9 +1686,6 @@ void Engine::clearExtensionData()
17331686
m_hatPredicateCompileFunctions.clear();
17341687
m_monitorNameFunctions.clear();
17351688
m_monitorChangeFunctions.clear();
1736-
m_inputs.clear();
1737-
m_fields.clear();
1738-
m_fieldValues.clear();
17391689
}
17401690

17411691
IExtension *Engine::blockExtension(const std::string &opcode) const
@@ -1818,57 +1768,6 @@ MonitorChangeFunc Engine::resolveMonitorChangeFunc(IExtension *extension, const
18181768
return nullptr;
18191769
}
18201770

1821-
int Engine::resolveInput(IExtension *extension, const std::string &name) const
1822-
{
1823-
if (!extension)
1824-
return -1;
1825-
1826-
auto it = m_inputs.find(extension);
1827-
1828-
if (it != m_inputs.cend()) {
1829-
auto dataIt = it->second.find(name);
1830-
1831-
if (dataIt != it->second.cend())
1832-
return dataIt->second;
1833-
}
1834-
1835-
return -1;
1836-
}
1837-
1838-
int Engine::resolveField(IExtension *extension, const std::string &name) const
1839-
{
1840-
if (!extension)
1841-
return -1;
1842-
1843-
auto it = m_fields.find(extension);
1844-
1845-
if (it != m_fields.cend()) {
1846-
auto dataIt = it->second.find(name);
1847-
1848-
if (dataIt != it->second.cend())
1849-
return dataIt->second;
1850-
}
1851-
1852-
return -1;
1853-
}
1854-
1855-
int Engine::resolveFieldValue(IExtension *extension, const std::string &value) const
1856-
{
1857-
if (!extension)
1858-
return -1;
1859-
1860-
auto it = m_fieldValues.find(extension);
1861-
1862-
if (it != m_fieldValues.cend()) {
1863-
auto dataIt = it->second.find(value);
1864-
1865-
if (dataIt != it->second.cend())
1866-
return dataIt->second;
1867-
}
1868-
1869-
return -1;
1870-
}
1871-
18721771
void Engine::compileMonitor(std::shared_ptr<Monitor> monitor)
18731772
{
18741773
Target *target = monitor->sprite() ? static_cast<Target *>(monitor->sprite()) : stage();

src/engine/internal/engine.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ class Engine : public IEngine
108108
void addMonitorNameFunction(IExtension *extension, const std::string &opcode, MonitorNameFunc f) override;
109109
void addMonitorChangeFunction(IExtension *extension, const std::string &opcode, MonitorChangeFunc f) override;
110110
void addHatBlock(IExtension *extension, const std::string &opcode) override;
111-
void addInput(IExtension *extension, const std::string &name, int id) override;
112-
void addField(IExtension *extension, const std::string &name, int id) override;
113-
void addFieldValue(IExtension *extension, const std::string &value, int id) override;
114111

115112
const std::vector<std::shared_ptr<Broadcast>> &broadcasts() const override;
116113
void setBroadcasts(const std::vector<std::shared_ptr<Broadcast>> &broadcasts) override;
@@ -192,9 +189,6 @@ class Engine : public IEngine
192189
HatPredicateCompileFunc resolveHatPredicateCompileFunc(IExtension *extension, const std::string &opcode) const;
193190
MonitorNameFunc resolveMonitorNameFunc(IExtension *extension, const std::string &opcode) const;
194191
MonitorChangeFunc resolveMonitorChangeFunc(IExtension *extension, const std::string &opcode) const;
195-
int resolveInput(IExtension *extension, const std::string &name) const;
196-
int resolveField(IExtension *extension, const std::string &name) const;
197-
int resolveFieldValue(IExtension *extension, const std::string &value) const;
198192

199193
void compileMonitor(std::shared_ptr<Monitor> monitor);
200194

@@ -255,9 +249,6 @@ class Engine : public IEngine
255249
std::unordered_map<IExtension *, std::unordered_map<std::string, HatPredicateCompileFunc>> m_hatPredicateCompileFunctions;
256250
std::unordered_map<IExtension *, std::unordered_map<std::string, MonitorNameFunc>> m_monitorNameFunctions;
257251
std::unordered_map<IExtension *, std::unordered_map<std::string, MonitorChangeFunc>> m_monitorChangeFunctions;
258-
std::unordered_map<IExtension *, std::unordered_map<std::string, int>> m_inputs;
259-
std::unordered_map<IExtension *, std::unordered_map<std::string, int>> m_fields;
260-
std::unordered_map<IExtension *, std::unordered_map<std::string, int>> m_fieldValues;
261252

262253
std::unordered_map<Target *, std::vector<Script *>> m_whenTouchingObjectHats;
263254
std::unordered_map<Target *, std::vector<Script *>> m_greenFlagHats;

src/scratch/block.cpp

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,6 @@ int Block::addInput(std::shared_ptr<Input> input)
198198
return it - impl->inputs.begin();
199199

200200
impl->inputs.push_back(input);
201-
impl->inputMap[input->inputId()] = input.get();
202-
203201
return impl->inputs.size() - 1;
204202
}
205203

@@ -223,27 +221,6 @@ int Block::findInput(const std::string &inputName) const
223221
return it - impl->inputs.begin();
224222
}
225223

226-
/*! Returns the input with the given ID. */
227-
Input *Block::findInputById(int id) const
228-
{
229-
if (impl->inputMap.count(id) == 1)
230-
return impl->inputMap.at(id);
231-
else {
232-
auto it = std::find_if(impl->inputs.begin(), impl->inputs.end(), [id](std::shared_ptr<Input> input) { return input->inputId() == id; });
233-
234-
if (it != impl->inputs.end())
235-
return it->get();
236-
}
237-
return nullptr;
238-
}
239-
240-
void Block::updateInputMap()
241-
{
242-
impl->inputMap.clear();
243-
for (auto input : impl->inputs)
244-
impl->inputMap[input->inputId()] = input.get();
245-
}
246-
247224
/*! Returns the list of fields. */
248225
const std::vector<std::shared_ptr<Field>> &Block::fields() const
249226
{
@@ -259,8 +236,6 @@ int Block::addField(std::shared_ptr<Field> field)
259236
return it - impl->fields.begin();
260237

261238
impl->fields.push_back(field);
262-
impl->fieldMap[field->fieldId()] = field.get();
263-
264239
return impl->fields.size() - 1;
265240
}
266241

@@ -284,27 +259,6 @@ int Block::findField(const std::string &fieldName) const
284259
return it - impl->fields.begin();
285260
}
286261

287-
/*! Returns the index of the field with the given ID. */
288-
Field *Block::findFieldById(int id) const
289-
{
290-
if (impl->fieldMap.count(id) == 1)
291-
return impl->fieldMap.at(id);
292-
else {
293-
auto it = std::find_if(impl->fields.begin(), impl->fields.end(), [id](std::shared_ptr<Field> field) { return field->fieldId() == id; });
294-
295-
if (it != impl->fields.end())
296-
return it->get();
297-
}
298-
return nullptr;
299-
}
300-
301-
void Block::updateFieldMap()
302-
{
303-
impl->fieldMap.clear();
304-
for (auto field : impl->fields)
305-
impl->fieldMap[field->fieldId()] = field.get();
306-
}
307-
308262
/*! Returns true if this is a shadow block. */
309263
bool Block::shadow() const
310264
{

src/scratch/block_p.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ struct BlockPrivate
2929
Block *parent = nullptr;
3030
std::string parentId;
3131
std::vector<std::shared_ptr<Input>> inputs;
32-
std::unordered_map<int, Input *> inputMap;
3332
std::vector<std::shared_ptr<Field>> fields;
34-
std::unordered_map<int, Field *> fieldMap;
3533
bool shadow = false;
3634
int x = 0;
3735
int y = 0;

src/scratch/field.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,6 @@ const std::string &Field::name() const
3131
return impl->name;
3232
}
3333

34-
/*! Returns the ID of the field. */
35-
int Field::fieldId() const
36-
{
37-
return impl->fieldId;
38-
}
39-
40-
/*! Sets the ID of the field. */
41-
void Field::setFieldId(int newFieldId)
42-
{
43-
impl->fieldId = newFieldId;
44-
}
45-
4634
/*! Returns the value of the field. */
4735
const Value &Field::value() const
4836
{
@@ -71,21 +59,3 @@ const std::string &Field::valueId() const
7159
{
7260
return impl->valueId;
7361
}
74-
75-
/*!
76-
* Returns the ID that was assigned to the value.
77-
* \see IEngine::addFieldValue()
78-
*/
79-
int Field::specialValueId() const
80-
{
81-
return impl->specialValueId;
82-
}
83-
84-
/*!
85-
* Assigns an ID to the value.
86-
* \see IEngine::addFieldValue()
87-
*/
88-
void Field::setSpecialValueId(int newSpecialValueId)
89-
{
90-
impl->specialValueId = newSpecialValueId;
91-
}

0 commit comments

Comments
 (0)