Beispiel #1
0
    public WorldEvent(Event info, Executable onInit, TypedExecutable <bool> condition,
                      Executable action, ParserContext parserContext)
    {
        this.info      = info;
        this.onInit    = onInit;
        this.condition = condition;
        this.action    = action;

        // Trigger limit parsing
        triggersLimit = TypedExecutable <int> .FromScript(info.TriggerLimit,
                                                          parserContext);

        if (triggersLimit == null)
        {
            Debug.LogError(
                $"WorldEvent (Info.Id = {info.Id}) : trigger limit parsing error in " +
                $"\"{info.TriggerLimit}\". Reverting to no limit default (-1).");
            triggersLimit = TypedExecutable <int> .FromScript("-1", parserContext); // no limit by default

            Assert.IsNotNull(triggersLimit);
        }

        // Text parsing
        cachedTitle = CachedText(info.TitleEnglish, titleExpressions, "Title",
                                 parserContext);
        cachedDescription = CachedText(info.DescriptionEnglish,
                                       descriptionExpressions, "Description", parserContext);
    }
Beispiel #2
0
 public WorldEngineFeature(EngineFeature info,
                           TypedExecutable <bool> requirement, Executable effect)
 {
     this.info        = info;
     this.requirement = requirement;
     this.effect      = effect;
 }
Beispiel #3
0
    public void CreateFeatures(List <EngineFeature> engineFeatures,
                               ParserContext parserContext)
    {
        foreach (EngineFeature f in engineFeatures)
        {
            // Parse the Requirement script
            TypedExecutable <bool> requirement = TypedExecutable <bool> .FromScript(
                f.Requirement, parserContext);

            if (requirement == null)
            {
                Debug.LogError("EngineFeaturesController.InitFeatures : Requirement parsing " +
                               $"error for EngineFeature (ID = {f.Id}). Ignoring \"{f.Requirement}\".");
                continue;
            }

            // Parse the Effect script
            Executable effect = Executable.FromScript(f.Effect, parserContext);
            if (effect == null)
            {
                Debug.LogError("EngineFeaturesController.InitFeatures : Effect parsing " +
                               $"error for EngineFeature (ID = {f.Id}). Ignoring \"{f.Effect}\".");
                continue;
            }

            // Store the WorldEvent and its computed metadata
            WorldEngineFeature worldFeature = new WorldEngineFeature(f, requirement, effect);
            worldFeatures.Add(worldFeature);
        }
    }
Beispiel #4
0
    public void CreateEvents(List <Event> events,
                             ParserContext parserContext)
    {
        foreach (Event e in events)
        {
            // On-Init script
            Executable onInit = Executable.FromScript(e.OnInit, parserContext);
            if (onInit == null)
            {
                Debug.LogError(
                    "EventsController - Event on-init script parsing " +
                    $"error for Event (ID = {e.Id}). Ignoring Event."
                    );
                continue;
            }
            // Condition script
            TypedExecutable <bool> condition = TypedExecutable <bool> .FromScript(
                e.TriggerCondition, parserContext);

            if (condition == null)
            {
                Debug.LogError(
                    "EventsController - Condition parsing error for Event " +
                    $"(ID = {e.Id}) in \"{e.TriggerCondition}\".");
                continue;
            }
            // Action script
            Executable action = Executable.FromScript(e.TriggerAction,
                                                      parserContext);
            if (action == null)
            {
                Debug.LogError(
                    "EventsController - Action parsing error for Event " +
                    $"(ID = {e.Id}) in \"{e.TriggerCondition}\".");
                continue;
            }
            // Store the WorldEvent and its computed metadata
            WorldEvent worldEvent = new WorldEvent(e, onInit, condition,
                                                   action, parserContext);
            worldEvents.Add(worldEvent);
        }
    }