Пример #1
0
    public bool IsActionValid(ref List <Requirements> _failureReason, ref bool isExcludedFromPlayerSelection)
    {
        bool result = true;

        if (tileToReplace == null)
        {
            return(false);
        }

        Tile tilePrefab = LevelGenerator.Instance.GetTilePrefab(newType);

        // check tile availability
        if (!tilePrefab.IsStructureAvailable)
        {
            isExcludedFromPlayerSelection = true;
            return(false);
        }

        // check weight
        int  weightValue       = tilePrefab.GetWeightSupportValue();
        bool passesWeightCheck = WeightAnalyzer.CanStructureBeAddedHere(tileToReplace, weightValue);

        /*
         * // check population
         * if (PopulationAnalyzer.CanStructureBeAdded(tilePrefab, tileToReplace.GetTileGrid()))
         * {
         *      //
         * }
         * else
         * {
         *      _failureReason.Add(new Requirements(Requirements.BuildRequirement.REQUIRES_ENOUGH_POPULATION));
         *      result = false;
         * }
         */

        bool passesClassValidation = true;

        if (ShouldValidateAction)
        {
            // check with tile for validation
            passesClassValidation = tilePrefab.CheckIfValidToBuild(LevelGenerator.Instance.GetTileGrid(), tileToReplace, ref _failureReason, ref isExcludedFromPlayerSelection);
        }

        if (!passesWeightCheck)
        {
            result = false;
            _failureReason.Add(new Requirements(Requirements.BuildRequirement.TILE_BELOW_MUST_SUPPORT_WEIGHT));
        }

        return(result && passesClassValidation);
    }
Пример #2
0
    public bool IsActionValid(ref List <Requirements> _failureReason, ref bool isExcludedFromPlayerSelection)
    {
        bool retVal = true;

        retVal = LevelManager.Instance.CurrentLevelPhase == LevelManager.LevelPhase.MAIN;
        if (!retVal)
        {
            _failureReason.Add(new Requirements(Requirements.BuildRequirement.INCOMPATIBLE_WITH_LEVEL_PHASE));
            return(false);
        }

        retVal = WeightAnalyzer.CanTileBeRemoved(tileToDestroy.GetCoordinate());
        if (!retVal)
        {
            _failureReason.Add(new Requirements(Requirements.BuildRequirement.STRUCTURE_REQUIRED_FOR_WEIGHT));
            return(false);
        }

        return(retVal);
    }
Пример #3
0
        // PrepareSourceBitmap selects page/frame and flips the source bitmap if needed
        // This step occurs after PrepareSourceBitmap has been called
        // More here: https://imageresizing.net/docs/v4/extend/imagebuilder
        protected override RequestedAction PostPrepareSourceBitmap(ImageState state)
        {
            if (!QualifyState(state))
            {
                return(RequestedAction.None);
            }

            // Parse plugin settings
            var settings = ParseSettings(state.settings);

            if (settings == null)
            {
                return(RequestedAction.None);
            }

            var bitmap = state.sourceBitmap;
            var data   = (BitmapData)null;

            state.Data[SettingsKey] = settings;

            var cropAnalysis   = (ICropAnalysis)null;
            var weightAnalysis = (IWeightAnalysis)null;

            try
            {
                // Lock memory range for bitmap for read purposes
                data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat);

                // Get analyzer depending on settings
                var cropAnalyzer = GetCropAnalyzer(data, settings);

                // The analyzer determines if the image is croppable...
                // ...also which area of the image to scan
                cropAnalysis = cropAnalyzer.GetAnalysis();
            }
            finally
            {
                // Unlock memory access
                if (data != null)
                {
                    bitmap.UnlockBits(data);
                }
            }

            if (cropAnalysis?.Success ?? false)
            {
                try
                {
                    // Analyze optical weight of image for later nudge adjustment
                    var weightAnalyzer = new WeightAnalyzer(bitmap, cropAnalysis.Background);
                    weightAnalysis = weightAnalyzer.GetAnalysis();
                }
                finally
                {
                    // Add an AutoCropState for later use
                    state.Data[DataKey] = new AutoCropState(bitmap, cropAnalysis, weightAnalysis);
                }
            }

            return(RequestedAction.None);
        }