From 3614979e357d25ec2153628e6d01ea944cff56ad Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sun, 20 Aug 2023 18:33:20 -0400 Subject: [PATCH] Add a function to protect textures --- texture.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/texture.go b/texture.go index 2e8485c..ccfcf72 100644 --- a/texture.go +++ b/texture.go @@ -12,3 +12,18 @@ type Texture interface { // the original texture as well. Clip (image.Rectangle) Texture } + +type protectedTexture struct { + Texture +} + +func (protectedTexture) Close () error { + return nil +} + +// Protect makes the Close() method of a texture do nothing. This is useful if +// several of the same texture are given out to different objects, but only one +// has the responsibility of closing it. +func Protect (texture Texture) Texture { + return protectedTexture { Texture: texture } +}