active-logic / activelogic-cs

Behavior Trees and Case Logic for C#7
GNU Affero General Public License v3.0
106 stars 7 forks source link

Avoid duplicating `Gate` #29

Closed eelstork closed 2 years ago

eelstork commented 3 years ago

Does not impact functionality, but we have 2-3 implementations of gate and status ref which are very closely related.

Right now it is not obvious whether this can be done or not, because null-conditional decorators rely on typing, and how far generification can help with this is unclear.

Generic gate:

namespace Active.Core{
public readonly struct Gate<T> where T : AbstractDecorator{

    readonly T owner; readonly LogData logData;

    internal Gate(T owner, LogData logData)
    { this.owner = owner; this.logData = logData; }

    public StatusRef this[status s]{ get{
        #if !AL_OPTIMIZE
        owner.target = s.targetScope;
        #endif
        owner.OnStatus(s);
        return new StatusRef(s, logData);
    }}

}}

Works when moving target and a couple other things to AbstractDecorator, however type dependency on StatusRef, which may be touchier.

eelstork commented 2 years ago

Closing; not something broken, unclear benefits