Skip to content

Commit

Permalink
* [Ядро] #51 Ошибка ядра: получение доступного содержимого проверяет …
Browse files Browse the repository at this point in the history
…только

    первую роль с нужным триггером
  • Loading branch information
realsonic committed May 16, 2022
1 parent def35fc commit d66cc43
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 28 deletions.
3 changes: 3 additions & 0 deletions docs/notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
ЯРИЛ, может не быть прав на запись файла.
ifml2/ifml2#47 Предложение 4. Добавление музыки
* [Платформа] В ifml2.jar теперь включаются mp3-библиотеки.
16.05.2022
* [Ядро] ifml2/ifml2#51 Ошибка ядра: получение доступного содержимого проверяет только
первую роль с нужным триггером

-----------------------------------------------------------------------------------------------
Выпуск 2016/5
Expand Down
42 changes: 18 additions & 24 deletions src/ifml2/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import ca.odell.glazedlists.BasicEventList;
import ca.odell.glazedlists.EventList;
import ifml2.CommonConstants;
import ifml2.FormatLogger;
import ifml2.IFML2Exception;
import ifml2.SystemIdentifiers;
import ifml2.*;
import ifml2.engine.featureproviders.IPlayerFeatureProvider;
import ifml2.engine.featureproviders.graphic.IOutputIconProvider;
import ifml2.engine.featureproviders.text.IOutputPlainTextProvider;
Expand All @@ -27,8 +24,8 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.*;
import java.util.List;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -637,28 +634,25 @@ public void loadGame(String saveFileName) throws IFML2Exception {
*/
public boolean checkDeepContent(Item itemToCheck, List<Item> items) throws IFML2Exception {
for (Item item : items) {
Value itemContents = item.getAccessibleContent(getVirtualMachine());
if (itemContents != null) {
if (!(itemContents instanceof CollectionValue)) {
throw new IFML2VMException("Триггер доступного содержимого у предмета \"{0}\" вернул не коллекцию, а \"{1}\"!",
itemToCheck, itemContents.getTypeName());
}

List itemContentsList = ((CollectionValue) itemContents).getValue();
List<Item> itemContentsItemList = new BasicEventList<>();
for (Object object : itemContentsList) {
if (!(object instanceof Item)) {
throw new IFML2VMException(
"Триггер доступного содержимого у предмета \"{0}\" вернул в коллекции не предмет, а \"{1}\"!", itemToCheck,
object);
}
CollectionValue itemContents = item.getAccessibleContent(getVirtualMachine());
if (itemContents == null) {
continue;
}

itemContentsItemList.add((Item) object);
List<? extends IFMLEntity> itemContentsList = itemContents.getValue();
List<Item> itemContentsItemList = new BasicEventList<>();
for (IFMLEntity ifmlEntity : itemContentsList) {
if (!(ifmlEntity instanceof Item)) {
throw new IFML2VMException(
"Триггер доступного содержимого у предмета \"{0}\" вернул в коллекции не предмет, а \"{1}\"!", itemToCheck,
ifmlEntity);
}

if (itemContentsList.contains(itemToCheck) || checkDeepContent(itemToCheck, itemContentsItemList)) {
return true;
}
itemContentsItemList.add((Item) ifmlEntity);
}

if (itemContentsList.contains(itemToCheck) || checkDeepContent(itemToCheck, itemContentsItemList)) {
return true;
}
}

Expand Down
25 changes: 21 additions & 4 deletions src/ifml2/om/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ifml2.IFML2Exception;
import ifml2.IFMLEntity;
import ifml2.om.xml.XmlSchemaConstants;
import ifml2.vm.IFML2VMException;
import ifml2.vm.SymbolResolver;
import ifml2.vm.VirtualMachine;
import ifml2.vm.values.CollectionValue;
Expand All @@ -15,11 +16,13 @@
import org.jetbrains.annotations.NotNull;

import javax.xml.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;

import static ifml2.om.Trigger.Type.GET_ACCESSIBLE_CONTENT;
import static ifml2.om.xml.XmlSchemaConstants.ITEM_STARTING_POSITION_ELEMENT;
import static ifml2.om.xml.XmlSchemaConstants.STARTING_POSITION_INVENTORY_ELEMENT;
import static java.lang.String.format;

@XmlAccessorType(XmlAccessType.NONE)
public class Item extends IFMLObject implements Cloneable {
Expand Down Expand Up @@ -67,18 +70,32 @@ public String toString() {
* @param virtualMachine Virtual Machine
* @return Value returned by trigger
*/
public Value getAccessibleContent(VirtualMachine virtualMachine) throws IFML2Exception {
public CollectionValue getAccessibleContent(VirtualMachine virtualMachine) throws IFML2Exception {
//todo: run own triggers -- when they will exist

List<IFMLEntity> allAccessibleObjects = new ArrayList<>();

// run roles' triggers
for (Role role : roles) {
Trigger trigger = role.getRoleDefinition().getTrigger(GET_ACCESSIBLE_CONTENT);
if (trigger != null) {
return virtualMachine.runTrigger(trigger, this);
if (trigger == null) {
continue;
}

Value<?> value = virtualMachine.runTrigger(trigger, this);
if (value == null) {
continue;
}

if (value instanceof CollectionValue) {
List<? extends IFMLEntity> accessibleObjects = ((CollectionValue) value).getValue();
allAccessibleObjects.addAll(accessibleObjects);
} else {
throw new IFML2VMException(format("Триггер доступного содержимого у роли \"%s\" предмета \"%s\" вернул не коллекцию, а \"%s\"!", role.getName(), this, value));
}
}

return null;
return new CollectionValue(allAccessibleObjects);
}

public List<? extends IFMLEntity> getContainer() {
Expand Down

0 comments on commit d66cc43

Please sign in to comment.